options.go raw

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