Skip to content

Commit

Permalink
wif-enable gcp-inquiries
Browse files Browse the repository at this point in the history
Signed-off-by: Chaitanya Kandagatla <[email protected]>
  • Loading branch information
ckandag committed Oct 14, 2024
1 parent cf6e500 commit 20cd61f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/ocm/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ func promptExistingGCPVPC(fs *pflag.FlagSet, connection *sdk.Connection) error {
if !useSharedVpc {
//get vpc's from the provider
vpcList, err := provider.GetGCPVPCs(connection.ClustersMgmt().V1(),
args.ccs, args.region)
args.ccs, args.gcpAuthentication, args.region)
if err != nil {
return err
}
Expand All @@ -1252,7 +1252,7 @@ func promptExistingGCPVPC(fs *pflag.FlagSet, connection *sdk.Connection) error {

//get subnets from the provider
subnetList, err := provider.GetGCPSubnetList(connection.ClustersMgmt().V1(), args.provider,
args.ccs, args.region)
args.ccs, args.gcpAuthentication, args.region)
if err != nil {
return err
}
Expand Down
27 changes: 21 additions & 6 deletions pkg/provider/subnetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ func getAWSVPCs(client *cmv1.Client, ccs cluster.CCS,
}

func GetGCPVPCs(client *cmv1.Client, ccs cluster.CCS,
region string) (cloudVPCList []*cmv1.CloudVPC, err error) {
gcpAuth cluster.GcpAuthentication, region string) (cloudVPCList []*cmv1.CloudVPC, err error) {

cloudProviderData, err := cmv1.NewCloudProviderData().
GCP(cmv1.NewGCP().ProjectID(ccs.GCP.ProjectID).
gcpBuilder := cmv1.NewGCP()

switch gcpAuth.Type {
case cluster.AuthenticationWif:
gcpAuth := cmv1.NewGcpAuthentication().
Kind(cmv1.WifConfigKind).
Id(gcpAuth.Id)
gcpBuilder.Authentication(gcpAuth)
case cluster.AuthenticationKey:
gcpBuilder.ProjectID(ccs.GCP.ProjectID).
ClientEmail(ccs.GCP.ClientEmail).
Type(ccs.GCP.Type).
PrivateKey(ccs.GCP.PrivateKey).
PrivateKeyID(ccs.GCP.PrivateKeyID).
AuthProviderX509CertURL(ccs.GCP.AuthProviderX509CertURL).
AuthURI(ccs.GCP.AuthURI).TokenURI(ccs.GCP.TokenURI).
ClientX509CertURL(ccs.GCP.ClientX509CertURL).
ClientID(ccs.GCP.ClientID).TokenURI(ccs.GCP.TokenURI)).
ClientID(ccs.GCP.ClientID).TokenURI(ccs.GCP.TokenURI)
default:
return nil, fmt.Errorf("Failed to build GCP provider data, unexpected GCP authentication method %q", gcpAuth.Type)
}

cloudProviderData, err := cmv1.NewCloudProviderData().
GCP(gcpBuilder).
Region(cmv1.NewCloudRegion().ID(region)).
Build()
if err != nil {
Expand Down Expand Up @@ -73,9 +87,10 @@ func GetAWSSubnetworks(client *cmv1.Client, ccs cluster.CCS,
}

func GetGCPSubnetList(client *cmv1.Client, provider string, ccs cluster.CCS,
region string) (subnetList []string, err error) {
gcpAuth cluster.GcpAuthentication, region string) (subnetList []string, err error) {
if ccs.Enabled && provider == "gcp" {
cloudVPCs, err := GetGCPVPCs(client, ccs, region)

cloudVPCs, err := GetGCPVPCs(client, ccs, gcpAuth, region)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 20cd61f

Please sign in to comment.