From 1fb7e31e58b6256f706a5145af836f6f6e18c024 Mon Sep 17 00:00:00 2001 From: mlec <42201667+mlec1@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:28:00 +0200 Subject: [PATCH] refactor(iam-api-key): Initialize client without account zone. Not needed for iam api-keys --- cmd/iam_api_key_create.go | 7 +------ cmd/iam_api_key_delete.go | 7 +------ cmd/iam_api_key_list.go | 24 +++++++----------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/cmd/iam_api_key_create.go b/cmd/iam_api_key_create.go index 7071e466..98354361 100644 --- a/cmd/iam_api_key_create.go +++ b/cmd/iam_api_key_create.go @@ -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" @@ -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 { diff --git a/cmd/iam_api_key_delete.go b/cmd/iam_api_key_delete.go index 0531607d..430534d6 100644 --- a/cmd/iam_api_key_delete.go +++ b/cmd/iam_api_key_delete.go @@ -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" ) @@ -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 { diff --git a/cmd/iam_api_key_list.go b/cmd/iam_api_key_list.go index e55a48f1..d623d769 100644 --- a/cmd/iam_api_key_list.go +++ b/cmd/iam_api_key_list.go @@ -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 { @@ -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 } } } @@ -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 {