Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api key and standardization of uid action #128

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading