From 35d6f0b8c3f970f6b8158a702c3af7824ab5df96 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Tue, 10 Oct 2017 12:27:55 -0700 Subject: [PATCH] Use string IDs in JSON res and req for Users Signed-off-by: Michael de Sa --- bolt/internal/internal.proto | 2 +- chronograf.go | 2 +- server/users.go | 6 +++--- server/users_test.go | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bolt/internal/internal.proto b/bolt/internal/internal.proto index c1b051f55..3c57c0413 100644 --- a/bolt/internal/internal.proto +++ b/bolt/internal/internal.proto @@ -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 diff --git a/chronograf.go b/chronograf.go index 2c229fa45..753068583 100644 --- a/chronograf.go +++ b/chronograf.go @@ -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"` diff --git a/server/users.go b/server/users.go index c1c1e3408..7b60c5a17 100644 --- a/server/users.go +++ b/server/users.go @@ -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), }, } } diff --git a/server/users_test.go b/server/users_test.go index 868e24c5c..8a4d626df 100644 --- a/server/users_test.go +++ b/server/users_test.go @@ -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"}}`, }, }