Skip to content

Commit

Permalink
Address Polaris AWS API changes (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
johan3141592 authored Mar 17, 2022
1 parent 1936263 commit 8b0c9ee
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 8 deletions.
12 changes: 10 additions & 2 deletions pkg/polaris/graphql/aws/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func (a API) FinalizeCloudAccountProtection(ctx context.Context, id, name string
query := finalizeAwsCloudAccountProtectionQuery
if graphql.VersionOlderThan(a.Version, "master-46133", "v20220315") {
query = finalizeAwsCloudAccountProtectionV0Query
} else if graphql.VersionOlderThan(a.Version, "master-46203", "v20220322") {
query = finalizeAwsCloudAccountProtectionV1Query
}
buf, err := a.GQL.Request(ctx, query, struct {
ID string `json:"nativeId"`
Expand Down Expand Up @@ -331,6 +333,8 @@ func (a API) UpdateCloudAccount(ctx context.Context, action core.CloudAccountAct
query := updateAwsCloudAccountQuery
if graphql.VersionOlderThan(a.Version, "master-46133", "v20220315") {
query = updateAwsCloudAccountV0Query
} else if graphql.VersionOlderThan(a.Version, "master-46203", "v20220322") {
query = updateAwsCloudAccountV1Query
}
buf, err := a.GQL.Request(ctx, query, struct {
Action core.CloudAccountAction `json:"action"`
Expand Down Expand Up @@ -383,15 +387,19 @@ type VPC struct {
func (a API) AllVpcsByRegion(ctx context.Context, id uuid.UUID, regions Region) ([]VPC, error) {
a.GQL.Log().Print(log.Trace)

buf, err := a.GQL.Request(ctx, allVpcsByRegionFromAwsQuery, struct {
query := allVpcsByRegionFromAwsQuery
if graphql.VersionOlderThan(a.Version, "master-46203", "v20220322") {
query = allVpcsByRegionFromAwsV0Query
}
buf, err := a.GQL.Request(ctx, query, struct {
ID uuid.UUID `json:"awsAccountRubrikId"`
Region Region `json:"region"`
}{ID: id, Region: regions})
if err != nil {
return nil, fmt.Errorf("failed to request AllVpcsByRegion: %v", err)
}

a.GQL.Log().Printf(log.Debug, "allVpcsByRegionFromAws(%q, %q): %s", id, regions, string(buf))
a.GQL.Log().Printf(log.Debug, "%s(%q, %q): %s", graphql.QueryName(query), id, regions, string(buf))

var payload struct {
Data struct {
Expand Down
53 changes: 50 additions & 3 deletions pkg/polaris/graphql/aws/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,4 +1,4 @@
query RubrikPolarisSDKRequest($awsAccountRubrikId: UUID!, $region: AwsNativeRegionEnum!) {
query RubrikPolarisSDKRequest($awsAccountRubrikId: UUID!, $region: AwsNativeRegion!) {
allVpcsByRegionFromAws(awsAccountRubrikId: $awsAccountRubrikId, region: $region) {
id
name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query RubrikPolarisSDKRequest($awsAccountRubrikId: UUID!, $region: AwsNativeRegionEnum!) {
allVpcsByRegionFromAws(awsAccountRubrikId: $awsAccountRubrikId, region: $region) {
id
name
subnets {
id
name
availabilityZone
}
securityGroups {
id
name
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation RubrikPolarisSDKRequest($nativeId: String!, $accountName: String!, $awsRegions: [AwsCloudAccountRegionEnum!], $externalId: String!, $featureVersion: [AwsCloudAccountFeatureVersionInput!]!, $feature: CloudAccountFeature!, $stackName: String!) {
mutation RubrikPolarisSDKRequest($nativeId: String!, $accountName: String!, $awsRegions: [AwsCloudAccountRegion!], $externalId: String!, $featureVersion: [AwsCloudAccountFeatureVersionInput!]!, $feature: CloudAccountFeature!, $stackName: String!) {
finalizeAwsCloudAccountProtection(input: {
action: CREATE,
awsChildAccounts: [{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mutation RubrikPolarisSDKRequest($nativeId: String!, $accountName: String!, $awsRegions: [AwsCloudAccountRegionEnum!], $externalId: String!, $featureVersion: [AwsCloudAccountFeatureVersionInput!]!, $feature: CloudAccountFeature!, $stackName: String!) {
finalizeAwsCloudAccountProtection(input: {
action: CREATE,
awsChildAccounts: [{
accountName: $accountName,
nativeId: $nativeId,
}],
awsRegions: $awsRegions,
externalId: $externalId,
featureVersion: $featureVersion,
features: [$feature],
stackName: $stackName,
}) {
awsChildAccounts {
accountName
nativeId
message
}
message
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountActionEnum!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegionEnum!]!, $feature: CloudAccountFeature!) {
mutation RubrikPolarisSDKRequest($action: CloudAccountAction!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegion!]!, $feature: CloudAccountFeature!) {
updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountActionEnum!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegionEnum!]!, $feature: CloudAccountFeature!) {
updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
}

0 comments on commit 8b0c9ee

Please sign in to comment.