From 564e7955e625a7f99b82a5fcbd102fe33665a032 Mon Sep 17 00:00:00 2001 From: Jakob Gray <20209054+JakobGray@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:34:35 -0400 Subject: [PATCH] Add role prefix flag on create wif-config --- cmd/ocm/gcp/create-wif-config.go | 16 +++++++++++----- cmd/ocm/gcp/gcp.go | 1 + go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/ocm/gcp/create-wif-config.go b/cmd/ocm/gcp/create-wif-config.go index 84caee42..8c4b4a05 100644 --- a/cmd/ocm/gcp/create-wif-config.go +++ b/cmd/ocm/gcp/create-wif-config.go @@ -27,10 +27,11 @@ import ( var ( // CreateWifConfigOpts captures the options that affect creation of the workload identity configuration CreateWifConfigOpts = options{ - DryRun: false, - Name: "", - Project: "", - TargetDir: "", + DryRun: false, + Name: "", + Project: "", + RolePrefix: "", + TargetDir: "", } ) @@ -54,6 +55,8 @@ func NewCreateWorkloadIdentityConfiguration() *cobra.Command { createWifConfigCmd.PersistentFlags().StringVar(&CreateWifConfigOpts.Project, "project", "", "ID of the Google cloud project") createWifConfigCmd.MarkPersistentFlagRequired("project") + createWifConfigCmd.PersistentFlags().StringVar(&CreateWifConfigOpts.RolePrefix, "role-prefix", "", + "Prefix for naming custom roles") createWifConfigCmd.PersistentFlags().BoolVar(&CreateWifConfigOpts.DryRun, "dry-run", false, "Skip creating objects, and just save what would have been created into files") createWifConfigCmd.PersistentFlags().StringVar(&CreateWifConfigOpts.TargetDir, "output-dir", "", @@ -157,9 +160,12 @@ func createWorkloadIdentityConfiguration(client gcp.GcpClient, displayName, proj ProjectId(projectId). ProjectNumber(strconv.FormatInt(projectNum, 10)) - wifBuilder.DisplayName(displayName) + if CreateWifConfigOpts.RolePrefix != "" { + gcpBuilder.RolePrefix(CreateWifConfigOpts.RolePrefix) + } wifBuilder.Gcp(gcpBuilder) + wifBuilder.DisplayName(displayName) wifConfigInput, err := wifBuilder.Build() if err != nil { return nil, errors.Wrap(err, "failed to build WIF config") diff --git a/cmd/ocm/gcp/gcp.go b/cmd/ocm/gcp/gcp.go index ea1ac047..9cbbc68b 100644 --- a/cmd/ocm/gcp/gcp.go +++ b/cmd/ocm/gcp/gcp.go @@ -9,6 +9,7 @@ type options struct { Region string Name string Project string + RolePrefix string WorkloadIdentityPool string WorkloadIdentityProvider string DryRun bool diff --git a/go.mod b/go.mod index 18b3afb8..b13b626b 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/nwidger/jsoncolor v0.3.2 github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.8 - github.com/openshift-online/ocm-sdk-go v0.1.434 + github.com/openshift-online/ocm-sdk-go v0.1.437 github.com/openshift/rosa v1.2.24 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index c8f1b297..392cf96b 100644 --- a/go.sum +++ b/go.sum @@ -361,8 +361,8 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ= -github.com/openshift-online/ocm-sdk-go v0.1.434 h1:5AbNG+Nci9Z3AaT6qzkK2QG/u1RpeJHjE5YcWqtU4rw= -github.com/openshift-online/ocm-sdk-go v0.1.434/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y= +github.com/openshift-online/ocm-sdk-go v0.1.437 h1:2xFFOu3lvrrA0wfz4zUmX7UxcWQvqfbgBWelLLB5T2I= +github.com/openshift-online/ocm-sdk-go v0.1.437/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y= github.com/openshift/rosa v1.2.24 h1:vv0yYnWHx6CCPEAau/0rS54P2ksaf+uWXb1TQPWxiYE= github.com/openshift/rosa v1.2.24/go.mod h1:MVXB27O3PF8WoOic23I03mmq6/9kVxpFx6FKyLMCyrQ= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=