open-vault/vendor/github.com/aws/aws-sdk-go/service/ec2/customizations.go

68 lines
1.8 KiB
Go
Raw Normal View History

2015-08-06 16:41:01 +00:00
package ec2
import (
"time"
2015-10-30 22:07:00 +00:00
"github.com/aws/aws-sdk-go/aws"
2015-08-06 16:41:01 +00:00
"github.com/aws/aws-sdk-go/aws/awsutil"
2017-01-04 21:47:38 +00:00
"github.com/aws/aws-sdk-go/aws/endpoints"
2015-09-22 15:44:21 +00:00
"github.com/aws/aws-sdk-go/aws/request"
2015-08-06 16:41:01 +00:00
)
func init() {
2015-09-22 15:44:21 +00:00
initRequest = func(r *request.Request) {
2015-08-06 16:41:01 +00:00
if r.Operation.Name == opCopySnapshot { // fill the PresignedURL parameter
r.Handlers.Build.PushFront(fillPresignedURL)
}
}
}
2015-09-22 15:44:21 +00:00
func fillPresignedURL(r *request.Request) {
2015-08-06 16:41:01 +00:00
if !r.ParamsFilled() {
return
}
2015-10-30 22:07:00 +00:00
origParams := r.Params.(*CopySnapshotInput)
2015-08-06 16:41:01 +00:00
// Stop if PresignedURL/DestinationRegion is set
2015-10-30 22:07:00 +00:00
if origParams.PresignedUrl != nil || origParams.DestinationRegion != nil {
2015-08-06 16:41:01 +00:00
return
}
2015-10-30 22:07:00 +00:00
origParams.DestinationRegion = r.Config.Region
newParams := awsutil.CopyOf(r.Params).(*CopySnapshotInput)
2015-08-06 16:41:01 +00:00
2015-10-30 22:07:00 +00:00
// Create a new request based on the existing request. We will use this to
// presign the CopySnapshot request against the source region.
cfg := r.Config.Copy(aws.NewConfig().
2015-08-06 16:41:01 +00:00
WithEndpoint("").
2015-10-30 22:07:00 +00:00
WithRegion(aws.StringValue(origParams.SourceRegion)))
2015-08-06 16:41:01 +00:00
2015-10-30 22:07:00 +00:00
clientInfo := r.ClientInfo
2017-01-04 21:47:38 +00:00
resolved, err := r.Config.EndpointResolver.EndpointFor(
clientInfo.ServiceName, aws.StringValue(cfg.Region),
func(opt *endpoints.Options) {
opt.DisableSSL = aws.BoolValue(cfg.DisableSSL)
opt.UseDualStack = aws.BoolValue(cfg.UseDualStack)
},
2016-09-02 22:05:09 +00:00
)
2017-01-04 21:47:38 +00:00
if err != nil {
r.Error = err
return
}
clientInfo.Endpoint = resolved.URL
clientInfo.SigningRegion = resolved.SigningRegion
2015-08-06 16:41:01 +00:00
// Presign a CopySnapshot request with modified params
2015-10-30 22:07:00 +00:00
req := request.New(*cfg, clientInfo, r.Handlers, r.Retryer, r.Operation, newParams, r.Data)
url, err := req.Presign(5 * time.Minute) // 5 minutes should be enough.
if err != nil { // bubble error back up to original request
2015-08-06 16:41:01 +00:00
r.Error = err
2015-10-30 22:07:00 +00:00
return
2015-08-06 16:41:01 +00:00
}
// We have our URL, set it on params
2015-10-30 22:07:00 +00:00
origParams.PresignedUrl = &url
2015-08-06 16:41:01 +00:00
}