src

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

options.go (8211B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package sso
      4 
      5 import (
      6 	"context"
      7 	"github.com/aws/aws-sdk-go-v2/aws"
      8 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
      9 	internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
     10 	smithyauth "github.com/aws/smithy-go/auth"
     11 	"github.com/aws/smithy-go/logging"
     12 	"github.com/aws/smithy-go/middleware"
     13 	smithyhttp "github.com/aws/smithy-go/transport/http"
     14 	"net/http"
     15 )
     16 
     17 type HTTPClient interface {
     18 	Do(*http.Request) (*http.Response, error)
     19 }
     20 
     21 type Options struct {
     22 	// Set of options to modify how an operation is invoked. These apply to all
     23 	// operations invoked for this client. Use functional options on operation call to
     24 	// modify this list for per operation behavior.
     25 	APIOptions []func(*middleware.Stack) error
     26 
     27 	// The optional application specific identifier appended to the User-Agent header.
     28 	AppID string
     29 
     30 	// This endpoint will be given as input to an EndpointResolverV2. It is used for
     31 	// providing a custom base endpoint that is subject to modifications by the
     32 	// processing EndpointResolverV2.
     33 	BaseEndpoint *string
     34 
     35 	// Configures the events that will be sent to the configured logger.
     36 	ClientLogMode aws.ClientLogMode
     37 
     38 	// The credentials object to use when signing requests.
     39 	Credentials aws.CredentialsProvider
     40 
     41 	// The configuration DefaultsMode that the SDK should use when constructing the
     42 	// clients initial default settings.
     43 	DefaultsMode aws.DefaultsMode
     44 
     45 	// The endpoint options to be used when attempting to resolve an endpoint.
     46 	EndpointOptions EndpointResolverOptions
     47 
     48 	// The service endpoint resolver.
     49 	//
     50 	// Deprecated: Deprecated: EndpointResolver and WithEndpointResolver. Providing a
     51 	// value for this field will likely prevent you from using any endpoint-related
     52 	// service features released after the introduction of EndpointResolverV2 and
     53 	// BaseEndpoint. To migrate an EndpointResolver implementation that uses a custom
     54 	// endpoint, set the client option BaseEndpoint instead.
     55 	EndpointResolver EndpointResolver
     56 
     57 	// Resolves the endpoint used for a particular service operation. This should be
     58 	// used over the deprecated EndpointResolver.
     59 	EndpointResolverV2 EndpointResolverV2
     60 
     61 	// Signature Version 4 (SigV4) Signer
     62 	HTTPSignerV4 HTTPSignerV4
     63 
     64 	// The logger writer interface to write logging messages to.
     65 	Logger logging.Logger
     66 
     67 	// The region to send requests to. (Required)
     68 	Region string
     69 
     70 	// RetryMaxAttempts specifies the maximum number attempts an API client will call
     71 	// an operation that fails with a retryable error. A value of 0 is ignored, and
     72 	// will not be used to configure the API client created default retryer, or modify
     73 	// per operation call's retry max attempts. If specified in an operation call's
     74 	// functional options with a value that is different than the constructed client's
     75 	// Options, the Client's Retryer will be wrapped to use the operation's specific
     76 	// RetryMaxAttempts value.
     77 	RetryMaxAttempts int
     78 
     79 	// RetryMode specifies the retry mode the API client will be created with, if
     80 	// Retryer option is not also specified. When creating a new API Clients this
     81 	// member will only be used if the Retryer Options member is nil. This value will
     82 	// be ignored if Retryer is not nil. Currently does not support per operation call
     83 	// overrides, may in the future.
     84 	RetryMode aws.RetryMode
     85 
     86 	// Retryer guides how HTTP requests should be retried in case of recoverable
     87 	// failures. When nil the API client will use a default retryer. The kind of
     88 	// default retry created by the API client can be changed with the RetryMode
     89 	// option.
     90 	Retryer aws.Retryer
     91 
     92 	// The RuntimeEnvironment configuration, only populated if the DefaultsMode is set
     93 	// to DefaultsModeAuto and is initialized using config.LoadDefaultConfig . You
     94 	// should not populate this structure programmatically, or rely on the values here
     95 	// within your applications.
     96 	RuntimeEnvironment aws.RuntimeEnvironment
     97 
     98 	// The initial DefaultsMode used when the client options were constructed. If the
     99 	// DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
    100 	// value was at that point in time. Currently does not support per operation call
    101 	// overrides, may in the future.
    102 	resolvedDefaultsMode aws.DefaultsMode
    103 
    104 	// The HTTP client to invoke API calls with. Defaults to client's default HTTP
    105 	// implementation if nil.
    106 	HTTPClient HTTPClient
    107 
    108 	// The auth scheme resolver which determines how to authenticate for each
    109 	// operation.
    110 	AuthSchemeResolver AuthSchemeResolver
    111 
    112 	// The list of auth schemes supported by the client.
    113 	AuthSchemes []smithyhttp.AuthScheme
    114 }
    115 
    116 // Copy creates a clone where the APIOptions list is deep copied.
    117 func (o Options) Copy() Options {
    118 	to := o
    119 	to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions))
    120 	copy(to.APIOptions, o.APIOptions)
    121 
    122 	return to
    123 }
    124 
    125 func (o Options) GetIdentityResolver(schemeID string) smithyauth.IdentityResolver {
    126 	if schemeID == "aws.auth#sigv4" {
    127 		return getSigV4IdentityResolver(o)
    128 	}
    129 	if schemeID == "smithy.api#noAuth" {
    130 		return &smithyauth.AnonymousIdentityResolver{}
    131 	}
    132 	return nil
    133 }
    134 
    135 // WithAPIOptions returns a functional option for setting the Client's APIOptions
    136 // option.
    137 func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) {
    138 	return func(o *Options) {
    139 		o.APIOptions = append(o.APIOptions, optFns...)
    140 	}
    141 }
    142 
    143 // Deprecated: EndpointResolver and WithEndpointResolver. Providing a value for
    144 // this field will likely prevent you from using any endpoint-related service
    145 // features released after the introduction of EndpointResolverV2 and BaseEndpoint.
    146 // To migrate an EndpointResolver implementation that uses a custom endpoint, set
    147 // the client option BaseEndpoint instead.
    148 func WithEndpointResolver(v EndpointResolver) func(*Options) {
    149 	return func(o *Options) {
    150 		o.EndpointResolver = v
    151 	}
    152 }
    153 
    154 // WithEndpointResolverV2 returns a functional option for setting the Client's
    155 // EndpointResolverV2 option.
    156 func WithEndpointResolverV2(v EndpointResolverV2) func(*Options) {
    157 	return func(o *Options) {
    158 		o.EndpointResolverV2 = v
    159 	}
    160 }
    161 
    162 func getSigV4IdentityResolver(o Options) smithyauth.IdentityResolver {
    163 	if o.Credentials != nil {
    164 		return &internalauthsmithy.CredentialsProviderAdapter{Provider: o.Credentials}
    165 	}
    166 	return nil
    167 }
    168 
    169 // WithSigV4SigningName applies an override to the authentication workflow to
    170 // use the given signing name for SigV4-authenticated operations.
    171 //
    172 // This is an advanced setting. The value here is FINAL, taking precedence over
    173 // the resolved signing name from both auth scheme resolution and endpoint
    174 // resolution.
    175 func WithSigV4SigningName(name string) func(*Options) {
    176 	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
    177 		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
    178 	) {
    179 		return next.HandleInitialize(awsmiddleware.SetSigningName(ctx, name), in)
    180 	}
    181 	return func(o *Options) {
    182 		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
    183 			return s.Initialize.Add(
    184 				middleware.InitializeMiddlewareFunc("withSigV4SigningName", fn),
    185 				middleware.Before,
    186 			)
    187 		})
    188 	}
    189 }
    190 
    191 // WithSigV4SigningRegion applies an override to the authentication workflow to
    192 // use the given signing region for SigV4-authenticated operations.
    193 //
    194 // This is an advanced setting. The value here is FINAL, taking precedence over
    195 // the resolved signing region from both auth scheme resolution and endpoint
    196 // resolution.
    197 func WithSigV4SigningRegion(region string) func(*Options) {
    198 	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
    199 		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
    200 	) {
    201 		return next.HandleInitialize(awsmiddleware.SetSigningRegion(ctx, region), in)
    202 	}
    203 	return func(o *Options) {
    204 		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
    205 			return s.Initialize.Add(
    206 				middleware.InitializeMiddlewareFunc("withSigV4SigningRegion", fn),
    207 				middleware.Before,
    208 			)
    209 		})
    210 	}
    211 }
    212 
    213 func ignoreAnonymousAuth(options *Options) {
    214 	if aws.IsCredentialsProvider(options.Credentials, (*aws.AnonymousCredentials)(nil)) {
    215 		options.Credentials = nil
    216 	}
    217 }