Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions service/rds/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func fillPresignedURL(r *request.Request) {
fns := map[string]func(r *request.Request){
opCopyDBSnapshot: copyDBSnapshotPresign,
opCreateDBInstanceReadReplica: createDBInstanceReadReplicaPresign,
opCopyDBClusterSnapshot: copyDBClusterSnapshotPresign,
opCreateDBCluster: createDBClusterPresign,
}
if !r.ParamsFilled() {
return
Expand All @@ -41,7 +43,7 @@ func fillPresignedURL(r *request.Request) {
func copyDBSnapshotPresign(r *request.Request) {
originParams := r.Params.(*CopyDBSnapshotInput)

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

Expand All @@ -53,7 +55,7 @@ func copyDBSnapshotPresign(r *request.Request) {
func createDBInstanceReadReplicaPresign(r *request.Request) {
originParams := r.Params.(*CreateDBInstanceReadReplicaInput)

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

Expand All @@ -62,6 +64,30 @@ func createDBInstanceReadReplicaPresign(r *request.Request) {
originParams.PreSignedUrl = presignURL(r, originParams.SourceRegion, newParams)
}

func copyDBClusterSnapshotPresign(r *request.Request) {
originParams := r.Params.(*CopyDBClusterSnapshotInput)

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

originParams.DestinationRegion = r.Config.Region
newParams := awsutil.CopyOf(r.Params).(*CopyDBClusterSnapshotInput)
originParams.PreSignedUrl = presignURL(r, originParams.SourceRegion, newParams)
}

func createDBClusterPresign(r *request.Request) {
originParams := r.Params.(*CreateDBClusterInput)

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

originParams.DestinationRegion = r.Config.Region
newParams := awsutil.CopyOf(r.Params).(*CreateDBClusterInput)
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
24 changes: 24 additions & 0 deletions service/rds/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/url"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
Expand Down Expand Up @@ -79,3 +80,26 @@ func TestPresignWithPresignSet(t *testing.T) {
assert.Regexp(t, `presignedURL`, u)
}
}

func TestPresignWithSourceNotSet(t *testing.T) {
reqs := map[string]*request.Request{}
svc := New(unit.Session, &aws.Config{Region: aws.String("us-west-2")})

assert.NotPanics(t, func() {
// Doesn't panic on nil input
req, _ := svc.CopyDBSnapshotRequest(nil)
req.Sign()
})

reqs[opCopyDBSnapshot], _ = svc.CopyDBSnapshotRequest(&CopyDBSnapshotInput{
SourceDBSnapshotIdentifier: aws.String("foo"),
TargetDBSnapshotIdentifier: aws.String("bar"),
})

for _, req := range reqs {
_, err := req.Presign(5 * time.Minute)
if err != nil {
t.Fatal(err)
}
}
}