mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add ability to name tokens (#6365)
* add tokens switch * reorged TokensPage * using Trans component for description * using Trans component on DeleteDialog * add owner col * simplify hook return * lint * type for response * added flag for name * fixed auth * lint, prettier, tests * added unique index for login type token * remove tokens by name * better check for unique constraint * docs * test: Fix dbfake to insert token name * fix doc tests * Update cli/tokens.go Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> * Update coderd/database/migrations/000102_add_apikey_name.down.sql Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> * add more specificity to IsUniqueViolation check * fix tests * Fix AutorizeAllEndpoints * rename migration --------- Co-authored-by: Steven Masley <stevenmasley@coder.com> Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
This commit is contained in:
co-authored by
Steven Masley
Steven Masley
parent
e3a4861e93
commit
71d1e63af0
@@ -36,6 +36,10 @@ func (q *querier) GetAPIKeyByID(ctx context.Context, id string) (database.APIKey
|
||||
return fetch(q.log, q.auth, q.db.GetAPIKeyByID)(ctx, id)
|
||||
}
|
||||
|
||||
func (q *querier) GetAPIKeyByName(ctx context.Context, arg database.GetAPIKeyByNameParams) (database.APIKey, error) {
|
||||
return fetch(q.log, q.auth, q.db.GetAPIKeyByName)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) GetAPIKeysByLoginType(ctx context.Context, loginType database.LoginType) ([]database.APIKey, error) {
|
||||
return fetchWithPostFilter(q.auth, q.db.GetAPIKeysByLoginType)(ctx, loginType)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,16 @@ func (s *MethodTestSuite) TestAPIKey() {
|
||||
key, _ := dbgen.APIKey(s.T(), db, database.APIKey{})
|
||||
check.Args(key.ID).Asserts(key, rbac.ActionRead).Returns(key)
|
||||
}))
|
||||
s.Run("GetAPIKeyByName", s.Subtest(func(db database.Store, check *expects) {
|
||||
key, _ := dbgen.APIKey(s.T(), db, database.APIKey{
|
||||
TokenName: "marge-cat",
|
||||
LoginType: database.LoginTypeToken,
|
||||
})
|
||||
check.Args(database.GetAPIKeyByNameParams{
|
||||
TokenName: key.TokenName,
|
||||
UserID: key.UserID,
|
||||
}).Asserts(key, rbac.ActionRead).Returns(key)
|
||||
}))
|
||||
s.Run("GetAPIKeysByLoginType", s.Subtest(func(db database.Store, check *expects) {
|
||||
a, _ := dbgen.APIKey(s.T(), db, database.APIKey{LoginType: database.LoginTypePassword})
|
||||
b, _ := dbgen.APIKey(s.T(), db, database.APIKey{LoginType: database.LoginTypePassword})
|
||||
|
||||
Reference in New Issue
Block a user