1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
package eventbridge
import (
"context"
"fmt"
smithy "github.com/aws/smithy-go"
smithyauth "github.com/aws/smithy-go/auth"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
type endpointAuthResolver struct {
EndpointResolver EndpointResolverV2
}
var _ AuthSchemeResolver = (*endpointAuthResolver)(nil)
func (r *endpointAuthResolver) ResolveAuthSchemes(
ctx context.Context, params *AuthResolverParameters,
) (
[]*smithyauth.Option, error,
) {
opts, err := r.resolveAuthSchemes(ctx, params)
if err != nil {
return nil, err
}
// preserve pre-SRA behavior where everything technically had anonymous
return append(opts, &smithyauth.Option{
SchemeID: smithyauth.SchemeIDAnonymous,
}), nil
}
func (r *endpointAuthResolver) resolveAuthSchemes(
ctx context.Context, params *AuthResolverParameters,
) (
[]*smithyauth.Option, error,
) {
endpt, err := r.EndpointResolver.ResolveEndpoint(ctx, *params.endpointParams)
if err != nil {
return nil, fmt.Errorf("resolve endpoint: %w", err)
}
if opts, ok := smithyauth.GetAuthOptions(&endpt.Properties); ok {
return opts, nil
}
// endpoint rules didn't specify, fallback to sigv4
return []*smithyauth.Option{
{
SchemeID: smithyauth.SchemeIDSigV4,
SignerProperties: func() smithy.Properties {
var props smithy.Properties
smithyhttp.SetSigV4SigningName(&props, "events")
smithyhttp.SetSigV4SigningRegion(&props, params.Region)
return props
}(),
},
{
SchemeID: smithyauth.SchemeIDSigV4A,
},
}, nil
}
func finalizeServiceEndpointAuthResolver(options *Options) {
if _, ok := options.AuthSchemeResolver.(*defaultAuthSchemeResolver); !ok {
return
}
options.AuthSchemeResolver = &endpointAuthResolver{
EndpointResolver: options.EndpointResolverV2,
}
}
func finalizeOperationEndpointAuthResolver(options *Options) {
resolver, ok := options.AuthSchemeResolver.(*endpointAuthResolver)
if !ok {
return
}
if resolver.EndpointResolver == options.EndpointResolverV2 {
return
}
options.AuthSchemeResolver = &endpointAuthResolver{
EndpointResolver: options.EndpointResolverV2,
}
}
|