Skip to content

Commit

Permalink
refactor(iam-api-key): Initialize client without account zone. Not ne…
Browse files Browse the repository at this point in the history
…eded for iam api-keys
  • Loading branch information
mlec1 committed Oct 13, 2024
1 parent c59320c commit 1fb7e31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
7 changes: 1 addition & 6 deletions cmd/iam_api_key_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
Expand Down Expand Up @@ -52,11 +51,7 @@ func (c *iamAPIKeyCreateCmd) cmdPreRun(cmd *cobra.Command, args []string) error

func (c *iamAPIKeyCreateCmd) cmdRun(cmd *cobra.Command, _ []string) error {
ctx := gContext
zone := account.CurrentAccount.DefaultZone
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}
client := globalstate.EgoscaleV3Client

listIAMRolesResp, err := client.ListIAMRoles(ctx)
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions cmd/iam_api_key_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
v3 "github.com/exoscale/egoscale/v3"
)
Expand Down Expand Up @@ -36,11 +35,7 @@ func (c *iamAPIKeyDeleteCmd) cmdPreRun(cmd *cobra.Command, args []string) error

func (c *iamAPIKeyDeleteCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := gContext
zone := account.CurrentAccount.DefaultZone
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}
client := globalstate.EgoscaleV3Client

listAPIKeysResp, err := client.ListAPIKeys(ctx)
if err != nil {
Expand Down
24 changes: 7 additions & 17 deletions cmd/iam_api_key_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/table"
v3 "github.com/exoscale/egoscale/v3"
)

type iamAPIKeyListItemOutput struct {
Expand All @@ -35,21 +33,17 @@ func (o *iamAPIKeyListOutput) ToTable() {
defer t.Render()

ctx := gContext
zone := account.CurrentAccount.DefaultZone
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
client := globalstate.EgoscaleV3Client

rolesMap := map[string]string{}

// For better UX we will print both role name and ID
listIAMRolesResp, err := client.ListIAMRoles(ctx)
// If API returns error, can continue (print UUID only) as this is non-essential feature
if err == nil {
// For better UX we will print both role name and ID
listIAMRolesResp, err := client.ListIAMRoles(ctx)
// If API returns error, can continue (print UUID only) as this is non-essential feature
if err == nil {
for _, role := range listIAMRolesResp.IAMRoles {
if role.ID.String() != "" && role.Name != "" {
rolesMap[role.ID.String()] = role.Name
}
for _, role := range listIAMRolesResp.IAMRoles {
if role.ID.String() != "" && role.Name != "" {
rolesMap[role.ID.String()] = role.Name
}
}
}
Expand Down Expand Up @@ -91,11 +85,7 @@ func (c *iamAPIKeyListCmd) cmdPreRun(cmd *cobra.Command, args []string) error {

func (c *iamAPIKeyListCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := gContext
zone := account.CurrentAccount.DefaultZone
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}
client := globalstate.EgoscaleV3Client

listAPIKeysResp, err := client.ListAPIKeys(ctx)
if err != nil {
Expand Down

0 comments on commit 1fb7e31

Please sign in to comment.