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

60 lines
1.6 KiB
Go
Raw Normal View History

2015-09-16 13:05:04 -07:00
package ec2
import (
"time"
"github.com/aws/aws-sdk-go/aws"
2015-09-16 13:05:04 -07:00
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/private/endpoints"
2015-09-16 13:05:04 -07:00
)
func init() {
initRequest = func(r *request.Request) {
if r.Operation.Name == opCopySnapshot { // fill the PresignedURL parameter
r.Handlers.Build.PushFront(fillPresignedURL)
}
}
}
func fillPresignedURL(r *request.Request) {
if !r.ParamsFilled() {
return
}
origParams := r.Params.(*CopySnapshotInput)
2015-09-16 13:05:04 -07:00
// Stop if PresignedURL/DestinationRegion is set
if origParams.PresignedUrl != nil || origParams.DestinationRegion != nil {
2015-09-16 13:05:04 -07:00
return
}
origParams.DestinationRegion = r.Config.Region
newParams := awsutil.CopyOf(r.Params).(*CopySnapshotInput)
2015-09-16 13:05:04 -07: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-09-16 13:05:04 -07:00
WithEndpoint("").
WithRegion(aws.StringValue(origParams.SourceRegion)))
2015-09-16 13:05:04 -07:00
clientInfo := r.ClientInfo
clientInfo.Endpoint, clientInfo.SigningRegion = endpoints.EndpointForRegion(
clientInfo.ServiceName,
aws.StringValue(cfg.Region),
aws.BoolValue(cfg.DisableSSL),
aws.BoolValue(cfg.UseDualStack),
)
2015-09-16 13:05:04 -07:00
// Presign a CopySnapshot request with modified params
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-09-16 13:05:04 -07:00
r.Error = err
return
2015-09-16 13:05:04 -07:00
}
// We have our URL, set it on params
origParams.PresignedUrl = &url
2015-09-16 13:05:04 -07:00
}