Use string IDs in JSON res and req for Users

Signed-off-by: Michael de Sa <mjdesa@gmail.com>
pull/2099/head
Jared Scheib 2017-10-10 12:27:55 -07:00 committed by Michael de Sa
parent a1782cae64
commit 35d6f0b8c3
4 changed files with 15 additions and 15 deletions

View File

@ -127,7 +127,7 @@ message User {
uint64 ID = 1; // ID is the unique ID of this user
string Name = 2; // Name is the user's login name
string Provider = 3; // Provider is the provider that certifies and issues this user's authentication, e.g. GitHub
string Scheme = 4; // Scheme is the scheme used to perform this user's authentication, e.g. OAuth2 or LDAP
string Scheme = 4; // Scheme is the scheme used to perform this user's authentication, e.g. OAuth2 or LDAP
}
// The following is a vim modeline, it autoconfigures vim to have the

View File

@ -597,7 +597,7 @@ type Scope string
// User represents an authenticated user.
type User struct {
ID uint64 `json:"id,omitempty"`
ID uint64 `json:"id,string,omitempty"`
Name string `json:"name"`
Passwd string `json:"password,omitempty"`
Permissions Permissions `json:"permissions,omitempty"`

View File

@ -12,7 +12,7 @@ import (
)
type userRequest struct {
ID uint64 `json:"id"`
ID uint64 `json:"id,string"`
Name string `json:"name"`
Provider string `json:"provider,omitempty"`
Scheme string `json:"scheme,omitempty"`
@ -40,7 +40,7 @@ func (r *userRequest) ValidUpdate() error {
type userResponse struct {
Links selfLinks `json:"links"`
ID uint64 `json:"id"`
ID uint64 `json:"id,string"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
Scheme string `json:"scheme,omitempty"`
@ -53,7 +53,7 @@ func newUserResponse(u *chronograf.User) *userResponse {
Provider: u.Provider,
Scheme: u.Scheme,
Links: selfLinks{
Self: fmt.Sprintf("/chronograf/v1/users/%v", u.ID),
Self: fmt.Sprintf("/chronograf/v1/users/%d", u.ID),
},
}
}

View File

@ -58,7 +58,7 @@ func TestService_UserID(t *testing.T) {
Scheme: "OAuth2",
}, nil
default:
return nil, fmt.Errorf("User with ID %v not found", ID)
return nil, fmt.Errorf("User with ID %s not found", ID)
}
},
},
@ -66,7 +66,7 @@ func TestService_UserID(t *testing.T) {
id: "1337",
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"id":1337,"name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}}`,
wantBody: `{"id":"1337","name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}}`,
},
}
@ -153,7 +153,7 @@ func TestService_NewUser(t *testing.T) {
},
wantStatus: http.StatusCreated,
wantContentType: "application/json",
wantBody: `{"id":1338,"name":"bob","provider":"GitHub","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1338"}}`,
wantBody: `{"id":"1338","name":"bob","provider":"GitHub","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1338"}}`,
},
}
@ -219,7 +219,7 @@ func TestService_RemoveUser(t *testing.T) {
Scheme: "LDAP",
}, nil
default:
return nil, fmt.Errorf("User with ID %v not found", ID)
return nil, fmt.Errorf("User with ID %s not found", ID)
}
},
DeleteF: func(ctx context.Context, user *chronograf.User) error {
@ -310,7 +310,7 @@ func TestService_UpdateUser(t *testing.T) {
Scheme: "OAuth2",
}, nil
default:
return nil, fmt.Errorf("User with ID %v not found", ID)
return nil, fmt.Errorf("User with ID %s not found", ID)
}
},
},
@ -332,7 +332,7 @@ func TestService_UpdateUser(t *testing.T) {
id: "1336",
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"id":1336,"name":"bobbetta","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1336"}}`,
wantBody: `{"id":"1336","name":"bobbetta","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1336"}}`,
},
{
@ -353,7 +353,7 @@ func TestService_UpdateUser(t *testing.T) {
Scheme: "OAuth2",
}, nil
default:
return nil, fmt.Errorf("User with ID %v not found", ID)
return nil, fmt.Errorf("User with ID %s not found", ID)
}
},
},
@ -373,7 +373,7 @@ func TestService_UpdateUser(t *testing.T) {
id: "1336",
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"id":1336,"name":"burnetta","provider":"GitHub","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1336"}}`,
wantBody: `{"id":"1336","name":"burnetta","provider":"GitHub","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1336"}}`,
},
}
for _, tt := range tests {
@ -462,7 +462,7 @@ func TestService_Users(t *testing.T) {
},
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"users":[{"id":1337,"name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}},{"id":1338,"name":"bobbettastuhvetta","provider":"Auth0","scheme":"LDAP","links":{"self":"/chronograf/v1/users/1338"}}],"links":{"self":"/chronograf/v1/users"}}`,
wantBody: `{"users":[{"id":"1337","name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}},{"id":"1338","name":"bobbettastuhvetta","provider":"Auth0","scheme":"LDAP","links":{"self":"/chronograf/v1/users/1338"}}],"links":{"self":"/chronograf/v1/users"}}`,
},
{
name: "Get all Chronograf users, ensuring order of users in response",
@ -497,7 +497,7 @@ func TestService_Users(t *testing.T) {
},
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"users":[{"id":1337,"name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}},{"id":1338,"name":"bobbettastuhvetta","provider":"Auth0","scheme":"LDAP","links":{"self":"/chronograf/v1/users/1338"}}],"links":{"self":"/chronograf/v1/users"}}`,
wantBody: `{"users":[{"id":"1337","name":"billysteve","provider":"Google","scheme":"OAuth2","links":{"self":"/chronograf/v1/users/1337"}},{"id":"1338","name":"bobbettastuhvetta","provider":"Auth0","scheme":"LDAP","links":{"self":"/chronograf/v1/users/1338"}}],"links":{"self":"/chronograf/v1/users"}}`,
},
}