mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat: Add user scoped git ssh keys (#834)
This commit is contained in:
@ -31,6 +31,7 @@ func New() database.Store {
|
||||
provisionerJobResource: make([]database.WorkspaceResource, 0),
|
||||
workspaceBuild: make([]database.WorkspaceBuild, 0),
|
||||
provisionerJobAgent: make([]database.WorkspaceAgent, 0),
|
||||
GitSSHKey: make([]database.GitSSHKey, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +58,7 @@ type fakeQuerier struct {
|
||||
provisionerJobLog []database.ProvisionerJobLog
|
||||
workspace []database.Workspace
|
||||
workspaceBuild []database.WorkspaceBuild
|
||||
GitSSHKey []database.GitSSHKey
|
||||
}
|
||||
|
||||
// InTx doesn't rollback data properly for in-memory yet.
|
||||
@ -1239,3 +1241,63 @@ func (q *fakeQuerier) UpdateWorkspaceDeletedByID(_ context.Context, arg database
|
||||
}
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertGitSSHKey(_ context.Context, arg database.InsertGitSSHKeyParams) (database.GitSSHKey, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
//nolint:gosimple
|
||||
gitSSHKey := database.GitSSHKey{
|
||||
UserID: arg.UserID,
|
||||
CreatedAt: arg.CreatedAt,
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
PrivateKey: arg.PrivateKey,
|
||||
PublicKey: arg.PublicKey,
|
||||
}
|
||||
q.GitSSHKey = append(q.GitSSHKey, gitSSHKey)
|
||||
return gitSSHKey, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetGitSSHKey(_ context.Context, userID uuid.UUID) (database.GitSSHKey, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
for _, key := range q.GitSSHKey {
|
||||
if key.UserID == userID {
|
||||
return key, nil
|
||||
}
|
||||
}
|
||||
return database.GitSSHKey{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) UpdateGitSSHKey(_ context.Context, arg database.UpdateGitSSHKeyParams) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, key := range q.GitSSHKey {
|
||||
if key.UserID.String() != arg.UserID.String() {
|
||||
continue
|
||||
}
|
||||
key.UpdatedAt = arg.UpdatedAt
|
||||
key.PrivateKey = arg.PrivateKey
|
||||
key.PublicKey = arg.PublicKey
|
||||
q.GitSSHKey[index] = key
|
||||
return nil
|
||||
}
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) DeleteGitSSHKey(_ context.Context, userID uuid.UUID) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, key := range q.GitSSHKey {
|
||||
if key.UserID.String() != userID.String() {
|
||||
continue
|
||||
}
|
||||
q.GitSSHKey[index] = q.GitSSHKey[len(q.GitSSHKey)-1]
|
||||
q.GitSSHKey = q.GitSSHKey[:len(q.GitSSHKey)-1]
|
||||
return nil
|
||||
}
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
Reference in New Issue
Block a user