options.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package s3
  3. import (
  4. "context"
  5. "fmt"
  6. "github.com/aws/aws-sdk-go-v2/aws"
  7. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  8. internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
  9. "github.com/aws/aws-sdk-go-v2/internal/v4a"
  10. s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
  11. smithyauth "github.com/aws/smithy-go/auth"
  12. "github.com/aws/smithy-go/logging"
  13. "github.com/aws/smithy-go/metrics"
  14. "github.com/aws/smithy-go/middleware"
  15. "github.com/aws/smithy-go/tracing"
  16. smithyhttp "github.com/aws/smithy-go/transport/http"
  17. "net/http"
  18. )
  19. type HTTPClient interface {
  20. Do(*http.Request) (*http.Response, error)
  21. }
  22. type Options struct {
  23. // Set of options to modify how an operation is invoked. These apply to all
  24. // operations invoked for this client. Use functional options on operation call to
  25. // modify this list for per operation behavior.
  26. APIOptions []func(*middleware.Stack) error
  27. // The optional application specific identifier appended to the User-Agent header.
  28. AppID string
  29. // This endpoint will be given as input to an EndpointResolverV2. It is used for
  30. // providing a custom base endpoint that is subject to modifications by the
  31. // processing EndpointResolverV2.
  32. BaseEndpoint *string
  33. // Configures the events that will be sent to the configured logger.
  34. ClientLogMode aws.ClientLogMode
  35. // The threshold ContentLength in bytes for HTTP PUT request to receive {Expect:
  36. // 100-continue} header. Setting to -1 will disable adding the Expect header to
  37. // requests; setting to 0 will set the threshold to default 2MB
  38. ContinueHeaderThresholdBytes int64
  39. // The credentials object to use when signing requests.
  40. Credentials aws.CredentialsProvider
  41. // The configuration DefaultsMode that the SDK should use when constructing the
  42. // clients initial default settings.
  43. DefaultsMode aws.DefaultsMode
  44. // Disables logging when the client skips output checksum validation due to lack
  45. // of algorithm support.
  46. DisableLogOutputChecksumValidationSkipped bool
  47. // Allows you to disable S3 Multi-Region access points feature.
  48. DisableMultiRegionAccessPoints bool
  49. // Disables this client's usage of Session Auth for S3Express buckets and reverts
  50. // to using conventional SigV4 for those.
  51. DisableS3ExpressSessionAuth *bool
  52. // The endpoint options to be used when attempting to resolve an endpoint.
  53. EndpointOptions EndpointResolverOptions
  54. // The service endpoint resolver.
  55. //
  56. // Deprecated: Deprecated: EndpointResolver and WithEndpointResolver. Providing a
  57. // value for this field will likely prevent you from using any endpoint-related
  58. // service features released after the introduction of EndpointResolverV2 and
  59. // BaseEndpoint.
  60. //
  61. // To migrate an EndpointResolver implementation that uses a custom endpoint, set
  62. // the client option BaseEndpoint instead.
  63. EndpointResolver EndpointResolver
  64. // Resolves the endpoint used for a particular service operation. This should be
  65. // used over the deprecated EndpointResolver.
  66. EndpointResolverV2 EndpointResolverV2
  67. // The credentials provider for S3Express requests.
  68. ExpressCredentials ExpressCredentialsProvider
  69. // Signature Version 4 (SigV4) Signer
  70. HTTPSignerV4 HTTPSignerV4
  71. // Provides idempotency tokens values that will be automatically populated into
  72. // idempotent API operations.
  73. IdempotencyTokenProvider IdempotencyTokenProvider
  74. // The logger writer interface to write logging messages to.
  75. Logger logging.Logger
  76. // The client meter provider.
  77. MeterProvider metrics.MeterProvider
  78. // The region to send requests to. (Required)
  79. Region string
  80. // Indicates how user opt-in/out request checksum calculation
  81. RequestChecksumCalculation aws.RequestChecksumCalculation
  82. // Indicates how user opt-in/out response checksum validation
  83. ResponseChecksumValidation aws.ResponseChecksumValidation
  84. // RetryMaxAttempts specifies the maximum number attempts an API client will call
  85. // an operation that fails with a retryable error. A value of 0 is ignored, and
  86. // will not be used to configure the API client created default retryer, or modify
  87. // per operation call's retry max attempts.
  88. //
  89. // If specified in an operation call's functional options with a value that is
  90. // different than the constructed client's Options, the Client's Retryer will be
  91. // wrapped to use the operation's specific RetryMaxAttempts value.
  92. RetryMaxAttempts int
  93. // RetryMode specifies the retry mode the API client will be created with, if
  94. // Retryer option is not also specified.
  95. //
  96. // When creating a new API Clients this member will only be used if the Retryer
  97. // Options member is nil. This value will be ignored if Retryer is not nil.
  98. //
  99. // Currently does not support per operation call overrides, may in the future.
  100. RetryMode aws.RetryMode
  101. // Retryer guides how HTTP requests should be retried in case of recoverable
  102. // failures. When nil the API client will use a default retryer. The kind of
  103. // default retry created by the API client can be changed with the RetryMode
  104. // option.
  105. Retryer aws.Retryer
  106. // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set
  107. // to DefaultsModeAuto and is initialized using config.LoadDefaultConfig . You
  108. // should not populate this structure programmatically, or rely on the values here
  109. // within your applications.
  110. RuntimeEnvironment aws.RuntimeEnvironment
  111. // The client tracer provider.
  112. TracerProvider tracing.TracerProvider
  113. // Allows you to enable arn region support for the service.
  114. UseARNRegion bool
  115. // Allows you to enable S3 Accelerate feature. All operations compatible with S3
  116. // Accelerate will use the accelerate endpoint for requests. Requests not
  117. // compatible will fall back to normal S3 requests. The bucket must be enabled for
  118. // accelerate to be used with S3 client with accelerate enabled. If the bucket is
  119. // not enabled for accelerate an error will be returned. The bucket name must be
  120. // DNS compatible to work with accelerate.
  121. UseAccelerate bool
  122. // Allows you to enable dual-stack endpoint support for the service.
  123. //
  124. // Deprecated: Set dual-stack by setting UseDualStackEndpoint on
  125. // EndpointResolverOptions. When EndpointResolverOptions' UseDualStackEndpoint
  126. // field is set it overrides this field value.
  127. UseDualstack bool
  128. // Allows you to enable the client to use path-style addressing, i.e.,
  129. // https://s3.amazonaws.com/BUCKET/KEY . By default, the S3 client will use virtual
  130. // hosted bucket addressing when possible( https://BUCKET.s3.amazonaws.com/KEY ).
  131. UsePathStyle bool
  132. // Signature Version 4a (SigV4a) Signer
  133. httpSignerV4a httpSignerV4a
  134. // The initial DefaultsMode used when the client options were constructed. If the
  135. // DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
  136. // value was at that point in time.
  137. //
  138. // Currently does not support per operation call overrides, may in the future.
  139. resolvedDefaultsMode aws.DefaultsMode
  140. // The HTTP client to invoke API calls with. Defaults to client's default HTTP
  141. // implementation if nil.
  142. HTTPClient HTTPClient
  143. // Client registry of operation interceptors.
  144. Interceptors smithyhttp.InterceptorRegistry
  145. // The auth scheme resolver which determines how to authenticate for each
  146. // operation.
  147. AuthSchemeResolver AuthSchemeResolver
  148. // The list of auth schemes supported by the client.
  149. AuthSchemes []smithyhttp.AuthScheme
  150. // Priority list of preferred auth scheme names (e.g. sigv4a).
  151. AuthSchemePreference []string
  152. }
  153. // Copy creates a clone where the APIOptions list is deep copied.
  154. func (o Options) Copy() Options {
  155. to := o
  156. to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions))
  157. copy(to.APIOptions, o.APIOptions)
  158. to.Interceptors = o.Interceptors.Copy()
  159. return to
  160. }
  161. func (o Options) GetIdentityResolver(schemeID string) smithyauth.IdentityResolver {
  162. if schemeID == "aws.auth#sigv4" {
  163. return getSigV4IdentityResolver(o)
  164. }
  165. if schemeID == "com.amazonaws.s3#sigv4express" {
  166. return getExpressIdentityResolver(o)
  167. }
  168. if schemeID == "aws.auth#sigv4a" {
  169. return getSigV4AIdentityResolver(o)
  170. }
  171. if schemeID == "smithy.api#noAuth" {
  172. return &smithyauth.AnonymousIdentityResolver{}
  173. }
  174. return nil
  175. }
  176. // WithAPIOptions returns a functional option for setting the Client's APIOptions
  177. // option.
  178. func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) {
  179. return func(o *Options) {
  180. o.APIOptions = append(o.APIOptions, optFns...)
  181. }
  182. }
  183. // Deprecated: EndpointResolver and WithEndpointResolver. Providing a value for
  184. // this field will likely prevent you from using any endpoint-related service
  185. // features released after the introduction of EndpointResolverV2 and BaseEndpoint.
  186. //
  187. // To migrate an EndpointResolver implementation that uses a custom endpoint, set
  188. // the client option BaseEndpoint instead.
  189. func WithEndpointResolver(v EndpointResolver) func(*Options) {
  190. return func(o *Options) {
  191. o.EndpointResolver = v
  192. }
  193. }
  194. // WithEndpointResolverV2 returns a functional option for setting the Client's
  195. // EndpointResolverV2 option.
  196. func WithEndpointResolverV2(v EndpointResolverV2) func(*Options) {
  197. return func(o *Options) {
  198. o.EndpointResolverV2 = v
  199. }
  200. }
  201. func getSigV4IdentityResolver(o Options) smithyauth.IdentityResolver {
  202. if o.Credentials != nil {
  203. return &internalauthsmithy.CredentialsProviderAdapter{Provider: o.Credentials}
  204. }
  205. return nil
  206. }
  207. // WithSigV4SigningName applies an override to the authentication workflow to
  208. // use the given signing name for SigV4-authenticated operations.
  209. //
  210. // This is an advanced setting. The value here is FINAL, taking precedence over
  211. // the resolved signing name from both auth scheme resolution and endpoint
  212. // resolution.
  213. func WithSigV4SigningName(name string) func(*Options) {
  214. fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
  215. out middleware.InitializeOutput, metadata middleware.Metadata, err error,
  216. ) {
  217. return next.HandleInitialize(awsmiddleware.SetSigningName(ctx, name), in)
  218. }
  219. return func(o *Options) {
  220. o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
  221. return s.Initialize.Add(
  222. middleware.InitializeMiddlewareFunc("withSigV4SigningName", fn),
  223. middleware.Before,
  224. )
  225. })
  226. }
  227. }
  228. // WithSigV4SigningRegion applies an override to the authentication workflow to
  229. // use the given signing region for SigV4-authenticated operations.
  230. //
  231. // This is an advanced setting. The value here is FINAL, taking precedence over
  232. // the resolved signing region from both auth scheme resolution and endpoint
  233. // resolution.
  234. func WithSigV4SigningRegion(region string) func(*Options) {
  235. fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
  236. out middleware.InitializeOutput, metadata middleware.Metadata, err error,
  237. ) {
  238. return next.HandleInitialize(awsmiddleware.SetSigningRegion(ctx, region), in)
  239. }
  240. return func(o *Options) {
  241. o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
  242. return s.Initialize.Add(
  243. middleware.InitializeMiddlewareFunc("withSigV4SigningRegion", fn),
  244. middleware.Before,
  245. )
  246. })
  247. }
  248. }
  249. func getSigV4AIdentityResolver(o Options) smithyauth.IdentityResolver {
  250. if o.Credentials != nil {
  251. return &v4a.CredentialsProviderAdapter{
  252. Provider: &v4a.SymmetricCredentialAdaptor{
  253. SymmetricProvider: o.Credentials,
  254. },
  255. }
  256. }
  257. return nil
  258. }
  259. // WithSigV4ASigningRegions applies an override to the authentication workflow to
  260. // use the given signing region set for SigV4A-authenticated operations.
  261. //
  262. // This is an advanced setting. The value here is FINAL, taking precedence over
  263. // the resolved signing region set from both auth scheme resolution and endpoint
  264. // resolution.
  265. func WithSigV4ASigningRegions(regions []string) func(*Options) {
  266. fn := func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
  267. out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
  268. ) {
  269. rscheme := getResolvedAuthScheme(ctx)
  270. if rscheme == nil {
  271. return out, metadata, fmt.Errorf("no resolved auth scheme")
  272. }
  273. smithyhttp.SetSigV4ASigningRegions(&rscheme.SignerProperties, regions)
  274. return next.HandleFinalize(ctx, in)
  275. }
  276. return func(o *Options) {
  277. o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
  278. return s.Finalize.Insert(
  279. middleware.FinalizeMiddlewareFunc("withSigV4ASigningRegions", fn),
  280. "Signing",
  281. middleware.Before,
  282. )
  283. })
  284. }
  285. }
  286. func ignoreAnonymousAuth(options *Options) {
  287. if aws.IsCredentialsProvider(options.Credentials, (*aws.AnonymousCredentials)(nil)) {
  288. options.Credentials = nil
  289. }
  290. }
  291. func getExpressIdentityResolver(o Options) smithyauth.IdentityResolver {
  292. if o.ExpressCredentials != nil {
  293. return &s3cust.ExpressIdentityResolver{Provider: o.ExpressCredentials}
  294. }
  295. return nil
  296. }