From 49f4e41747d8eb57feb9f572c4c25b1950a8a70f Mon Sep 17 00:00:00 2001 From: Jakob Gray <20209054+JakobGray@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:46:45 -0400 Subject: [PATCH] Set project number on wif config creation --- cmd/ocm/gcp/create-wif-config.go | 15 ++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/ocm/gcp/create-wif-config.go b/cmd/ocm/gcp/create-wif-config.go index b97a8dc0..84caee42 100644 --- a/cmd/ocm/gcp/create-wif-config.go +++ b/cmd/ocm/gcp/create-wif-config.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "reflect" + "strconv" "strings" "github.com/googleapis/gax-go/v2/apierror" @@ -70,7 +71,7 @@ func createWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) e } log.Println("Creating workload identity configuration...") - wifConfig, err := createWorkloadIdentityConfiguration(CreateWifConfigOpts.Name, CreateWifConfigOpts.Project) + wifConfig, err := createWorkloadIdentityConfiguration(gcpClient, CreateWifConfigOpts.Name, CreateWifConfigOpts.Project) if err != nil { return errors.Wrapf(err, "failed to create WIF config") } @@ -138,7 +139,13 @@ func validationForCreateWorkloadIdentityConfigurationCmd(cmd *cobra.Command, arg return nil } -func createWorkloadIdentityConfiguration(displayName, projectId string) (*cmv1.WifConfig, error) { +func createWorkloadIdentityConfiguration(client gcp.GcpClient, displayName, projectId string) (*cmv1.WifConfig, error) { + + projectNum, err := client.ProjectNumberFromId(projectId) + if err != nil { + return nil, errors.Wrapf(err, "failed to get GCP project number from project id") + } + connection, err := ocm.NewConnection().Build() if err != nil { return nil, errors.Wrapf(err, "Failed to create OCM connection") @@ -146,7 +153,9 @@ func createWorkloadIdentityConfiguration(displayName, projectId string) (*cmv1.W defer connection.Close() wifBuilder := cmv1.NewWifConfig() - gcpBuilder := cmv1.NewWifGcp().ProjectId(projectId) + gcpBuilder := cmv1.NewWifGcp(). + ProjectId(projectId). + ProjectNumber(strconv.FormatInt(projectNum, 10)) wifBuilder.DisplayName(displayName) wifBuilder.Gcp(gcpBuilder) diff --git a/go.mod b/go.mod index 500bedb7..18b3afb8 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.433 + github.com/openshift-online/ocm-sdk-go v0.1.434 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 4de12fa3..c8f1b297 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.433 h1:8i0Si9KrFkMprMBGR1a4ppmgVezMBjjXXkvhv28OVUk= -github.com/openshift-online/ocm-sdk-go v0.1.433/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y= +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/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=