Skip to content

Commit

Permalink
Merge pull request #854 from gdbranco/feat/#452-output-create-admin
Browse files Browse the repository at this point in the history
[SDA-5272] feat: add --output json/yaml to create admin, omit when passwordArg is set
  • Loading branch information
openshift-merge-robot authored Oct 3, 2022
2 parents 12cbfea + f234cb8 commit bf1432e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/create/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/spf13/cobra"

"github.com/openshift/rosa/cmd/create/idp"
"github.com/openshift/rosa/pkg/object"
"github.com/openshift/rosa/pkg/ocm"
"github.com/openshift/rosa/pkg/output"
"github.com/openshift/rosa/pkg/rosa"
)

Expand All @@ -52,6 +54,7 @@ func init() {
"",
"Choice of password for admin user.",
)
output.AddFlag(Cmd)
}

func run(cmd *cobra.Command, _ []string) {
Expand Down Expand Up @@ -154,11 +157,30 @@ func run(cmd *cobra.Command, _ []string) {
}
}

outputObject := object.Object{
"api_url": cluster.API().URL(),
"username": idp.ClusterAdminUsername,
"password": password,
}

if output.HasFlag() {
if len(passwordArg) != 0 {
delete(outputObject, "password")
}
err = output.Print(outputObject)
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
return
}

r.Reporter.Infof("Admin account has been added to cluster '%s'.", clusterKey)
r.Reporter.Infof("Please securely store this generated password. " +
"If you lose this password you can delete and recreate the cluster admin user.")
r.Reporter.Infof("To login, run the following command:\n\n"+
" oc login %s --username %s --password %s\n", cluster.API().URL(), idp.ClusterAdminUsername, password)
" oc login %s --username %s --password %s\n",
outputObject["api_url"], outputObject["username"], outputObject["password"])
r.Reporter.Infof("It may take up to a minute for the account to become active.")
}

Expand Down

0 comments on commit bf1432e

Please sign in to comment.