Skip to content

Commit

Permalink
Address Polaris GCP API changes (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
johan3141592 authored Apr 22, 2022
1 parent 758c5f0 commit 2c4bf02
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 39 deletions.
29 changes: 19 additions & 10 deletions pkg/polaris/graphql/gcp/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,22 @@ func (a API) CloudAccountAddManualAuthProject(ctx context.Context, projectID, pr
query := gcpCloudAccountAddManualAuthProjectQuery
if graphql.VersionOlderThan(a.Version, "master-46133", "v20220315") {
query = gcpCloudAccountAddManualAuthProjectV0Query
} else if graphql.VersionOlderThan(a.Version, "master-47076", "v20220426") {
query = gcpCloudAccountAddManualAuthProjectV1Query
}
_, err := a.GQL.Request(ctx, query, struct {
Feature core.Feature `json:"feature"`
ID string `json:"gcpNativeProjectId"`
Name string `json:"gcpProjectName"`
Number int64 `json:"gcpProjectNumber"`
OrgName string `json:"organizationName,omitempty"`
JwtConfig string `json:"serviceAccountJwtConfigOptional,omitempty"`
}{Feature: feature, ID: projectID, Name: projectName, Number: projectNumber, OrgName: orgName, JwtConfig: jwtConfig})
ID string `json:"gcpNativeProjectId"`
Name string `json:"gcpProjectName"`
Number int64 `json:"gcpProjectNumber"`
OrgName string `json:"organizationName,omitempty"`
JwtConfig string `json:"serviceAccountJwtConfig,omitempty"`
JwtConfigOpt string `json:"serviceAccountJwtConfigOptional,omitempty"`
Feature core.Feature `json:"feature"`
}{ID: projectID, Name: projectName, Number: projectNumber, OrgName: orgName, JwtConfig: jwtConfig, JwtConfigOpt: jwtConfig, Feature: feature})
if err != nil {
return fmt.Errorf("failed to request CloudAccountAddManualAuthProject: %v", err)
}

return nil
}

Expand All @@ -119,14 +123,19 @@ func (a API) CloudAccountAddManualAuthProject(ctx context.Context, projectID, pr
func (a API) CloudAccountDeleteProject(ctx context.Context, id uuid.UUID) error {
a.GQL.Log().Print(log.Trace)

buf, err := a.GQL.Request(ctx, gcpCloudAccountDeleteProjectsQuery, struct {
query := gcpCloudAccountDeleteProjectsQuery
if graphql.VersionOlderThan(a.Version, "master-47076", "v20220426") {
query = gcpCloudAccountDeleteProjectsV0Query
}
buf, err := a.GQL.Request(ctx, query, struct {
ID uuid.UUID `json:"nativeProtectionProjectId"`
IDs []uuid.UUID `json:"nativeProtectionProjectUuids"`
}{IDs: []uuid.UUID{id}})
}{ID: id, IDs: []uuid.UUID{id}})
if err != nil {
return fmt.Errorf("failed to request CloudAccountDeleteProject: %v", err)
}

a.GQL.Log().Printf(log.Debug, "gcpCloudAccountDeleteProjects(%q): %s", []uuid.UUID{id}, string(buf))
a.GQL.Log().Printf(log.Debug, "%s(%q): %s", graphql.QueryName(query), id, string(buf))

var payload struct {
Data struct {
Expand Down
11 changes: 8 additions & 3 deletions pkg/polaris/graphql/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ func (a API) DefaultCredentialsServiceAccount(ctx context.Context) (name string,
func (a API) SetDefaultServiceAccount(ctx context.Context, name, jwtConfig string) error {
a.GQL.Log().Print(log.Trace)

buf, err := a.GQL.Request(ctx, gcpSetDefaultServiceAccountJwtConfigQuery, struct {
query := gcpSetDefaultServiceAccountJwtConfigQuery
if graphql.VersionOlderThan(a.Version, "master-47076", "v20220426") {
query = gcpSetDefaultServiceAccountJwtConfigV0Query
}
buf, err := a.GQL.Request(ctx, query, struct {
Name string `json:"serviceAccountName"`
JwtConfig string `json:"serviceAccountJWTConfig"`
JwtConfig string `json:"serviceAccountJwtConfig"`
}{Name: name, JwtConfig: jwtConfig})
if err != nil {
return fmt.Errorf("failed to request SetDefaultServiceAccount: %v", err)
}

a.GQL.Log().Printf(log.Debug, "gcpSetDefaultServiceAccount(%q, %q): %s", name, jwtConfig, string(buf))
a.GQL.Log().Printf(log.Debug, "%s(%q, %q): %s", graphql.QueryName(query), name, jwtConfig,
string(buf))

var payload struct {
Data struct {
Expand Down
10 changes: 10 additions & 0 deletions pkg/polaris/graphql/gcp/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package gcp
import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/google/uuid"
Expand Down Expand Up @@ -132,6 +133,8 @@ func (a API) NativeDisableProject(ctx context.Context, id uuid.UUID, deleteSnaps
query := gcpNativeDisableProjectQuery
if graphql.VersionOlderThan(a.Version, "master-46700", "v20220412") {
query = gcpNativeDisableProjectV0Query
} else if graphql.VersionOlderThan(a.Version, "master-47076", "v20220426") {
query = gcpNativeDisableProjectV1Query
}
buf, err := a.GQL.Request(ctx, query, struct {
ID uuid.UUID `json:"projectId"`
Expand All @@ -148,6 +151,7 @@ func (a API) NativeDisableProject(ctx context.Context, id uuid.UUID, deleteSnaps
Query struct {
JobID uuid.UUID `json:"jobId"`
TaskChainID uuid.UUID `json:"taskchainUuid"`
Error string `json:"error"`
} `json:"gcpNativeDisableProject"`
} `json:"data"`
}
Expand All @@ -158,5 +162,11 @@ func (a API) NativeDisableProject(ctx context.Context, id uuid.UUID, deleteSnaps
if graphql.VersionOlderThan(a.Version, "master-46700", "v20220412") {
return payload.Data.Query.TaskChainID, nil
}
if graphql.VersionOlderThan(a.Version, "master-47076", "v20220426") {
return payload.Data.Query.JobID, nil
}
if payload.Data.Query.Error != "" {
return uuid.Nil, errors.New(payload.Data.Query.Error)
}
return payload.Data.Query.JobID, nil
}
61 changes: 52 additions & 9 deletions pkg/polaris/graphql/gcp/queries.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mutation RubrikPolarisSDKRequest($feature: CloudAccountFeature!, $gcpNativeProjectId: String!, $gcpProjectName: String!, $gcpProjectNumber: Long!, $organizationName: String, $serviceAccountJwtConfigOptional: String)
{
gcpCloudAccountAddManualAuthProject(
features: [$feature],
gcpNativeProjectId: $gcpNativeProjectId,
gcpProjectName: $gcpProjectName,
gcpProjectNumber: $gcpProjectNumber,
organizationName: $organizationName,
serviceAccountJwtConfigOptional: $serviceAccountJwtConfigOptional,
)
mutation RubrikPolarisSDKRequest($gcpNativeProjectId: String!, $gcpProjectName: String!, $gcpProjectNumber: Long!, $organizationName: String, $serviceAccountJwtConfig: String, $feature: CloudAccountFeature!) {
gcpCloudAccountAddManualAuthProject(input: {
gcpNativeProjectId: $gcpNativeProjectId,
gcpProjectName: $gcpProjectName,
gcpProjectNumber: $gcpProjectNumber,
organizationName: $organizationName,
serviceAccountJwtConfig: $serviceAccountJwtConfig,
features: [$feature],
})
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mutation RubrikPolarisSDKRequest($feature: CloudAccountFeatureEnum!, $gcpNativeProjectId: String!, $gcpProjectName: String!, $gcpProjectNumber: Long!, $organizationName: String, $serviceAccountJwtConfigOptional: String)
{
mutation RubrikPolarisSDKRequest($feature: CloudAccountFeatureEnum!, $gcpNativeProjectId: String!, $gcpProjectName: String!, $gcpProjectNumber: Long!, $organizationName: String, $serviceAccountJwtConfigOptional: String) {
gcpCloudAccountAddManualAuthProject(
features: [$feature],
gcpNativeProjectId: $gcpNativeProjectId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation RubrikPolarisSDKRequest($feature: CloudAccountFeature!, $gcpNativeProjectId: String!, $gcpProjectName: String!, $gcpProjectNumber: Long!, $organizationName: String, $serviceAccountJwtConfigOptional: String) {
gcpCloudAccountAddManualAuthProject(
features: [$feature],
gcpNativeProjectId: $gcpNativeProjectId,
gcpProjectName: $gcpProjectName,
gcpProjectNumber: $gcpProjectNumber,
organizationName: $organizationName,
serviceAccountJwtConfigOptional: $serviceAccountJwtConfigOptional,
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
mutation RubrikPolarisSDKRequest($nativeProtectionProjectUuids: [UUID!]!) {
gcpCloudAccountDeleteProjects(nativeProtectionProjectUuids: $nativeProtectionProjectUuids, sharedVpcHostProjectUuids: [], cloudAccountsProjectUuids: [], skipResourceDeletion: true) {
mutation RubrikPolarisSDKRequest($nativeProtectionProjectId: UUID!) {
gcpCloudAccountDeleteProjects(input: {
nativeProtectionProjectIds: [$nativeProtectionProjectId],
sharedVpcHostProjectIds: [],
cloudAccountsProjectIds: [],
skipResourceDeletion: true,
}) {
projectUuid
success
error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation RubrikPolarisSDKRequest($nativeProtectionProjectUuids: [UUID!]!) {
gcpCloudAccountDeleteProjects(nativeProtectionProjectUuids: $nativeProtectionProjectUuids, sharedVpcHostProjectUuids: [], cloudAccountsProjectUuids: [], skipResourceDeletion: true) {
projectUuid
success
error
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mutation RubrikPolarisSDKRequest($projectId: UUID!, $shouldDeleteNativeSnapshots: Boolean!) {
gcpNativeDisableProject(projectId: $projectId, shouldDeleteNativeSnapshots: $shouldDeleteNativeSnapshots) {
gcpNativeDisableProject(input: {
projectId: $projectId,
shouldDeleteNativeSnapshots: $shouldDeleteNativeSnapshots
}) {
jobId
error
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation RubrikPolarisSDKRequest($projectId: UUID!, $shouldDeleteNativeSnapshots: Boolean!) {
gcpNativeDisableProject(projectId: $projectId, shouldDeleteNativeSnapshots: $shouldDeleteNativeSnapshots) {
jobId
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mutation RubrikPolarisSDKRequest($serviceAccountName: String!, $serviceAccountJWTConfig: String!) {
gcpSetDefaultServiceAccountJwtConfig(serviceAccountJWTConfig: $serviceAccountJWTConfig, serviceAccountName: $serviceAccountName)
mutation RubrikPolarisSDKRequest($serviceAccountName: String!, $serviceAccountJwtConfig: String!) {
gcpSetDefaultServiceAccountJwtConfig(input: {
serviceAccountJwtConfig: $serviceAccountJwtConfig,
serviceAccountName: $serviceAccountName,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation RubrikPolarisSDKRequest($serviceAccountName: String!, $serviceAccountJwtConfig: String!) {
gcpSetDefaultServiceAccountJwtConfig(serviceAccountJWTConfig: $serviceAccountJwtConfig, serviceAccountName: $serviceAccountName)
}

0 comments on commit 2c4bf02

Please sign in to comment.