From 5df4993e51a17e7bbb64639b8d1bd2ccbb3b701e Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:04:53 -0400 Subject: [PATCH 1/2] refactor(db): return user on created and updated (#935) --- api/admin/user.go | 4 +-- api/auth/get_token.go | 4 +-- api/auth/logout.go | 2 +- api/user/create.go | 5 +-- api/user/create_token.go | 2 +- api/user/delete_token.go | 2 +- api/user/update.go | 5 +-- api/user/update_current.go | 12 +------- database/integration_test.go | 9 ++---- database/user/count_test.go | 4 +-- database/user/create.go | 19 +++++++----- database/user/create_test.go | 7 ++++- database/user/delete_test.go | 2 +- database/user/get_name_test.go | 2 +- database/user/get_test.go | 2 +- database/user/interface.go | 4 +-- database/user/list_lite_test.go | 4 +-- database/user/list_test.go | 4 +-- database/user/update.go | 19 +++++++----- database/user/update_test.go | 9 ++++-- internal/token/refresh_test.go | 4 +-- router/middleware/claims/claims_test.go | 2 +- router/middleware/perm/perm_test.go | 34 ++++++++++----------- router/middleware/pipeline/pipeline_test.go | 2 +- router/middleware/user/user_test.go | 2 +- 25 files changed, 82 insertions(+), 83 deletions(-) diff --git a/api/admin/user.go b/api/admin/user.go index f7ef70ba3..c0c2aacfd 100644 --- a/api/admin/user.go +++ b/api/admin/user.go @@ -66,7 +66,7 @@ func UpdateUser(c *gin.Context) { } // send API call to update the user - err = database.FromContext(c).UpdateUser(input) + u, err := database.FromContext(c).UpdateUser(input) if err != nil { retErr := fmt.Errorf("unable to update user %d: %w", input.GetID(), err) @@ -75,5 +75,5 @@ func UpdateUser(c *gin.Context) { return } - c.JSON(http.StatusOK, input) + c.JSON(http.StatusOK, u) } diff --git a/api/auth/get_token.go b/api/auth/get_token.go index 29829f072..2b6d7da66 100644 --- a/api/auth/get_token.go +++ b/api/auth/get_token.go @@ -121,7 +121,7 @@ func GetAuthToken(c *gin.Context) { u.SetRefreshToken(rt) // send API call to create the user in the database - err = database.FromContext(c).CreateUser(u) + _, err = database.FromContext(c).CreateUser(u) if err != nil { retErr := fmt.Errorf("unable to create user %s: %w", u.GetName(), err) @@ -154,7 +154,7 @@ func GetAuthToken(c *gin.Context) { u.SetRefreshToken(rt) // send API call to update the user in the database - err = database.FromContext(c).UpdateUser(u) + _, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", u.GetName(), err) diff --git a/api/auth/logout.go b/api/auth/logout.go index 8accdf42e..1bc8f8d58 100644 --- a/api/auth/logout.go +++ b/api/auth/logout.go @@ -75,7 +75,7 @@ func Logout(c *gin.Context) { u.SetRefreshToken("") // send API call to update the user in the database - err = database.FromContext(c).UpdateUser(u) + _, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", u.GetName(), err) diff --git a/api/user/create.go b/api/user/create.go index d6348810e..bb7823546 100644 --- a/api/user/create.go +++ b/api/user/create.go @@ -72,7 +72,7 @@ func CreateUser(c *gin.Context) { }).Infof("creating new user %s", input.GetName()) // send API call to create the user - err = database.FromContext(c).CreateUser(input) + user, err := database.FromContext(c).CreateUser(input) if err != nil { retErr := fmt.Errorf("unable to create user: %w", err) @@ -81,8 +81,5 @@ func CreateUser(c *gin.Context) { return } - // send API call to capture the created user - user, _ := database.FromContext(c).GetUserForName(input.GetName()) - c.JSON(http.StatusCreated, user) } diff --git a/api/user/create_token.go b/api/user/create_token.go index dee7044cb..427fab34d 100644 --- a/api/user/create_token.go +++ b/api/user/create_token.go @@ -65,7 +65,7 @@ func CreateToken(c *gin.Context) { u.SetRefreshToken(rt) // send API call to update the user - err = database.FromContext(c).UpdateUser(u) + _, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", u.GetName(), err) diff --git a/api/user/delete_token.go b/api/user/delete_token.go index 22fa9724d..05a7a3699 100644 --- a/api/user/delete_token.go +++ b/api/user/delete_token.go @@ -65,7 +65,7 @@ func DeleteToken(c *gin.Context) { u.SetRefreshToken(rt) // send API call to update the user - err = database.FromContext(c).UpdateUser(u) + _, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", u.GetName(), err) diff --git a/api/user/update.go b/api/user/update.go index d2fb631ab..21a089e04 100644 --- a/api/user/update.go +++ b/api/user/update.go @@ -108,7 +108,7 @@ func UpdateUser(c *gin.Context) { } // send API call to update the user - err = database.FromContext(c).UpdateUser(u) + u, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", user, err) @@ -117,8 +117,5 @@ func UpdateUser(c *gin.Context) { return } - // send API call to capture the updated user - u, _ = database.FromContext(c).GetUserForName(user) - c.JSON(http.StatusOK, u) } diff --git a/api/user/update_current.go b/api/user/update_current.go index ed861ae61..0eeb4e1be 100644 --- a/api/user/update_current.go +++ b/api/user/update_current.go @@ -82,7 +82,7 @@ func UpdateCurrentUser(c *gin.Context) { } // send API call to update the user - err = database.FromContext(c).UpdateUser(u) + u, err = database.FromContext(c).UpdateUser(u) if err != nil { retErr := fmt.Errorf("unable to update user %s: %w", u.GetName(), err) @@ -91,15 +91,5 @@ func UpdateCurrentUser(c *gin.Context) { return } - // send API call to capture the updated user - u, err = database.FromContext(c).GetUserForName(u.GetName()) - if err != nil { - retErr := fmt.Errorf("unable to get updated user %s: %w", u.GetName(), err) - - util.HandleError(c, http.StatusNotFound, retErr) - - return - } - c.JSON(http.StatusOK, u) } diff --git a/database/integration_test.go b/database/integration_test.go index 30d6ff696..f982b25cb 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -1656,7 +1656,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { // create the users for _, user := range resources.Users { - err := db.CreateUser(user) + _, err := db.CreateUser(user) if err != nil { t.Errorf("unable to create user %d: %v", user.GetID(), err) } @@ -1711,16 +1711,11 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { // update the users for _, user := range resources.Users { user.SetActive(false) - err = db.UpdateUser(user) + got, err := db.UpdateUser(user) if err != nil { t.Errorf("unable to update user %d: %v", user.GetID(), err) } - // lookup the user by ID - got, err := db.GetUser(user.GetID()) - if err != nil { - t.Errorf("unable to get user %d by ID: %v", user.GetID(), err) - } if !reflect.DeepEqual(got, user) { t.Errorf("GetUser() is %v, want %v", got, user) } diff --git a/database/user/count_test.go b/database/user/count_test.go index be7cb6437..be4c77f0c 100644 --- a/database/user/count_test.go +++ b/database/user/count_test.go @@ -37,12 +37,12 @@ func TestUser_Engine_CountUsers(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_userOne) + _, err := _sqlite.CreateUser(_userOne) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } - err = _sqlite.CreateUser(_userTwo) + _, err = _sqlite.CreateUser(_userTwo) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/create.go b/database/user/create.go index f527979b9..4a45f0d89 100644 --- a/database/user/create.go +++ b/database/user/create.go @@ -15,7 +15,7 @@ import ( ) // CreateUser creates a new user in the database. -func (e *engine) CreateUser(u *library.User) error { +func (e *engine) CreateUser(u *library.User) (*library.User, error) { e.logger.WithFields(logrus.Fields{ "user": u.GetName(), }).Tracef("creating user %s in the database", u.GetName()) @@ -30,7 +30,7 @@ func (e *engine) CreateUser(u *library.User) error { // https://pkg.go.dev/github.com/go-vela/types/database#User.Validate err := user.Validate() if err != nil { - return err + return nil, err } // encrypt the fields for the user @@ -38,12 +38,17 @@ func (e *engine) CreateUser(u *library.User) error { // https://pkg.go.dev/github.com/go-vela/types/database#User.Encrypt err = user.Encrypt(e.config.EncryptionKey) if err != nil { - return fmt.Errorf("unable to encrypt user %s: %w", u.GetName(), err) + return nil, fmt.Errorf("unable to encrypt user %s: %w", u.GetName(), err) } // send query to the database - return e.client. - Table(constants.TableUser). - Create(user). - Error + result := e.client.Table(constants.TableUser).Create(user) + + // decrypt fields to return user + err = user.Decrypt(e.config.EncryptionKey) + if err != nil { + return nil, fmt.Errorf("unable to decrypt user %s: %w", u.GetName(), err) + } + + return user.ToLibrary(), result.Error } diff --git a/database/user/create_test.go b/database/user/create_test.go index 12de80f96..815b3ef88 100644 --- a/database/user/create_test.go +++ b/database/user/create_test.go @@ -5,6 +5,7 @@ package user import ( + "reflect" "testing" "github.com/DATA-DOG/go-sqlmock" @@ -55,7 +56,7 @@ VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"`). // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err := test.database.CreateUser(_user) + got, err := test.database.CreateUser(_user) if test.failure { if err == nil { @@ -68,6 +69,10 @@ VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"`). if err != nil { t.Errorf("CreateUser for %s returned err: %v", test.name, err) } + + if !reflect.DeepEqual(got, _user) { + t.Errorf("CreateUser for %s returned %s, want %s", test.name, got, _user) + } }) } } diff --git a/database/user/delete_test.go b/database/user/delete_test.go index 0dec0a6b2..937df9bc3 100644 --- a/database/user/delete_test.go +++ b/database/user/delete_test.go @@ -29,7 +29,7 @@ func TestUser_Engine_DeleteUser(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_user) + _, err := _sqlite.CreateUser(_user) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/get_name_test.go b/database/user/get_name_test.go index 4b0a6446b..cb93ffd0b 100644 --- a/database/user/get_name_test.go +++ b/database/user/get_name_test.go @@ -35,7 +35,7 @@ func TestUser_Engine_GetUserForName(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_user) + _, err := _sqlite.CreateUser(_user) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/get_test.go b/database/user/get_test.go index 4593ce48f..2ecac65f2 100644 --- a/database/user/get_test.go +++ b/database/user/get_test.go @@ -35,7 +35,7 @@ func TestUser_Engine_GetUser(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_user) + _, err := _sqlite.CreateUser(_user) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/interface.go b/database/user/interface.go index ad5986fad..dc67c933c 100644 --- a/database/user/interface.go +++ b/database/user/interface.go @@ -29,7 +29,7 @@ type UserInterface interface { // CountUsers defines a function that gets the count of all users. CountUsers() (int64, error) // CreateUser defines a function that creates a new user. - CreateUser(*library.User) error + CreateUser(*library.User) (*library.User, error) // DeleteUser defines a function that deletes an existing user. DeleteUser(*library.User) error // GetUser defines a function that gets a user by ID. @@ -41,5 +41,5 @@ type UserInterface interface { // ListLiteUsers defines a function that gets a lite list of users. ListLiteUsers(int, int) ([]*library.User, int64, error) // UpdateUser defines a function that updates an existing user. - UpdateUser(*library.User) error + UpdateUser(*library.User) (*library.User, error) } diff --git a/database/user/list_lite_test.go b/database/user/list_lite_test.go index 4c44bc20b..6dd88aa75 100644 --- a/database/user/list_lite_test.go +++ b/database/user/list_lite_test.go @@ -49,12 +49,12 @@ func TestUser_Engine_ListLiteUsers(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_userOne) + _, err := _sqlite.CreateUser(_userOne) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } - err = _sqlite.CreateUser(_userTwo) + _, err = _sqlite.CreateUser(_userTwo) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/list_test.go b/database/user/list_test.go index 61293d44c..9e088e72f 100644 --- a/database/user/list_test.go +++ b/database/user/list_test.go @@ -49,12 +49,12 @@ func TestUser_Engine_ListUsers(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_userOne) + _, err := _sqlite.CreateUser(_userOne) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } - err = _sqlite.CreateUser(_userTwo) + _, err = _sqlite.CreateUser(_userTwo) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } diff --git a/database/user/update.go b/database/user/update.go index c7efc5e7f..2a215a75f 100644 --- a/database/user/update.go +++ b/database/user/update.go @@ -15,7 +15,7 @@ import ( ) // UpdateUser updates an existing user in the database. -func (e *engine) UpdateUser(u *library.User) error { +func (e *engine) UpdateUser(u *library.User) (*library.User, error) { e.logger.WithFields(logrus.Fields{ "user": u.GetName(), }).Tracef("updating user %s in the database", u.GetName()) @@ -30,7 +30,7 @@ func (e *engine) UpdateUser(u *library.User) error { // https://pkg.go.dev/github.com/go-vela/types/database#User.Validate err := user.Validate() if err != nil { - return err + return nil, err } // encrypt the fields for the user @@ -38,12 +38,17 @@ func (e *engine) UpdateUser(u *library.User) error { // https://pkg.go.dev/github.com/go-vela/types/database#User.Encrypt err = user.Encrypt(e.config.EncryptionKey) if err != nil { - return fmt.Errorf("unable to encrypt user %s: %w", u.GetName(), err) + return nil, fmt.Errorf("unable to encrypt user %s: %w", u.GetName(), err) } // send query to the database - return e.client. - Table(constants.TableUser). - Save(user). - Error + result := e.client.Table(constants.TableUser).Save(user) + + // decrypt fields to return user + err = user.Decrypt(e.config.EncryptionKey) + if err != nil { + return nil, fmt.Errorf("unable to decrypt user %s: %w", u.GetName(), err) + } + + return user.ToLibrary(), result.Error } diff --git a/database/user/update_test.go b/database/user/update_test.go index 4253ac435..44f2cb0fe 100644 --- a/database/user/update_test.go +++ b/database/user/update_test.go @@ -5,6 +5,7 @@ package user import ( + "reflect" "testing" "github.com/DATA-DOG/go-sqlmock" @@ -31,7 +32,7 @@ WHERE "id" = $8`). _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateUser(_user) + _, err := _sqlite.CreateUser(_user) if err != nil { t.Errorf("unable to create test user for sqlite: %v", err) } @@ -57,7 +58,7 @@ WHERE "id" = $8`). // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err = test.database.UpdateUser(_user) + got, err := test.database.UpdateUser(_user) if test.failure { if err == nil { @@ -70,6 +71,10 @@ WHERE "id" = $8`). if err != nil { t.Errorf("UpdateUser for %s returned err: %v", test.name, err) } + + if !reflect.DeepEqual(got, _user) { + t.Errorf("UpdateUser for %s returned %s, want %s", test.name, got, _user) + } }) } } diff --git a/internal/token/refresh_test.go b/internal/token/refresh_test.go index e306f9ed6..ee9a30c4d 100644 --- a/internal/token/refresh_test.go +++ b/internal/token/refresh_test.go @@ -55,7 +55,7 @@ func TestTokenManager_Refresh(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) // set up context gin.SetMode(gin.TestMode) @@ -114,7 +114,7 @@ func TestTokenManager_Refresh_Expired(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) // set up context gin.SetMode(gin.TestMode) diff --git a/router/middleware/claims/claims_test.go b/router/middleware/claims/claims_test.go index da28eb319..fd1e0ccfd 100644 --- a/router/middleware/claims/claims_test.go +++ b/router/middleware/claims/claims_test.go @@ -278,7 +278,7 @@ func TestClaims_Establish_BadToken(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) mto := &token.MintTokenOpts{ User: u, diff --git a/router/middleware/perm/perm_test.go b/router/middleware/perm/perm_test.go index b1495ab19..2b384250e 100644 --- a/router/middleware/perm/perm_test.go +++ b/router/middleware/perm/perm_test.go @@ -64,7 +64,7 @@ func TestPerm_MustPlatformAdmin(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) // setup context gin.SetMode(gin.TestMode) @@ -152,7 +152,7 @@ func TestPerm_MustPlatformAdmin_NotAdmin(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/admin/users", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -279,7 +279,7 @@ func TestPerm_MustWorkerRegisterToken_PlatAdmin(t *testing.T) { db.Close() }() - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -544,7 +544,7 @@ func TestPerm_MustBuildAccess_PlatAdmin(t *testing.T) { _, _ = db.CreateRepo(_context.TODO(), r) _, _ = db.CreateBuild(ctx, b) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar/builds/1", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -963,7 +963,7 @@ func TestPerm_MustAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1061,7 +1061,7 @@ func TestPerm_MustAdmin_PlatAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1159,7 +1159,7 @@ func TestPerm_MustAdmin_NotAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1257,7 +1257,7 @@ func TestPerm_MustWrite(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1355,7 +1355,7 @@ func TestPerm_MustWrite_PlatAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1453,7 +1453,7 @@ func TestPerm_MustWrite_RepoAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1551,7 +1551,7 @@ func TestPerm_MustWrite_NotWrite(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1649,7 +1649,7 @@ func TestPerm_MustRead(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1747,7 +1747,7 @@ func TestPerm_MustRead_PlatAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1931,7 +1931,7 @@ func TestPerm_MustRead_RepoAdmin(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -2029,7 +2029,7 @@ func TestPerm_MustRead_RepoWrite(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -2127,7 +2127,7 @@ func TestPerm_MustRead_RepoPublic(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -2225,7 +2225,7 @@ func TestPerm_MustRead_NotRead(t *testing.T) { }() _, _ = db.CreateRepo(_context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) diff --git a/router/middleware/pipeline/pipeline_test.go b/router/middleware/pipeline/pipeline_test.go index 0fc1e8b29..ead046065 100644 --- a/router/middleware/pipeline/pipeline_test.go +++ b/router/middleware/pipeline/pipeline_test.go @@ -295,7 +295,7 @@ func TestPipeline_Establish_NoPipeline(t *testing.T) { }() _, _ = db.CreateRepo(context.TODO(), r) - _ = db.CreateUser(u) + _, _ = db.CreateUser(u) // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/user/user_test.go b/router/middleware/user/user_test.go index 0ea18dfcc..c90cb53fc 100644 --- a/router/middleware/user/user_test.go +++ b/router/middleware/user/user_test.go @@ -96,7 +96,7 @@ func TestUser_Establish(t *testing.T) { db.Close() }() - _ = db.CreateUser(want) + _, _ = db.CreateUser(want) // setup context gin.SetMode(gin.TestMode) From 20f3d92369dcd79de933300f833edf0c62cdd205 Mon Sep 17 00:00:00 2001 From: dave vader <48764154+plyr4@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:32:23 -0500 Subject: [PATCH 2/2] enhance: use consistent variable aliases (#946) --- queue/flags.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/queue/flags.go b/queue/flags.go index b5ede4733..2e78b11da 100644 --- a/queue/flags.go +++ b/queue/flags.go @@ -51,13 +51,13 @@ var Flags = []cli.Flag{ Value: 60 * time.Second, }, &cli.StringFlag{ - EnvVars: []string{"QUEUE_PRIVATE_KEY"}, + EnvVars: []string{"VELA_QUEUE_PRIVATE_KEY", "QUEUE_PRIVATE_KEY"}, FilePath: "/vela/signing.key", Name: "queue.private-key", Usage: "set value of base64 encoded queue signing private key", }, &cli.StringFlag{ - EnvVars: []string{"QUEUE_PUBLIC_KEY"}, + EnvVars: []string{"VELA_QUEUE_PUBLIC_KEY", "QUEUE_PUBLIC_KEY"}, FilePath: "/vela/signing.pub", Name: "queue.public-key", Usage: "set value of base64 encoded queue signing public key",