Skip to content

Commit

Permalink
Merge commit '4842a73b0529310557c2c30138d790e08d842069' into release
Browse files Browse the repository at this point in the history
* commit '4842a73b0529310557c2c30138d790e08d842069':
  service/rds: add customization for additional presigned URL method
  • Loading branch information
awssdkgo committed Dec 4, 2020
2 parents 3728291 + 4842a73 commit d3b0b60
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
4 changes: 3 additions & 1 deletion private/model/api/customization_passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,15 @@ func mergeServicesCustomizations(a *API) error {
return nil
}

// rdsCustomizations are customization for the service/rds. This adds non-modeled fields used for presigning.
// rdsCustomizations are customization for the service/rds. This adds
// non-modeled fields used for presigning.
func rdsCustomizations(a *API) error {
inputs := []string{
"CopyDBSnapshotInput",
"CreateDBInstanceReadReplicaInput",
"CopyDBClusterSnapshotInput",
"CreateDBClusterInput",
"StartDBInstanceAutomatedBackupsReplicationInput",
}
for _, input := range inputs {
if ref, ok := a.Shapes[input]; ok {
Expand Down
27 changes: 23 additions & 4 deletions service/rds/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func init() {
opCreateDBInstanceReadReplica,
opCopyDBClusterSnapshot,
opCreateDBCluster,
opStartDBInstanceAutomatedBackupsReplication,
}
initRequest = func(r *request.Request) {
for _, operation := range ops {
Expand All @@ -27,10 +28,11 @@ func init() {

func fillPresignedURL(r *request.Request) {
fns := map[string]func(r *request.Request){
opCopyDBSnapshot: copyDBSnapshotPresign,
opCreateDBInstanceReadReplica: createDBInstanceReadReplicaPresign,
opCopyDBClusterSnapshot: copyDBClusterSnapshotPresign,
opCreateDBCluster: createDBClusterPresign,
opCopyDBSnapshot: copyDBSnapshotPresign,
opCreateDBInstanceReadReplica: createDBInstanceReadReplicaPresign,
opCopyDBClusterSnapshot: copyDBClusterSnapshotPresign,
opCreateDBCluster: createDBClusterPresign,
opStartDBInstanceAutomatedBackupsReplication: startDBInstanceAutomatedBackupsReplicationPresign,
}
if !r.ParamsFilled() {
return
Expand Down Expand Up @@ -109,6 +111,23 @@ func createDBClusterPresign(r *request.Request) {
originParams.PreSignedUrl = presignURL(r, originParams.SourceRegion, newParams)
}

func startDBInstanceAutomatedBackupsReplicationPresign(r *request.Request) {
originParams := r.Params.(*StartDBInstanceAutomatedBackupsReplicationInput)

if originParams.SourceRegion == nil || originParams.PreSignedUrl != nil || originParams.DestinationRegion != nil {
return
}

originParams.DestinationRegion = r.Config.Region
// preSignedUrl is not required for instances in the same region.
if *originParams.SourceRegion == *originParams.DestinationRegion {
return
}

newParams := awsutil.CopyOf(r.Params).(*StartDBInstanceAutomatedBackupsReplicationInput)
originParams.PreSignedUrl = presignURL(r, originParams.SourceRegion, newParams)
}

// presignURL will presign the request by using SoureRegion to sign with. SourceRegion is not
// sent to the service, and is only used to not have the SDKs parsing ARNs.
func presignURL(r *request.Request, sourceRegion *string, newParams interface{}) *string {
Expand Down
36 changes: 36 additions & 0 deletions service/rds/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func TestPresignCrossRegionRequest(t *testing.T) {
Assert: assertAsRegexMatch(fmt.Sprintf(regexPattern,
opCreateDBCluster, targetRegion)),
},
opStartDBInstanceAutomatedBackupsReplication: {
Req: func() *request.Request {
req, _ := svc.StartDBInstanceAutomatedBackupsReplicationRequest(
&StartDBInstanceAutomatedBackupsReplicationInput{
SourceRegion: aws.String("us-west-1"),
SourceDBInstanceArn: aws.String("bar"),
})
return req
}(),
Assert: assertAsRegexMatch(fmt.Sprintf(regexPattern,
opStartDBInstanceAutomatedBackupsReplication, targetRegion)),
},
opCopyDBSnapshot + " same region": {
Req: func() *request.Request {
req, _ := svc.CopyDBSnapshotRequest(&CopyDBSnapshotInput{
Expand Down Expand Up @@ -137,6 +149,17 @@ func TestPresignCrossRegionRequest(t *testing.T) {
}(),
Assert: assertAsEmpty(),
},
opStartDBInstanceAutomatedBackupsReplication + " same region": {
Req: func() *request.Request {
req, _ := svc.StartDBInstanceAutomatedBackupsReplicationRequest(
&StartDBInstanceAutomatedBackupsReplicationInput{
SourceRegion: aws.String("us-west-2"),
SourceDBInstanceArn: aws.String("bar"),
})
return req
}(),
Assert: assertAsEmpty(),
},
opCopyDBSnapshot + " presignURL set": {
Req: func() *request.Request {
req, _ := svc.CopyDBSnapshotRequest(&CopyDBSnapshotInput{
Expand Down Expand Up @@ -187,6 +210,19 @@ func TestPresignCrossRegionRequest(t *testing.T) {
}(),
Assert: assertAsEqual("mockPresignedURL"),
},
opStartDBInstanceAutomatedBackupsReplication + " presignURL set": {
Req: func() *request.Request {
req, _ := svc.StartDBInstanceAutomatedBackupsReplicationRequest(
&StartDBInstanceAutomatedBackupsReplicationInput{
SourceRegion: aws.String("us-west-1"),
KmsKeyId: aws.String("foo"),
SourceDBInstanceArn: aws.String("bar"),
PreSignedUrl: aws.String("mockPresignedURL"),
})
return req
}(),
Assert: assertAsEqual("mockPresignedURL"),
},
}

for name, c := range cases {
Expand Down

0 comments on commit d3b0b60

Please sign in to comment.