src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

v4signer_adapter.go (1438B)


      1 package smithy
      2 
      3 import (
      4 	"context"
      5 	"fmt"
      6 
      7 	v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
      8 	"github.com/aws/aws-sdk-go-v2/internal/sdk"
      9 	"github.com/aws/smithy-go"
     10 	"github.com/aws/smithy-go/auth"
     11 	"github.com/aws/smithy-go/logging"
     12 	smithyhttp "github.com/aws/smithy-go/transport/http"
     13 )
     14 
     15 // V4SignerAdapter adapts v4.HTTPSigner to smithy http.Signer.
     16 type V4SignerAdapter struct {
     17 	Signer     v4.HTTPSigner
     18 	Logger     logging.Logger
     19 	LogSigning bool
     20 }
     21 
     22 var _ (smithyhttp.Signer) = (*V4SignerAdapter)(nil)
     23 
     24 // SignRequest signs the request with the provided identity.
     25 func (v *V4SignerAdapter) SignRequest(ctx context.Context, r *smithyhttp.Request, identity auth.Identity, props smithy.Properties) error {
     26 	ca, ok := identity.(*CredentialsAdapter)
     27 	if !ok {
     28 		return fmt.Errorf("unexpected identity type: %T", identity)
     29 	}
     30 
     31 	name, ok := smithyhttp.GetSigV4SigningName(&props)
     32 	if !ok {
     33 		return fmt.Errorf("sigv4 signing name is required")
     34 	}
     35 
     36 	region, ok := smithyhttp.GetSigV4SigningRegion(&props)
     37 	if !ok {
     38 		return fmt.Errorf("sigv4 signing region is required")
     39 	}
     40 
     41 	hash := v4.GetPayloadHash(ctx)
     42 	err := v.Signer.SignHTTP(ctx, ca.Credentials, r.Request, hash, name, region, sdk.NowTime(), func(o *v4.SignerOptions) {
     43 		o.DisableURIPathEscaping, _ = smithyhttp.GetDisableDoubleEncoding(&props)
     44 
     45 		o.Logger = v.Logger
     46 		o.LogSigning = v.LogSigning
     47 	})
     48 	if err != nil {
     49 		return fmt.Errorf("sign http: %w", err)
     50 	}
     51 
     52 	return nil
     53 }