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

OSD-25695 - Remove Deprecated Cluster ID (-C) from Account Console Command #612

Merged
Merged
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
59 changes: 2 additions & 57 deletions cmd/account/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func newCmdConsole() *cobra.Command {
consoleCmd.Flags().StringVarP(&ops.awsAccountID, "accountId", "i", "", "AWS Account ID")
consoleCmd.Flags().StringVarP(&ops.awsProfile, "profile", "p", "", "AWS Profile")
consoleCmd.Flags().StringVarP(&ops.region, "region", "r", "", "Region")
consoleCmd.Flags().StringVarP(&ops.clusterID, "clusterID", "C", "", "Cluster ID")

return consoleCmd
}
Expand All @@ -48,7 +47,6 @@ type consoleOptions struct {
awsAccountID string
awsProfile string
region string
clusterID string

consoleDuration int32
}
Expand All @@ -59,26 +57,8 @@ func newConsoleOptions() *consoleOptions {

func (o *consoleOptions) complete(cmd *cobra.Command) error {

var err error

ocmClient, err := utils.CreateConnection()
if err != nil {
return err
}

if o.awsAccountID == "" && o.clusterID == "" {
return fmt.Errorf("please specify -i or -C")
}

if o.awsAccountID != "" && o.clusterID != "" {
return fmt.Errorf("-i and -c are mutually exclusive, please only specify one")
}

if o.clusterID != "" {
o.awsAccountID, err = utils.GetAWSAccountIdForCluster(ocmClient, o.clusterID)
if err != nil {
return err
}
if o.awsAccountID == "" {
return fmt.Errorf("please specify -i")
}

if o.region == "" {
Expand All @@ -90,7 +70,6 @@ func (o *consoleOptions) complete(cmd *cobra.Command) error {

func (o *consoleOptions) run() error {

isCCS := false
var err error

ocmClient, err := utils.CreateConnection()
Expand All @@ -99,14 +78,6 @@ func (o *consoleOptions) run() error {
}
defer ocmClient.Close()

// If a cluster ID was provided, determine if the cluster is CCS
if o.clusterID != "" {
isCCS, err = utils.IsClusterCCS(ocmClient, o.clusterID)
if err != nil {
return err
}
}

// Build the base AWS client using the provide credentials (profile or env vars)
awsClient, err := aws.NewAwsClient(o.awsProfile, o.region, "")
if err != nil {
Expand All @@ -130,32 +101,6 @@ func (o *consoleOptions) run() error {
// By default, the target role arn is OrganizationAccountAccessRole (works for -i and non-CCS clusters)
targetRoleArnString := aws.GenerateRoleARN(o.awsAccountID, osdCloud.OrganizationAccountAccessRole)

if isCCS {
// If a cluster is provided and it's CCS, the target role is the Managed Support role arn
targetRoleArnString, err = utils.GetSupportRoleArnForCluster(ocmClient, o.clusterID)
if err != nil {
return err
}

// The AWS client used to generate the URL should be the jump role for CCS clusters
jumpRoleCreds, err := osdCloud.GenerateJumpRoleCredentials(awsClient, o.region, sessionName)
if err != nil {
return err
}

awsClient, err = aws.NewAwsClientWithInput(
&aws.ClientInput{
AccessKeyID: *jumpRoleCreds.AccessKeyId,
SecretAccessKey: *jumpRoleCreds.SecretAccessKey,
SessionToken: *jumpRoleCreds.SessionToken,
Region: o.region,
},
)
if err != nil {
return err
}
}

targetRoleArn, err := arn.Parse(targetRoleArnString)
if err != nil {
return err
Expand Down