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

OCM-11019 | fix: Do not accept clusterID for thumbprint if programmatic #2443

Merged
merged 1 commit into from
Sep 10, 2024
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
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)
}
davidleerh marked this conversation as resolved.
Show resolved Hide resolved
input, err := inputBuilder.Build()
if err != nil {
return err
}
Expand Down