mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: delete API token in /logout API (#1770)
* delete API token in logout api * add deleteapikeybyid to databasefake * set blank cookie on logout always * refactor logout flow, add unit tests * update logout messsage * use read-only file mode for windows * fix file mode on windows for cleanup * change file permissions on windows * assert error is not nil * refactor cli * try different file mode on windows * try different file mode on windows * try keeping the files open on Windows * fix the error message on Windows
This commit is contained in:
@@ -126,6 +126,21 @@ func (q *fakeQuerier) GetAPIKeyByID(_ context.Context, id string) (database.APIK
|
||||
return database.APIKey{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) DeleteAPIKeyByID(_ context.Context, id string) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, apiKey := range q.apiKeys {
|
||||
if apiKey.ID != id {
|
||||
continue
|
||||
}
|
||||
q.apiKeys[index] = q.apiKeys[len(q.apiKeys)-1]
|
||||
q.apiKeys = q.apiKeys[:len(q.apiKeys)-1]
|
||||
return nil
|
||||
}
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetFileByHash(_ context.Context, hash string) (database.File, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user