Skip to content

Commit

Permalink
Merge pull request #2443 from hunterkepley/ocm-11019
Browse files Browse the repository at this point in the history
OCM-11019 | fix: Do not accept clusterID for thumbprint if programmatic
  • Loading branch information
openshift-merge-bot[bot] committed Sep 10, 2024
2 parents 99e2b4e + eb6416b commit 90494f7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/create/oidcprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func run(cmd *cobra.Command, argv []string) {
defer r.Cleanup()

// Allow the command to be called programmatically
isProgmaticallyCalled := false
isProgrammaticallyCalled := false
shouldUseClusterKey := true
if len(argv) >= 3 && !cmd.Flag("cluster").Changed {
ocm.SetClusterKey(argv[0])
interactive.SetModeKey(argv[1])

if argv[1] != "" {
isProgmaticallyCalled = true
isProgrammaticallyCalled = true
}

if argv[2] != "" {
Expand All @@ -107,14 +107,14 @@ func run(cmd *cobra.Command, argv []string) {
}

// Determine if interactive mode is needed
if !isProgmaticallyCalled && !interactive.Enabled() &&
if !isProgrammaticallyCalled && !interactive.Enabled() &&
(!cmd.Flags().Changed("cluster") || !cmd.Flags().Changed("mode")) {
interactive.Enable()
}

var cluster *cmv1.Cluster
clusterKey := ""
if cmd.Flags().Changed("cluster") || (isProgmaticallyCalled && shouldUseClusterKey) {
if cmd.Flags().Changed("cluster") || (isProgrammaticallyCalled && shouldUseClusterKey) {
clusterKey = r.GetClusterKey()
cluster = r.FetchCluster()
if !ocm.IsSts(cluster) {
Expand All @@ -123,7 +123,7 @@ func run(cmd *cobra.Command, argv []string) {
}
}

if !cmd.Flags().Changed("mode") && interactive.Enabled() && !isProgmaticallyCalled {
if !cmd.Flags().Changed("mode") && interactive.Enabled() && !isProgrammaticallyCalled {
mode, err = interactive.GetOptionMode(cmd, mode, "OIDC provider creation mode")
if err != nil {
r.Reporter.Errorf("Expected a valid OIDC provider creation mode: %s", err)
Expand All @@ -135,7 +135,7 @@ func run(cmd *cobra.Command, argv []string) {
if cluster != nil {
oidcEndpointURL = cluster.AWS().STS().OIDCEndpointURL()
} else {
if isProgmaticallyCalled && args.oidcEndpointUrl != "" {
if isProgrammaticallyCalled && args.oidcEndpointUrl != "" {
oidcEndpointURL = args.oidcEndpointUrl
} else {
if args.oidcConfigId == "" {
Expand Down Expand Up @@ -192,7 +192,7 @@ func run(cmd *cobra.Command, argv []string) {
if clusterId == "" {
clusterId = cmd.Flag("cluster").Value.String()
}
err = createProvider(r, oidcEndpointURL, clusterId)
err = createProvider(r, oidcEndpointURL, clusterId, isProgrammaticallyCalled)
if err != nil {
r.Reporter.Errorf("There was an error creating the OIDC provider: %s", err)
r.OCMClient.LogEvent("ROSACreateOIDCProviderModeAuto", map[string]string{
Expand Down Expand Up @@ -228,8 +228,14 @@ func run(cmd *cobra.Command, argv []string) {
}
}

func createProvider(r *rosa.Runtime, oidcEndpointUrl string, clusterId string) error {
input, err := cmv1.NewOidcThumbprintInput().OidcConfigId(args.oidcConfigId).ClusterId(clusterId).Build()
func createProvider(r *rosa.Runtime, oidcEndpointUrl string, clusterId string, isProgrammaticallyCalled bool) error {
inputBuilder := cmv1.NewOidcThumbprintInput()
if isProgrammaticallyCalled || clusterId == "" {
inputBuilder.OidcConfigId(args.oidcConfigId)
} else {
inputBuilder.ClusterId(clusterId)
}
input, err := inputBuilder.Build()
if err != nil {
return err
}
Expand Down

0 comments on commit 90494f7

Please sign in to comment.