Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handwritten prototype of presign url client #880

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 9 additions & 12 deletions service/internal/presigned-url/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package presignedurl
import (
"context"
"fmt"
"net/http"

awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"

"github.com/awslabs/smithy-go/middleware"
)

Expand All @@ -18,20 +19,16 @@ type ParameterAccessor struct {
CopyInput func(interface{}) (interface{}, error)
SetDestinationRegion func(interface{}, string) error
SetPresignedURL func(interface{}, string) error
}

// URLPresigner provides the interface to presign the input parameters in to a
// presigned URL.
type URLPresigner interface {
PresignURL(ctx context.Context, srcRegion string, params interface{}) (
presignedURL string, signedHeader http.Header, err error,
)
// GetPresigner fetches a request presigner
// The function should be of format:
// func $name (ctx context.Context, srcRegion string, params interface{}) (v4.HTTPRequest, error)
GetPresigner func(context.Context, string, interface{}) (v4.PresignedHTTPRequest, error)
}

// Options provides the set of options needed by the presigned URL middleware.
type Options struct {
Accessor ParameterAccessor
Presigner URLPresigner
Accessor ParameterAccessor
}

// AddMiddleware adds the Presign URL middleware to the middleware stack.
Expand Down Expand Up @@ -84,13 +81,13 @@ func (m *presignMiddleware) HandleInitialize(
return out, metadata, fmt.Errorf("presign middleware failed, %w", err)
}

presignedURL, _, err := m.options.Presigner.PresignURL(ctx, srcRegion, paramCpy)
presignedReq, err := m.options.Accessor.GetPresigner(ctx, srcRegion, paramCpy)
if err != nil {
return out, metadata, fmt.Errorf("unable to create presigned URL, %w", err)
}

// Update the original input with the presigned URL value.
if err = m.options.Accessor.SetPresignedURL(input.Parameters, presignedURL); err != nil {
if err = m.options.Accessor.SetPresignedURL(input.Parameters, presignedReq.URL); err != nil {
return out, metadata, fmt.Errorf("presign middleware failed, %w", err)
}

Expand Down
54 changes: 54 additions & 0 deletions service/rds/api_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 44 additions & 63 deletions service/rds/api_op_CopyDBClusterSnapshot.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.