src

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

config.go (11580B)


      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 	// DisableClockSkewCorrection turns off SDK clock skew correction. When set
    168 	// the SDK will not adjust request signing timestamps to compensate for
    169 	// drift between the client and service clocks. Set to false (enabled) by
    170 	// default. This variable is sourced from the environment variable
    171 	// AWS_DISABLE_CLOCK_SKEW_CORRECTION or the shared config profile attribute
    172 	// disable_clock_skew_correction.
    173 	DisableClockSkewCorrection bool
    174 
    175 	// Controls how a resolved AWS account ID is handled for endpoint routing.
    176 	AccountIDEndpointMode AccountIDEndpointMode
    177 
    178 	// RequestChecksumCalculation determines when request checksum calculation is performed.
    179 	//
    180 	// There are two possible values for this setting:
    181 	//
    182 	// 1. RequestChecksumCalculationWhenSupported (default): The checksum is always calculated
    183 	//    if the operation supports it, regardless of whether the user sets an algorithm in the request.
    184 	//
    185 	// 2. RequestChecksumCalculationWhenRequired: The checksum is only calculated if the user
    186 	//    explicitly sets a checksum algorithm in the request.
    187 	//
    188 	// This setting is sourced from the environment variable AWS_REQUEST_CHECKSUM_CALCULATION
    189 	// or the shared config profile attribute "request_checksum_calculation".
    190 	RequestChecksumCalculation RequestChecksumCalculation
    191 
    192 	// ResponseChecksumValidation determines when response checksum validation is performed
    193 	//
    194 	// There are two possible values for this setting:
    195 	//
    196 	// 1. ResponseChecksumValidationWhenSupported (default): The checksum is always validated
    197 	//    if the operation supports it, regardless of whether the user sets the validation mode to ENABLED in request.
    198 	//
    199 	// 2. ResponseChecksumValidationWhenRequired: The checksum is only validated if the user
    200 	//    explicitly sets the validation mode to ENABLED in the request
    201 	// This variable is sourced from environment variable AWS_RESPONSE_CHECKSUM_VALIDATION or
    202 	// the shared config profile attribute "response_checksum_validation".
    203 	ResponseChecksumValidation ResponseChecksumValidation
    204 
    205 	// Registry of HTTP interceptors.
    206 	Interceptors smithyhttp.InterceptorRegistry
    207 
    208 	// Priority list of preferred auth scheme IDs.
    209 	AuthSchemePreference []string
    210 
    211 	// ServiceOptions provides service specific configuration options that will be applied
    212 	// when constructing clients for specific services. Each callback function receives the service ID
    213 	// and the service's Options struct, allowing for dynamic configuration based on the service.
    214 	ServiceOptions []func(string, any)
    215 
    216 	// Controls whether the SDK restricts file permissions on credential
    217 	// cache files it creates.
    218 	RestrictFilePermissions RestrictFilePermissions
    219 }
    220 
    221 // NewConfig returns a new Config pointer that can be chained with builder
    222 // methods to set multiple configuration values inline without using pointers.
    223 func NewConfig() *Config {
    224 	return &Config{}
    225 }
    226 
    227 // Copy will return a shallow copy of the Config object.
    228 func (c Config) Copy() Config {
    229 	cp := c
    230 	return cp
    231 }
    232 
    233 // EndpointDiscoveryEnableState indicates if endpoint discovery is
    234 // enabled, disabled, auto or unset state.
    235 //
    236 // Default behavior (Auto or Unset) indicates operations that require endpoint
    237 // discovery will use Endpoint Discovery by default. Operations that
    238 // optionally use Endpoint Discovery will not use Endpoint Discovery
    239 // unless EndpointDiscovery is explicitly enabled.
    240 type EndpointDiscoveryEnableState uint
    241 
    242 // Enumeration values for EndpointDiscoveryEnableState
    243 const (
    244 	// EndpointDiscoveryUnset represents EndpointDiscoveryEnableState is unset.
    245 	// Users do not need to use this value explicitly. The behavior for unset
    246 	// is the same as for EndpointDiscoveryAuto.
    247 	EndpointDiscoveryUnset EndpointDiscoveryEnableState = iota
    248 
    249 	// EndpointDiscoveryAuto represents an AUTO state that allows endpoint
    250 	// discovery only when required by the api. This is the default
    251 	// configuration resolved by the client if endpoint discovery is neither
    252 	// enabled or disabled.
    253 	EndpointDiscoveryAuto // default state
    254 
    255 	// EndpointDiscoveryDisabled indicates client MUST not perform endpoint
    256 	// discovery even when required.
    257 	EndpointDiscoveryDisabled
    258 
    259 	// EndpointDiscoveryEnabled indicates client MUST always perform endpoint
    260 	// discovery if supported for the operation.
    261 	EndpointDiscoveryEnabled
    262 )