Skip to content

Commit

Permalink
Merge pull request #654 from JakobGray/wifprojectnumber
Browse files Browse the repository at this point in the history
Set project number on wif config creation
  • Loading branch information
ckandag authored Aug 5, 2024
2 parents 57ce1d5 + 49f4e41 commit 70b8184
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions cmd/ocm/gcp/create-wif-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"reflect"
"strconv"
"strings"

"github.com/googleapis/gax-go/v2/apierror"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -138,15 +139,23 @@ 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")
}
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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 70b8184

Please sign in to comment.