From 78b8fcd69d4045916dab1ab3bc8fe26c30df0cae Mon Sep 17 00:00:00 2001 From: Cortney Reed Date: Thu, 21 Sep 2023 16:49:27 -0400 Subject: [PATCH] [OSD-17502] Update transferowner to get newOwner username --- cmd/cluster/transferowner.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/cluster/transferowner.go b/cmd/cluster/transferowner.go index 2eb40d23..503d5e04 100644 --- a/cmd/cluster/transferowner.go +++ b/cmd/cluster/transferowner.go @@ -34,7 +34,6 @@ type transferOwnerOptions struct { clusterID string newOwnerName string dryrun bool - userName string cluster *cmv1.Cluster genericclioptions.IOStreams @@ -281,18 +280,25 @@ func (o *transferOwnerOptions) run() error { cluster, err := utils.GetClusterAnyStatus(ocm, o.clusterID) o.cluster = cluster o.clusterID = cluster.ID() + + userDetails, err := ocm.AccountsMgmt().V1().Accounts().Account(o.newOwnerName).Get().Send() + userName, ok := userDetails.Body().GetUsername() + if !ok { + return fmt.Errorf("Failed to get username from new user id") + } + // Find and setup all resources that are needed hiveKubeCli, _, hivecClientset, err := getHiveKubeConfigAndClient(o.clusterID) if err != nil { return err } - response, err := ocm.AccountsMgmt().V1().AccessToken().Post().Impersonate(o.userName).Parameter("body", "/dev/null").Send() + response, err := ocm.AccountsMgmt().V1().AccessToken().Post().Impersonate(userName).Parameter("body", "/dev/null").Send() if err != nil { return fmt.Errorf("Can't send request: %v", err) } - _, ok := response.Body().GetAuths() + _, ok = response.Body().GetAuths() if !ok { return fmt.Errorf("Error validating pull secret structure. This shouldn't happen, so you might need to contact SDB") }