src

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

config.go (10993B)


      1 package aws
      2 
      3 import (
      4 	"net/http"
      5 
      6 	smithybearer "github.com/aws/smithy-go/auth/bearer"
      7 	"github.com/aws/smithy-go/logging"
      8 	"github.com/aws/smithy-go/middleware"
      9 	smithyhttp "github.com/aws/smithy-go/transport/http"
     10 )
     11 
     12 // HTTPClient provides the interface to provide custom HTTPClients. Generally
     13 // *http.Client is sufficient for most use cases. The HTTPClient should not
     14 // follow 301 or 302 redirects.
     15 type HTTPClient interface {
     16 	Do(*http.Request) (*http.Response, error)
     17 }
     18 
     19 // A Config provides service configuration for service clients.
     20 type Config struct {
     21 	// The region to send requests to. This parameter is required and must
     22 	// be configured globally or on a per-client basis unless otherwise
     23 	// noted. A full list of regions is found in the "Regions and Endpoints"
     24 	// document.
     25 	//
     26 	// See http://docs.aws.amazon.com/general/latest/gr/rande.html for
     27 	// information on AWS regions.
     28 	Region string
     29 
     30 	// The credentials object to use when signing requests.
     31 	// Use the LoadDefaultConfig to load configuration from all the SDK's supported
     32 	// sources, and resolve credentials using the SDK's default credential chain.
     33 	Credentials CredentialsProvider
     34 
     35 	// The Bearer Authentication token provider to use for authenticating API
     36 	// operation calls with a Bearer Authentication token. The API clients and
     37 	// operation must support Bearer Authentication scheme in order for the
     38 	// token provider to be used. API clients created with NewFromConfig will
     39 	// automatically be configured with this option, if the API client support
     40 	// Bearer Authentication.
     41 	//
     42 	// The SDK's config.LoadDefaultConfig can automatically populate this
     43 	// option for external configuration options such as SSO session.
     44 	// https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html
     45 	BearerAuthTokenProvider smithybearer.TokenProvider
     46 
     47 	// The HTTP Client the SDK's API clients will use to invoke HTTP requests.
     48 	// The SDK defaults to a BuildableClient allowing API clients to create
     49 	// copies of the HTTP Client for service specific customizations.
     50 	//
     51 	// Use a (*http.Client) for custom behavior. Using a custom http.Client
     52 	// will prevent the SDK from modifying the HTTP client.
     53 	HTTPClient HTTPClient
     54 
     55 	// An endpoint resolver that can be used to provide or override an endpoint
     56 	// for the given service and region.
     57 	//
     58 	// See the `aws.EndpointResolver` documentation for additional usage
     59 	// information.
     60 	//
     61 	// Deprecated: See Config.EndpointResolverWithOptions
     62 	EndpointResolver EndpointResolver
     63 
     64 	// An endpoint resolver that can be used to provide or override an endpoint
     65 	// for the given service and region.
     66 	//
     67 	// When EndpointResolverWithOptions is specified, it will be used by a
     68 	// service client rather than using EndpointResolver if also specified.
     69 	//
     70 	// See the `aws.EndpointResolverWithOptions` documentation for additional
     71 	// usage information.
     72 	//
     73 	// Deprecated: with the release of endpoint resolution v2 in API clients,
     74 	// EndpointResolver and EndpointResolverWithOptions are deprecated.
     75 	// Providing a value for this field will likely prevent you from using
     76 	// newer endpoint-related service features. See API client options
     77 	// EndpointResolverV2 and BaseEndpoint.
     78 	EndpointResolverWithOptions EndpointResolverWithOptions
     79 
     80 	// RetryMaxAttempts specifies the maximum number attempts an API client
     81 	// will call an operation that fails with a retryable error.
     82 	//
     83 	// API Clients will only use this value to construct a retryer if the
     84 	// Config.Retryer member is not nil. This value will be ignored if
     85 	// Retryer is not nil.
     86 	RetryMaxAttempts int
     87 
     88 	// RetryMode specifies the retry model the API client will be created with.
     89 	//
     90 	// API Clients will only use this value to construct a retryer if the
     91 	// Config.Retryer member is not nil. This value will be ignored if
     92 	// Retryer is not nil.
     93 	RetryMode RetryMode
     94 
     95 	// Retryer is a function that provides a Retryer implementation. A Retryer
     96 	// guides how HTTP requests should be retried in case of recoverable
     97 	// failures. When nil the API client will use a default retryer.
     98 	//
     99 	// In general, the provider function should return a new instance of a
    100 	// Retryer if you are attempting to provide a consistent Retryer
    101 	// configuration across all clients. This will ensure that each client will
    102 	// be provided a new instance of the Retryer implementation, and will avoid
    103 	// issues such as sharing the same retry token bucket across services.
    104 	//
    105 	// If not nil, RetryMaxAttempts, and RetryMode will be ignored by API
    106 	// clients.
    107 	Retryer func() Retryer
    108 
    109 	// ConfigSources are the sources that were used to construct the Config.
    110 	// Allows for additional configuration to be loaded by clients.
    111 	ConfigSources []interface{}
    112 
    113 	// APIOptions provides the set of middleware mutations modify how the API
    114 	// client requests will be handled. This is useful for adding additional
    115 	// tracing data to a request, or changing behavior of the SDK's client.
    116 	APIOptions []func(*middleware.Stack) error
    117 
    118 	// The logger writer interface to write logging messages to. Defaults to
    119 	// standard error.
    120 	Logger logging.Logger
    121 
    122 	// Configures the events that will be sent to the configured logger. This
    123 	// can be used to configure the logging of signing, retries, request, and
    124 	// responses of the SDK clients.
    125 	//
    126 	// See the ClientLogMode type documentation for the complete set of logging
    127 	// modes and available configuration.
    128 	ClientLogMode ClientLogMode
    129 
    130 	// The configured DefaultsMode. If not specified, service clients will
    131 	// default to legacy.
    132 	//
    133 	// Supported modes are: auto, cross-region, in-region, legacy, mobile,
    134 	// standard
    135 	DefaultsMode DefaultsMode
    136 
    137 	// The RuntimeEnvironment configuration, only populated if the DefaultsMode
    138 	// is set to DefaultsModeAuto and is initialized by
    139 	// `config.LoadDefaultConfig`. You should not populate this structure
    140 	// programmatically, or rely on the values here within your applications.
    141 	RuntimeEnvironment RuntimeEnvironment
    142 
    143 	// AppId is an optional application specific identifier that can be set.
    144 	// When set it will be appended to the User-Agent header of every request
    145 	// in the form of App/{AppId}. This variable is sourced from environment
    146 	// variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
    147 	// See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for
    148 	// more information on environment variables and shared config settings.
    149 	AppID string
    150 
    151 	// BaseEndpoint is an intermediary transfer location to a service specific
    152 	// BaseEndpoint on a service's Options.
    153 	BaseEndpoint *string
    154 
    155 	// DisableRequestCompression toggles if an operation request could be
    156 	// compressed or not. Will be set to false by default. This variable is sourced from
    157 	// environment variable AWS_DISABLE_REQUEST_COMPRESSION or the shared config profile attribute
    158 	// disable_request_compression
    159 	DisableRequestCompression bool
    160 
    161 	// RequestMinCompressSizeBytes sets the inclusive min bytes of a request body that could be
    162 	// compressed. Will be set to 10240 by default and must be within 0 and 10485760 bytes inclusively.
    163 	// This variable is sourced from environment variable AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES or
    164 	// the shared config profile attribute request_min_compression_size_bytes
    165 	RequestMinCompressSizeBytes int64
    166 
    167 	// Controls how a resolved AWS account ID is handled for endpoint routing.
    168 	AccountIDEndpointMode AccountIDEndpointMode
    169 
    170 	// RequestChecksumCalculation determines when request checksum calculation is performed.
    171 	//
    172 	// There are two possible values for this setting:
    173 	//
    174 	// 1. RequestChecksumCalculationWhenSupported (default): The checksum is always calculated
    175 	//    if the operation supports it, regardless of whether the user sets an algorithm in the request.
    176 	//
    177 	// 2. RequestChecksumCalculationWhenRequired: The checksum is only calculated if the user
    178 	//    explicitly sets a checksum algorithm in the request.
    179 	//
    180 	// This setting is sourced from the environment variable AWS_REQUEST_CHECKSUM_CALCULATION
    181 	// or the shared config profile attribute "request_checksum_calculation".
    182 	RequestChecksumCalculation RequestChecksumCalculation
    183 
    184 	// ResponseChecksumValidation determines when response checksum validation is performed
    185 	//
    186 	// There are two possible values for this setting:
    187 	//
    188 	// 1. ResponseChecksumValidationWhenSupported (default): The checksum is always validated
    189 	//    if the operation supports it, regardless of whether the user sets the validation mode to ENABLED in request.
    190 	//
    191 	// 2. ResponseChecksumValidationWhenRequired: The checksum is only validated if the user
    192 	//    explicitly sets the validation mode to ENABLED in the request
    193 	// This variable is sourced from environment variable AWS_RESPONSE_CHECKSUM_VALIDATION or
    194 	// the shared config profile attribute "response_checksum_validation".
    195 	ResponseChecksumValidation ResponseChecksumValidation
    196 
    197 	// Registry of HTTP interceptors.
    198 	Interceptors smithyhttp.InterceptorRegistry
    199 
    200 	// Priority list of preferred auth scheme IDs.
    201 	AuthSchemePreference []string
    202 
    203 	// ServiceOptions provides service specific configuration options that will be applied
    204 	// when constructing clients for specific services. Each callback function receives the service ID
    205 	// and the service's Options struct, allowing for dynamic configuration based on the service.
    206 	ServiceOptions []func(string, any)
    207 }
    208 
    209 // NewConfig returns a new Config pointer that can be chained with builder
    210 // methods to set multiple configuration values inline without using pointers.
    211 func NewConfig() *Config {
    212 	return &Config{}
    213 }
    214 
    215 // Copy will return a shallow copy of the Config object.
    216 func (c Config) Copy() Config {
    217 	cp := c
    218 	return cp
    219 }
    220 
    221 // EndpointDiscoveryEnableState indicates if endpoint discovery is
    222 // enabled, disabled, auto or unset state.
    223 //
    224 // Default behavior (Auto or Unset) indicates operations that require endpoint
    225 // discovery will use Endpoint Discovery by default. Operations that
    226 // optionally use Endpoint Discovery will not use Endpoint Discovery
    227 // unless EndpointDiscovery is explicitly enabled.
    228 type EndpointDiscoveryEnableState uint
    229 
    230 // Enumeration values for EndpointDiscoveryEnableState
    231 const (
    232 	// EndpointDiscoveryUnset represents EndpointDiscoveryEnableState is unset.
    233 	// Users do not need to use this value explicitly. The behavior for unset
    234 	// is the same as for EndpointDiscoveryAuto.
    235 	EndpointDiscoveryUnset EndpointDiscoveryEnableState = iota
    236 
    237 	// EndpointDiscoveryAuto represents an AUTO state that allows endpoint
    238 	// discovery only when required by the api. This is the default
    239 	// configuration resolved by the client if endpoint discovery is neither
    240 	// enabled or disabled.
    241 	EndpointDiscoveryAuto // default state
    242 
    243 	// EndpointDiscoveryDisabled indicates client MUST not perform endpoint
    244 	// discovery even when required.
    245 	EndpointDiscoveryDisabled
    246 
    247 	// EndpointDiscoveryEnabled indicates client MUST always perform endpoint
    248 	// discovery if supported for the operation.
    249 	EndpointDiscoveryEnabled
    250 )