Skip to content

Commit

Permalink
Address Polaris AWS API changes (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
johan3141592 authored May 16, 2022
1 parent f992e05 commit 6a10af4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/polaris/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (a API) UpdateAccount(ctx context.Context, id IdentityFunc, feature core.Fe
return fmt.Errorf("failed to get account: %v", err)
}

err = aws.Wrap(a.gql).UpdateCloudAccount(ctx, core.UpdateRegions, account.ID, feature, options.regions)
err = aws.Wrap(a.gql).UpdateCloudAccountFeature(ctx, core.UpdateRegions, account.ID, feature, options.regions)
if err != nil {
return fmt.Errorf("failed to update account: %v", err)
}
Expand Down
18 changes: 10 additions & 8 deletions pkg/polaris/graphql/aws/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,19 @@ func (a API) FinalizeCloudAccountDeletion(ctx context.Context, id uuid.UUID, fea
return nil
}

// UpdateCloudAccount updates the settings of the cloud account. The message
// returned by the GraphQL API call is converted into a Go error. At this time
// only the regions can be updated.
func (a API) UpdateCloudAccount(ctx context.Context, action core.CloudAccountAction, id uuid.UUID, feature core.Feature, regions []Region) error {
// UpdateCloudAccountFeature updates the settings of the cloud account. The
// message returned by the GraphQL API call is converted into a Go error. At
// this time only the regions can be updated.
func (a API) UpdateCloudAccountFeature(ctx context.Context, action core.CloudAccountAction, id uuid.UUID, feature core.Feature, regions []Region) error {
a.GQL.Log().Print(log.Trace)

query := updateAwsCloudAccountQuery
if graphql.VersionOlderThan(a.Version, "master-46133", "v20220315") {
query = updateAwsCloudAccountV0Query
} else if graphql.VersionOlderThan(a.Version, "master-46203", "v20220322") {
query = updateAwsCloudAccountV1Query
} else if graphql.VersionOlderThan(a.Version, "master-47593", "v20220516") {
query = updateAwsCloudAccountV2Query
}
buf, err := a.GQL.Request(ctx, query, struct {
Action core.CloudAccountAction `json:"action"`
Expand All @@ -350,18 +352,18 @@ func (a API) UpdateCloudAccount(ctx context.Context, action core.CloudAccountAct

var payload struct {
Data struct {
Query struct {
Result struct {
Message string `json:"message"`
} `json:"updateAwsCloudAccount"`
} `json:"result"`
} `json:"data"`
}
if err := json.Unmarshal(buf, &payload); err != nil {
return fmt.Errorf("failed to unmarshal UpdateCloudAccount: %v", err)
}

// On success the message starts with "successfully".
if !strings.HasPrefix(strings.ToLower(payload.Data.Query.Message), "successfully") {
return errors.New(payload.Data.Query.Message)
if !strings.HasPrefix(strings.ToLower(payload.Data.Result.Message), "successfully") {
return errors.New(payload.Data.Result.Message)
}

return nil
Expand Down
13 changes: 10 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,5 +1,5 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountAction!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegion!]!, $feature: CloudAccountFeature!) {
updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
result: updateAwsCloudAccountFeature(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountActionEnum!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegionEnum!]!, $feature: CloudAccountFeatureEnum!) {
updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
result: updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountActionEnum!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegionEnum!]!, $feature: CloudAccountFeature!) {
updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
result: updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation RubrikPolarisSDKRequest($action: CloudAccountAction!, $cloudAccountId: UUID!, $awsRegions: [AwsCloudAccountRegion!]!, $feature: CloudAccountFeature!) {
result: updateAwsCloudAccount(input: {action: $action, cloudAccountId: $cloudAccountId, awsRegions: $awsRegions, feature: $feature}) {
message
}
}

0 comments on commit 6a10af4

Please sign in to comment.