Skip to content

Commit

Permalink
feat: api key and standardization of uid action
Browse files Browse the repository at this point in the history
  • Loading branch information
wcrum committed Sep 5, 2024
1 parent d692450 commit c382bf4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
39 changes: 39 additions & 0 deletions client/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,42 @@ package client

// CRUDL operations on API keys are all tenant scoped.
// See: hubble/services/service/user/internal/service/apikey/apikey_acl.go

import (
"fmt"

clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1"
"github.com/spectrocloud/palette-sdk-go/api/models"
)

func (h *V1Client) GetAPIKeys() (*models.V1APIKeys, error) {

Check failure on line 13 in client/api_key.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: exported method V1Client.GetAPIKeys should have comment or be unexported (revive)
params := clientv1.NewV1APIKeysListParams()
resp, err := h.Client.V1APIKeysList(params)
if err != nil {
return nil, err
}

return resp.Payload, nil
}

func (h *V1Client) DeleteAPIKeyByName(name string) error {

Check failure on line 23 in client/api_key.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: exported method V1Client.DeleteAPIKeyByName should have comment or be unexported (revive)
keys, err := h.GetAPIKeys()
if err != nil {
return err
}
for _, key := range keys.Items {
if key.Metadata.Name == name {
return h.DeleteAPIKey(key.Metadata.UID)
}
}
return fmt.Errorf("api key with name '%s' not found", name)
}

func (h *V1Client) DeleteAPIKey(uid string) error {

Check failure on line 36 in client/api_key.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: exported method V1Client.DeleteAPIKey should have comment or be unexported (revive)
params := clientv1.NewV1APIKeysUIDDeleteParams().WithUID(uid)
_, err := h.Client.V1APIKeysUIDDelete(params)
if err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (h *V1Client) GetProjectUID(projectName string) (string, error) {
}

// GetProjectByUID retrieves an existing project by UID.

Check failure on line 41 in client/project.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: comment on exported method V1Client.GetProject should be of the form "GetProject ..." (revive)
func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) {
func (h *V1Client) GetProject(uid string) (*models.V1Project, error) {
// ACL scoped to tenant only
params := clientv1.NewV1ProjectsUIDGetParams().
WithUID(uid)
Expand Down
2 changes: 1 addition & 1 deletion client/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *V1Client) GetSSHKeyByName(name string) (*models.V1UserAssetSSH, error)
}

// GetSSHKeyByUID retrieves an existing SSH key by UID.

Check failure on line 45 in client/ssh_key.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: comment on exported method V1Client.GetSSHKey should be of the form "GetSSHKey ..." (revive)
func (h *V1Client) GetSSHKeyByUID(uid string) (*models.V1UserAssetSSH, error) {
func (h *V1Client) GetSSHKey(uid string) (*models.V1UserAssetSSH, error) {
params := clientv1.NewV1UsersAssetSSHGetUIDParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1UsersAssetSSHGetUID(params)
Expand Down
4 changes: 2 additions & 2 deletions client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) {
}

// DeleteUserByUID deletes an existing user by UID.

Check failure on line 87 in client/user.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

exported: comment on exported method V1Client.DeleteUser should be of the form "DeleteUser ..." (revive)
func (h *V1Client) DeleteUserByUID(uid string) error {
func (h *V1Client) DeleteUser(uid string) error {
params := clientv1.NewV1UsersUIDDeleteParams().WithUID(uid)
_, err := h.Client.V1UsersUIDDelete(params)
if err != nil {
Expand All @@ -102,7 +102,7 @@ func (h *V1Client) DeleteUserByName(name string) error {
}
for _, user := range users.Items {
if user.Metadata.Name == name {
return h.DeleteUserByUID(user.Metadata.UID)
return h.DeleteUser(user.Metadata.UID)
}
}
return fmt.Errorf("user with name '%s' not found", name)
Expand Down

0 comments on commit c382bf4

Please sign in to comment.