From 9690fe0d6b66d10db6d368260bc3dd498caa8832 Mon Sep 17 00:00:00 2001 From: Amulyam24 Date: Fri, 2 Jun 2023 16:12:27 +0530 Subject: [PATCH] Modify capibmadm to not use GetAPIKeyDetails to fetch the account ID Signed-off-by: Amulyam24 --- cmd/capibmadm/cmd/powervs/image/import.go | 5 +++-- cmd/capibmadm/cmd/powervs/image/list.go | 4 +++- cmd/capibmadm/cmd/powervs/key/create.go | 5 +++-- cmd/capibmadm/cmd/powervs/key/delete.go | 5 +++-- cmd/capibmadm/cmd/powervs/key/list.go | 5 +++-- cmd/capibmadm/cmd/powervs/network/create.go | 5 +++-- cmd/capibmadm/cmd/powervs/network/delete.go | 5 +++-- cmd/capibmadm/cmd/powervs/network/list.go | 5 +++-- cmd/capibmadm/cmd/powervs/port/create.go | 4 +++- cmd/capibmadm/cmd/powervs/port/delete.go | 5 +++-- cmd/capibmadm/cmd/powervs/port/list.go | 4 +++- cmd/capibmadm/cmd/vpc/image/list.go | 7 ++++--- cmd/capibmadm/cmd/vpc/key/create.go | 4 +++- cmd/capibmadm/cmd/vpc/key/list.go | 4 ++-- cmd/capibmadm/utils/utils.go | 21 --------------------- 15 files changed, 42 insertions(+), 46 deletions(-) diff --git a/cmd/capibmadm/cmd/powervs/image/import.go b/cmd/capibmadm/cmd/powervs/image/import.go index 6b52f390c..4a96e38c4 100644 --- a/cmd/capibmadm/cmd/powervs/image/import.go +++ b/cmd/capibmadm/cmd/powervs/image/import.go @@ -31,9 +31,10 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) type imageImportOptions struct { @@ -106,7 +107,7 @@ func importimage(ctx context.Context, imageImportOption imageImportOptions) erro log := logf.Log log.Info("Importing PowerVS images: ", "service-instance-id", options.GlobalOptions.ServiceInstanceID) - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/image/list.go b/cmd/capibmadm/cmd/powervs/image/list.go index 9022ebea7..713c9db58 100644 --- a/cmd/capibmadm/cmd/powervs/image/list.go +++ b/cmd/capibmadm/cmd/powervs/image/list.go @@ -28,10 +28,12 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) // ListCommand powervs image list command. @@ -55,7 +57,7 @@ func listimage(ctx context.Context) error { log := logf.Log log.Info("Listing PowerVS images", "service-instance-id", options.GlobalOptions.ServiceInstanceID) - accountID, err := utils.GetAccountID(ctx) + accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/key/create.go b/cmd/capibmadm/cmd/powervs/key/create.go index 77f305889..67c01e42d 100644 --- a/cmd/capibmadm/cmd/powervs/key/create.go +++ b/cmd/capibmadm/cmd/powervs/key/create.go @@ -29,9 +29,10 @@ import ( "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) type keyCreateOptions struct { @@ -88,7 +89,7 @@ func createSSHKey(ctx context.Context, keyCreateOption keyCreateOptions) error { logger := log.Log logger.Info("Creating SSH key...") - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/key/delete.go b/cmd/capibmadm/cmd/powervs/key/delete.go index d371361bf..b0057bc2a 100644 --- a/cmd/capibmadm/cmd/powervs/key/delete.go +++ b/cmd/capibmadm/cmd/powervs/key/delete.go @@ -25,9 +25,10 @@ import ( "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) // DeleteSSHKeyCommand - child command of 'key' to delete an SSH key. @@ -55,7 +56,7 @@ func deleteSSHKey(ctx context.Context, keyName string) error { logger := log.Log logger.Info("Deleting SSH key...") - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/key/list.go b/cmd/capibmadm/cmd/powervs/key/list.go index 0a67c1d88..cfd662d37 100644 --- a/cmd/capibmadm/cmd/powervs/key/list.go +++ b/cmd/capibmadm/cmd/powervs/key/list.go @@ -27,10 +27,11 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) // ListSSHKeyCommand function to list PowerVS SSH Keys. @@ -55,7 +56,7 @@ func listSSHKeys(ctx context.Context) error { log := logf.Log log.Info("Listing PowerVS SSH Keys", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone) - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/network/create.go b/cmd/capibmadm/cmd/powervs/network/create.go index a201574e6..d8d96f423 100644 --- a/cmd/capibmadm/cmd/powervs/network/create.go +++ b/cmd/capibmadm/cmd/powervs/network/create.go @@ -28,9 +28,10 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) type networkCreateOptions struct { @@ -83,7 +84,7 @@ func createNetwork(ctx context.Context, netCreateOption networkCreateOptions) er log := logf.Log log.Info("Creating PowerVS network", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone) - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/network/delete.go b/cmd/capibmadm/cmd/powervs/network/delete.go index 167ca21f2..6f3937613 100644 --- a/cmd/capibmadm/cmd/powervs/network/delete.go +++ b/cmd/capibmadm/cmd/powervs/network/delete.go @@ -25,9 +25,10 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) // DeleteCommand function to delete network. @@ -55,7 +56,7 @@ func deleteNetwork(ctx context.Context, networkID string) error { log := logf.Log log.Info("Deleting PowerVS network", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone) - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/network/list.go b/cmd/capibmadm/cmd/powervs/network/list.go index cd3c1cb39..fc24a919e 100644 --- a/cmd/capibmadm/cmd/powervs/network/list.go +++ b/cmd/capibmadm/cmd/powervs/network/list.go @@ -27,10 +27,11 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) // ListCommand function to create PowerVS network. @@ -55,7 +56,7 @@ func listNetwork(ctx context.Context) error { log := logf.Log log.Info("Listing PowerVS networks", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone) - accountID, err := utils.GetAccountID(ctx) + accountID, err := utils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/port/create.go b/cmd/capibmadm/cmd/powervs/port/create.go index 174546e0f..ade11cd38 100644 --- a/cmd/capibmadm/cmd/powervs/port/create.go +++ b/cmd/capibmadm/cmd/powervs/port/create.go @@ -28,10 +28,12 @@ import ( "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) type portCreateOptions struct { @@ -66,7 +68,7 @@ capibmadm powervs port create --network --description func createPort(ctx context.Context, portCreateOption portCreateOptions) error { logger := log.Log logger.Info("Creating Port ", "Network ID/Name", portCreateOption.network, "IP Address", portCreateOption.ipAddress, "Description", portCreateOption.description, "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone) - accountID, err := utils.GetAccountID(ctx) + accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth()) if err != nil { return err } diff --git a/cmd/capibmadm/cmd/powervs/port/delete.go b/cmd/capibmadm/cmd/powervs/port/delete.go index bc48563d6..6c894797c 100755 --- a/cmd/capibmadm/cmd/powervs/port/delete.go +++ b/cmd/capibmadm/cmd/powervs/port/delete.go @@ -25,9 +25,10 @@ import ( logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" + "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs" "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options" - "sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" + "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils" ) type portDeleteOptions struct { @@ -61,7 +62,7 @@ capibmadm powervs port delete --port-id --network