Skip to content

Commit

Permalink
feat: api key and standardization of uid action (#128)
Browse files Browse the repository at this point in the history
* feat: api key and standardization of uid action

* fix: method comments
  • Loading branch information
wcrum authored Sep 9, 2024
1 parent d692450 commit d5dfc0c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
42 changes: 42 additions & 0 deletions client/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,45 @@ 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"
)

// GetAPIKeys retrieves all API Keys.
func (h *V1Client) GetAPIKeys() (*models.V1APIKeys, error) {
params := clientv1.NewV1APIKeysListParams()
resp, err := h.Client.V1APIKeysList(params)
if err != nil {
return nil, err
}

return resp.Payload, nil
}

// DeleteAPIKeyByName deletes an existing API Key by name.
func (h *V1Client) DeleteAPIKeyByName(name string) error {
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)
}

// DeleteAPIKey deletes an existing API Key by UID.
func (h *V1Client) DeleteAPIKey(uid string) error {
params := clientv1.NewV1APIKeysUIDDeleteParams().WithUID(uid)
_, err := h.Client.V1APIKeysUIDDelete(params)
if err != nil {
return err
}
return nil
}
4 changes: 2 additions & 2 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (h *V1Client) GetProjectUID(projectName string) (string, error) {
return "", fmt.Errorf("project '%s' not found", projectName)
}

// GetProjectByUID retrieves an existing project by UID.
func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) {
// GetProject retrieves an existing project by UID.
func (h *V1Client) GetProject(uid string) (*models.V1Project, error) {
// ACL scoped to tenant only
params := clientv1.NewV1ProjectsUIDGetParams().
WithUID(uid)
Expand Down
4 changes: 2 additions & 2 deletions client/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (h *V1Client) GetSSHKeyByName(name string) (*models.V1UserAssetSSH, error)
return nil, fmt.Errorf("ssh key '%s' not found", name)
}

// GetSSHKeyByUID retrieves an existing SSH key by UID.
func (h *V1Client) GetSSHKeyByUID(uid string) (*models.V1UserAssetSSH, error) {
// GetSSHKey retrieves an existing SSH key by UID.
func (h *V1Client) GetSSHKey(uid string) (*models.V1UserAssetSSH, error) {
params := clientv1.NewV1UsersAssetSSHGetUIDParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1UsersAssetSSHGetUID(params)
Expand Down
6 changes: 3 additions & 3 deletions client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) {
return nil, fmt.Errorf("user with email '%s' not found", email)
}

// DeleteUserByUID deletes an existing user by UID.
func (h *V1Client) DeleteUserByUID(uid string) error {
// DeleteUser deletes an existing user by UID.
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 d5dfc0c

Please sign in to comment.