load_options.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. package config
  2. import (
  3. "context"
  4. "io"
  5. "github.com/aws/aws-sdk-go-v2/aws"
  6. "github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds"
  7. "github.com/aws/aws-sdk-go-v2/credentials/endpointcreds"
  8. "github.com/aws/aws-sdk-go-v2/credentials/processcreds"
  9. "github.com/aws/aws-sdk-go-v2/credentials/ssocreds"
  10. "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
  11. "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
  12. smithybearer "github.com/aws/smithy-go/auth/bearer"
  13. "github.com/aws/smithy-go/logging"
  14. "github.com/aws/smithy-go/middleware"
  15. )
  16. // LoadOptionsFunc is a type alias for LoadOptions functional option
  17. type LoadOptionsFunc func(*LoadOptions) error
  18. // LoadOptions are discrete set of options that are valid for loading the
  19. // configuration
  20. type LoadOptions struct {
  21. // Region is the region to send requests to.
  22. Region string
  23. // Credentials object to use when signing requests.
  24. Credentials aws.CredentialsProvider
  25. // Token provider for authentication operations with bearer authentication.
  26. BearerAuthTokenProvider smithybearer.TokenProvider
  27. // HTTPClient the SDK's API clients will use to invoke HTTP requests.
  28. HTTPClient HTTPClient
  29. // EndpointResolver that can be used to provide or override an endpoint for
  30. // the given service and region.
  31. //
  32. // See the `aws.EndpointResolver` documentation on usage.
  33. //
  34. // Deprecated: See EndpointResolverWithOptions
  35. EndpointResolver aws.EndpointResolver
  36. // EndpointResolverWithOptions that can be used to provide or override an
  37. // endpoint for the given service and region.
  38. //
  39. // See the `aws.EndpointResolverWithOptions` documentation on usage.
  40. EndpointResolverWithOptions aws.EndpointResolverWithOptions
  41. // RetryMaxAttempts specifies the maximum number attempts an API client
  42. // will call an operation that fails with a retryable error.
  43. //
  44. // This value will only be used if Retryer option is nil.
  45. RetryMaxAttempts int
  46. // RetryMode specifies the retry model the API client will be created with.
  47. //
  48. // This value will only be used if Retryer option is nil.
  49. RetryMode aws.RetryMode
  50. // Retryer is a function that provides a Retryer implementation. A Retryer
  51. // guides how HTTP requests should be retried in case of recoverable
  52. // failures.
  53. //
  54. // If not nil, RetryMaxAttempts, and RetryMode will be ignored.
  55. Retryer func() aws.Retryer
  56. // APIOptions provides the set of middleware mutations modify how the API
  57. // client requests will be handled. This is useful for adding additional
  58. // tracing data to a request, or changing behavior of the SDK's client.
  59. APIOptions []func(*middleware.Stack) error
  60. // Logger writer interface to write logging messages to.
  61. Logger logging.Logger
  62. // ClientLogMode is used to configure the events that will be sent to the
  63. // configured logger. This can be used to configure the logging of signing,
  64. // retries, request, and responses of the SDK clients.
  65. //
  66. // See the ClientLogMode type documentation for the complete set of logging
  67. // modes and available configuration.
  68. ClientLogMode *aws.ClientLogMode
  69. // SharedConfigProfile is the profile to be used when loading the SharedConfig
  70. SharedConfigProfile string
  71. // SharedConfigFiles is the slice of custom shared config files to use when
  72. // loading the SharedConfig. A non-default profile used within config file
  73. // must have name defined with prefix 'profile '. eg [profile xyz]
  74. // indicates a profile with name 'xyz'. To read more on the format of the
  75. // config file, please refer the documentation at
  76. // https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-config
  77. //
  78. // If duplicate profiles are provided within the same, or across multiple
  79. // shared config files, the next parsed profile will override only the
  80. // properties that conflict with the previously defined profile. Note that
  81. // if duplicate profiles are provided within the SharedCredentialsFiles and
  82. // SharedConfigFiles, the properties defined in shared credentials file
  83. // take precedence.
  84. SharedConfigFiles []string
  85. // SharedCredentialsFile is the slice of custom shared credentials files to
  86. // use when loading the SharedConfig. The profile name used within
  87. // credentials file must not prefix 'profile '. eg [xyz] indicates a
  88. // profile with name 'xyz'. Profile declared as [profile xyz] will be
  89. // ignored. To read more on the format of the credentials file, please
  90. // refer the documentation at
  91. // https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-creds
  92. //
  93. // If duplicate profiles are provided with a same, or across multiple
  94. // shared credentials files, the next parsed profile will override only
  95. // properties that conflict with the previously defined profile. Note that
  96. // if duplicate profiles are provided within the SharedCredentialsFiles and
  97. // SharedConfigFiles, the properties defined in shared credentials file
  98. // take precedence.
  99. SharedCredentialsFiles []string
  100. // CustomCABundle is CA bundle PEM bytes reader
  101. CustomCABundle io.Reader
  102. // DefaultRegion is the fall back region, used if a region was not resolved
  103. // from other sources
  104. DefaultRegion string
  105. // UseEC2IMDSRegion indicates if SDK should retrieve the region
  106. // from the EC2 Metadata service
  107. UseEC2IMDSRegion *UseEC2IMDSRegion
  108. // CredentialsCacheOptions is a function for setting the
  109. // aws.CredentialsCacheOptions
  110. CredentialsCacheOptions func(*aws.CredentialsCacheOptions)
  111. // BearerAuthTokenCacheOptions is a function for setting the smithy-go
  112. // auth/bearer#TokenCacheOptions
  113. BearerAuthTokenCacheOptions func(*smithybearer.TokenCacheOptions)
  114. // SSOTokenProviderOptions is a function for setting the
  115. // credentials/ssocreds.SSOTokenProviderOptions
  116. SSOTokenProviderOptions func(*ssocreds.SSOTokenProviderOptions)
  117. // ProcessCredentialOptions is a function for setting
  118. // the processcreds.Options
  119. ProcessCredentialOptions func(*processcreds.Options)
  120. // EC2RoleCredentialOptions is a function for setting
  121. // the ec2rolecreds.Options
  122. EC2RoleCredentialOptions func(*ec2rolecreds.Options)
  123. // EndpointCredentialOptions is a function for setting
  124. // the endpointcreds.Options
  125. EndpointCredentialOptions func(*endpointcreds.Options)
  126. // WebIdentityRoleCredentialOptions is a function for setting
  127. // the stscreds.WebIdentityRoleOptions
  128. WebIdentityRoleCredentialOptions func(*stscreds.WebIdentityRoleOptions)
  129. // AssumeRoleCredentialOptions is a function for setting the
  130. // stscreds.AssumeRoleOptions
  131. AssumeRoleCredentialOptions func(*stscreds.AssumeRoleOptions)
  132. // SSOProviderOptions is a function for setting
  133. // the ssocreds.Options
  134. SSOProviderOptions func(options *ssocreds.Options)
  135. // LogConfigurationWarnings when set to true, enables logging
  136. // configuration warnings
  137. LogConfigurationWarnings *bool
  138. // S3UseARNRegion specifies if the S3 service should allow ARNs to direct
  139. // the region, the client's requests are sent to.
  140. S3UseARNRegion *bool
  141. // EnableEndpointDiscovery specifies if endpoint discovery is enable for
  142. // the client.
  143. EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
  144. // Specifies if the EC2 IMDS service client is enabled.
  145. //
  146. // AWS_EC2_METADATA_DISABLED=true
  147. EC2IMDSClientEnableState imds.ClientEnableState
  148. // Specifies the EC2 Instance Metadata Service default endpoint selection
  149. // mode (IPv4 or IPv6)
  150. EC2IMDSEndpointMode imds.EndpointModeState
  151. // Specifies the EC2 Instance Metadata Service endpoint to use. If
  152. // specified it overrides EC2IMDSEndpointMode.
  153. EC2IMDSEndpoint string
  154. // Specifies that SDK clients must resolve a dual-stack endpoint for
  155. // services.
  156. UseDualStackEndpoint aws.DualStackEndpointState
  157. // Specifies that SDK clients must resolve a FIPS endpoint for
  158. // services.
  159. UseFIPSEndpoint aws.FIPSEndpointState
  160. // Specifies the SDK configuration mode for defaults.
  161. DefaultsModeOptions DefaultsModeOptions
  162. }
  163. func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
  164. if len(o.DefaultsModeOptions.Mode) == 0 {
  165. return "", false, nil
  166. }
  167. return o.DefaultsModeOptions.Mode, true, nil
  168. }
  169. // GetRetryMaxAttempts returns the RetryMaxAttempts if specified in the
  170. // LoadOptions and not 0.
  171. func (o LoadOptions) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) {
  172. if o.RetryMaxAttempts == 0 {
  173. return 0, false, nil
  174. }
  175. return o.RetryMaxAttempts, true, nil
  176. }
  177. // GetRetryMode returns the RetryMode specified in the LoadOptions.
  178. func (o LoadOptions) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
  179. if len(o.RetryMode) == 0 {
  180. return "", false, nil
  181. }
  182. return o.RetryMode, true, nil
  183. }
  184. func (o LoadOptions) getDefaultsModeIMDSClient(ctx context.Context) (*imds.Client, bool, error) {
  185. if o.DefaultsModeOptions.IMDSClient == nil {
  186. return nil, false, nil
  187. }
  188. return o.DefaultsModeOptions.IMDSClient, true, nil
  189. }
  190. // getRegion returns Region from config's LoadOptions
  191. func (o LoadOptions) getRegion(ctx context.Context) (string, bool, error) {
  192. if len(o.Region) == 0 {
  193. return "", false, nil
  194. }
  195. return o.Region, true, nil
  196. }
  197. // WithRegion is a helper function to construct functional options
  198. // that sets Region on config's LoadOptions. Setting the region to
  199. // an empty string, will result in the region value being ignored.
  200. // If multiple WithRegion calls are made, the last call overrides
  201. // the previous call values.
  202. func WithRegion(v string) LoadOptionsFunc {
  203. return func(o *LoadOptions) error {
  204. o.Region = v
  205. return nil
  206. }
  207. }
  208. // getDefaultRegion returns DefaultRegion from config's LoadOptions
  209. func (o LoadOptions) getDefaultRegion(ctx context.Context) (string, bool, error) {
  210. if len(o.DefaultRegion) == 0 {
  211. return "", false, nil
  212. }
  213. return o.DefaultRegion, true, nil
  214. }
  215. // WithDefaultRegion is a helper function to construct functional options
  216. // that sets a DefaultRegion on config's LoadOptions. Setting the default
  217. // region to an empty string, will result in the default region value
  218. // being ignored. If multiple WithDefaultRegion calls are made, the last
  219. // call overrides the previous call values. Note that both WithRegion and
  220. // WithEC2IMDSRegion call takes precedence over WithDefaultRegion call
  221. // when resolving region.
  222. func WithDefaultRegion(v string) LoadOptionsFunc {
  223. return func(o *LoadOptions) error {
  224. o.DefaultRegion = v
  225. return nil
  226. }
  227. }
  228. // getSharedConfigProfile returns SharedConfigProfile from config's LoadOptions
  229. func (o LoadOptions) getSharedConfigProfile(ctx context.Context) (string, bool, error) {
  230. if len(o.SharedConfigProfile) == 0 {
  231. return "", false, nil
  232. }
  233. return o.SharedConfigProfile, true, nil
  234. }
  235. // WithSharedConfigProfile is a helper function to construct functional options
  236. // that sets SharedConfigProfile on config's LoadOptions. Setting the shared
  237. // config profile to an empty string, will result in the shared config profile
  238. // value being ignored.
  239. // If multiple WithSharedConfigProfile calls are made, the last call overrides
  240. // the previous call values.
  241. func WithSharedConfigProfile(v string) LoadOptionsFunc {
  242. return func(o *LoadOptions) error {
  243. o.SharedConfigProfile = v
  244. return nil
  245. }
  246. }
  247. // getSharedConfigFiles returns SharedConfigFiles set on config's LoadOptions
  248. func (o LoadOptions) getSharedConfigFiles(ctx context.Context) ([]string, bool, error) {
  249. if o.SharedConfigFiles == nil {
  250. return nil, false, nil
  251. }
  252. return o.SharedConfigFiles, true, nil
  253. }
  254. // WithSharedConfigFiles is a helper function to construct functional options
  255. // that sets slice of SharedConfigFiles on config's LoadOptions.
  256. // Setting the shared config files to an nil string slice, will result in the
  257. // shared config files value being ignored.
  258. // If multiple WithSharedConfigFiles calls are made, the last call overrides
  259. // the previous call values.
  260. func WithSharedConfigFiles(v []string) LoadOptionsFunc {
  261. return func(o *LoadOptions) error {
  262. o.SharedConfigFiles = v
  263. return nil
  264. }
  265. }
  266. // getSharedCredentialsFiles returns SharedCredentialsFiles set on config's LoadOptions
  267. func (o LoadOptions) getSharedCredentialsFiles(ctx context.Context) ([]string, bool, error) {
  268. if o.SharedCredentialsFiles == nil {
  269. return nil, false, nil
  270. }
  271. return o.SharedCredentialsFiles, true, nil
  272. }
  273. // WithSharedCredentialsFiles is a helper function to construct functional options
  274. // that sets slice of SharedCredentialsFiles on config's LoadOptions.
  275. // Setting the shared credentials files to an nil string slice, will result in the
  276. // shared credentials files value being ignored.
  277. // If multiple WithSharedCredentialsFiles calls are made, the last call overrides
  278. // the previous call values.
  279. func WithSharedCredentialsFiles(v []string) LoadOptionsFunc {
  280. return func(o *LoadOptions) error {
  281. o.SharedCredentialsFiles = v
  282. return nil
  283. }
  284. }
  285. // getCustomCABundle returns CustomCABundle from LoadOptions
  286. func (o LoadOptions) getCustomCABundle(ctx context.Context) (io.Reader, bool, error) {
  287. if o.CustomCABundle == nil {
  288. return nil, false, nil
  289. }
  290. return o.CustomCABundle, true, nil
  291. }
  292. // WithCustomCABundle is a helper function to construct functional options
  293. // that sets CustomCABundle on config's LoadOptions. Setting the custom CA Bundle
  294. // to nil will result in custom CA Bundle value being ignored.
  295. // If multiple WithCustomCABundle calls are made, the last call overrides the
  296. // previous call values.
  297. func WithCustomCABundle(v io.Reader) LoadOptionsFunc {
  298. return func(o *LoadOptions) error {
  299. o.CustomCABundle = v
  300. return nil
  301. }
  302. }
  303. // UseEC2IMDSRegion provides a regionProvider that retrieves the region
  304. // from the EC2 Metadata service.
  305. type UseEC2IMDSRegion struct {
  306. // If unset will default to generic EC2 IMDS client.
  307. Client *imds.Client
  308. }
  309. // getRegion attempts to retrieve the region from EC2 Metadata service.
  310. func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error) {
  311. if ctx == nil {
  312. ctx = context.Background()
  313. }
  314. client := p.Client
  315. if client == nil {
  316. client = imds.New(imds.Options{})
  317. }
  318. result, err := client.GetRegion(ctx, nil)
  319. if err != nil {
  320. return "", false, err
  321. }
  322. if len(result.Region) != 0 {
  323. return result.Region, true, nil
  324. }
  325. return "", false, nil
  326. }
  327. // getEC2IMDSRegion returns the value of EC2 IMDS region.
  328. func (o LoadOptions) getEC2IMDSRegion(ctx context.Context) (string, bool, error) {
  329. if o.UseEC2IMDSRegion == nil {
  330. return "", false, nil
  331. }
  332. return o.UseEC2IMDSRegion.getRegion(ctx)
  333. }
  334. // WithEC2IMDSRegion is a helper function to construct functional options
  335. // that enables resolving EC2IMDS region. The function takes
  336. // in a UseEC2IMDSRegion functional option, and can be used to set the
  337. // EC2IMDS client which will be used to resolve EC2IMDSRegion.
  338. // If no functional option is provided, an EC2IMDS client is built and used
  339. // by the resolver. If multiple WithEC2IMDSRegion calls are made, the last
  340. // call overrides the previous call values. Note that the WithRegion calls takes
  341. // precedence over WithEC2IMDSRegion when resolving region.
  342. func WithEC2IMDSRegion(fnOpts ...func(o *UseEC2IMDSRegion)) LoadOptionsFunc {
  343. return func(o *LoadOptions) error {
  344. o.UseEC2IMDSRegion = &UseEC2IMDSRegion{}
  345. for _, fn := range fnOpts {
  346. fn(o.UseEC2IMDSRegion)
  347. }
  348. return nil
  349. }
  350. }
  351. // getCredentialsProvider returns the credentials value
  352. func (o LoadOptions) getCredentialsProvider(ctx context.Context) (aws.CredentialsProvider, bool, error) {
  353. if o.Credentials == nil {
  354. return nil, false, nil
  355. }
  356. return o.Credentials, true, nil
  357. }
  358. // WithCredentialsProvider is a helper function to construct functional options
  359. // that sets Credential provider value on config's LoadOptions. If credentials
  360. // provider is set to nil, the credentials provider value will be ignored.
  361. // If multiple WithCredentialsProvider calls are made, the last call overrides
  362. // the previous call values.
  363. func WithCredentialsProvider(v aws.CredentialsProvider) LoadOptionsFunc {
  364. return func(o *LoadOptions) error {
  365. o.Credentials = v
  366. return nil
  367. }
  368. }
  369. // getCredentialsCacheOptionsProvider returns the wrapped function to set aws.CredentialsCacheOptions
  370. func (o LoadOptions) getCredentialsCacheOptions(ctx context.Context) (func(*aws.CredentialsCacheOptions), bool, error) {
  371. if o.CredentialsCacheOptions == nil {
  372. return nil, false, nil
  373. }
  374. return o.CredentialsCacheOptions, true, nil
  375. }
  376. // WithCredentialsCacheOptions is a helper function to construct functional
  377. // options that sets a function to modify the aws.CredentialsCacheOptions the
  378. // aws.CredentialsCache will be configured with, if the CredentialsCache is used
  379. // by the configuration loader.
  380. //
  381. // If multiple WithCredentialsCacheOptions calls are made, the last call
  382. // overrides the previous call values.
  383. func WithCredentialsCacheOptions(v func(*aws.CredentialsCacheOptions)) LoadOptionsFunc {
  384. return func(o *LoadOptions) error {
  385. o.CredentialsCacheOptions = v
  386. return nil
  387. }
  388. }
  389. // getBearerAuthTokenProvider returns the credentials value
  390. func (o LoadOptions) getBearerAuthTokenProvider(ctx context.Context) (smithybearer.TokenProvider, bool, error) {
  391. if o.BearerAuthTokenProvider == nil {
  392. return nil, false, nil
  393. }
  394. return o.BearerAuthTokenProvider, true, nil
  395. }
  396. // WithBearerAuthTokenProvider is a helper function to construct functional options
  397. // that sets Credential provider value on config's LoadOptions. If credentials
  398. // provider is set to nil, the credentials provider value will be ignored.
  399. // If multiple WithBearerAuthTokenProvider calls are made, the last call overrides
  400. // the previous call values.
  401. func WithBearerAuthTokenProvider(v smithybearer.TokenProvider) LoadOptionsFunc {
  402. return func(o *LoadOptions) error {
  403. o.BearerAuthTokenProvider = v
  404. return nil
  405. }
  406. }
  407. // getBearerAuthTokenCacheOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
  408. func (o LoadOptions) getBearerAuthTokenCacheOptions(ctx context.Context) (func(*smithybearer.TokenCacheOptions), bool, error) {
  409. if o.BearerAuthTokenCacheOptions == nil {
  410. return nil, false, nil
  411. }
  412. return o.BearerAuthTokenCacheOptions, true, nil
  413. }
  414. // WithBearerAuthTokenCacheOptions is a helper function to construct functional options
  415. // that sets a function to modify the TokenCacheOptions the smithy-go
  416. // auth/bearer#TokenCache will be configured with, if the TokenCache is used by
  417. // the configuration loader.
  418. //
  419. // If multiple WithBearerAuthTokenCacheOptions calls are made, the last call overrides
  420. // the previous call values.
  421. func WithBearerAuthTokenCacheOptions(v func(*smithybearer.TokenCacheOptions)) LoadOptionsFunc {
  422. return func(o *LoadOptions) error {
  423. o.BearerAuthTokenCacheOptions = v
  424. return nil
  425. }
  426. }
  427. // getSSOTokenProviderOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
  428. func (o LoadOptions) getSSOTokenProviderOptions(ctx context.Context) (func(*ssocreds.SSOTokenProviderOptions), bool, error) {
  429. if o.SSOTokenProviderOptions == nil {
  430. return nil, false, nil
  431. }
  432. return o.SSOTokenProviderOptions, true, nil
  433. }
  434. // WithSSOTokenProviderOptions is a helper function to construct functional
  435. // options that sets a function to modify the SSOtokenProviderOptions the SDK's
  436. // credentials/ssocreds#SSOProvider will be configured with, if the
  437. // SSOTokenProvider is used by the configuration loader.
  438. //
  439. // If multiple WithSSOTokenProviderOptions calls are made, the last call overrides
  440. // the previous call values.
  441. func WithSSOTokenProviderOptions(v func(*ssocreds.SSOTokenProviderOptions)) LoadOptionsFunc {
  442. return func(o *LoadOptions) error {
  443. o.SSOTokenProviderOptions = v
  444. return nil
  445. }
  446. }
  447. // getProcessCredentialOptions returns the wrapped function to set processcreds.Options
  448. func (o LoadOptions) getProcessCredentialOptions(ctx context.Context) (func(*processcreds.Options), bool, error) {
  449. if o.ProcessCredentialOptions == nil {
  450. return nil, false, nil
  451. }
  452. return o.ProcessCredentialOptions, true, nil
  453. }
  454. // WithProcessCredentialOptions is a helper function to construct functional options
  455. // that sets a function to use processcreds.Options on config's LoadOptions.
  456. // If process credential options is set to nil, the process credential value will
  457. // be ignored. If multiple WithProcessCredentialOptions calls are made, the last call
  458. // overrides the previous call values.
  459. func WithProcessCredentialOptions(v func(*processcreds.Options)) LoadOptionsFunc {
  460. return func(o *LoadOptions) error {
  461. o.ProcessCredentialOptions = v
  462. return nil
  463. }
  464. }
  465. // getEC2RoleCredentialOptions returns the wrapped function to set the ec2rolecreds.Options
  466. func (o LoadOptions) getEC2RoleCredentialOptions(ctx context.Context) (func(*ec2rolecreds.Options), bool, error) {
  467. if o.EC2RoleCredentialOptions == nil {
  468. return nil, false, nil
  469. }
  470. return o.EC2RoleCredentialOptions, true, nil
  471. }
  472. // WithEC2RoleCredentialOptions is a helper function to construct functional options
  473. // that sets a function to use ec2rolecreds.Options on config's LoadOptions. If
  474. // EC2 role credential options is set to nil, the EC2 role credential options value
  475. // will be ignored. If multiple WithEC2RoleCredentialOptions calls are made,
  476. // the last call overrides the previous call values.
  477. func WithEC2RoleCredentialOptions(v func(*ec2rolecreds.Options)) LoadOptionsFunc {
  478. return func(o *LoadOptions) error {
  479. o.EC2RoleCredentialOptions = v
  480. return nil
  481. }
  482. }
  483. // getEndpointCredentialOptions returns the wrapped function to set endpointcreds.Options
  484. func (o LoadOptions) getEndpointCredentialOptions(context.Context) (func(*endpointcreds.Options), bool, error) {
  485. if o.EndpointCredentialOptions == nil {
  486. return nil, false, nil
  487. }
  488. return o.EndpointCredentialOptions, true, nil
  489. }
  490. // WithEndpointCredentialOptions is a helper function to construct functional options
  491. // that sets a function to use endpointcreds.Options on config's LoadOptions. If
  492. // endpoint credential options is set to nil, the endpoint credential options
  493. // value will be ignored. If multiple WithEndpointCredentialOptions calls are made,
  494. // the last call overrides the previous call values.
  495. func WithEndpointCredentialOptions(v func(*endpointcreds.Options)) LoadOptionsFunc {
  496. return func(o *LoadOptions) error {
  497. o.EndpointCredentialOptions = v
  498. return nil
  499. }
  500. }
  501. // getWebIdentityRoleCredentialOptions returns the wrapped function
  502. func (o LoadOptions) getWebIdentityRoleCredentialOptions(context.Context) (func(*stscreds.WebIdentityRoleOptions), bool, error) {
  503. if o.WebIdentityRoleCredentialOptions == nil {
  504. return nil, false, nil
  505. }
  506. return o.WebIdentityRoleCredentialOptions, true, nil
  507. }
  508. // WithWebIdentityRoleCredentialOptions is a helper function to construct
  509. // functional options that sets a function to use stscreds.WebIdentityRoleOptions
  510. // on config's LoadOptions. If web identity role credentials options is set to nil,
  511. // the web identity role credentials value will be ignored. If multiple
  512. // WithWebIdentityRoleCredentialOptions calls are made, the last call
  513. // overrides the previous call values.
  514. func WithWebIdentityRoleCredentialOptions(v func(*stscreds.WebIdentityRoleOptions)) LoadOptionsFunc {
  515. return func(o *LoadOptions) error {
  516. o.WebIdentityRoleCredentialOptions = v
  517. return nil
  518. }
  519. }
  520. // getAssumeRoleCredentialOptions returns AssumeRoleCredentialOptions from LoadOptions
  521. func (o LoadOptions) getAssumeRoleCredentialOptions(context.Context) (func(options *stscreds.AssumeRoleOptions), bool, error) {
  522. if o.AssumeRoleCredentialOptions == nil {
  523. return nil, false, nil
  524. }
  525. return o.AssumeRoleCredentialOptions, true, nil
  526. }
  527. // WithAssumeRoleCredentialOptions is a helper function to construct
  528. // functional options that sets a function to use stscreds.AssumeRoleOptions
  529. // on config's LoadOptions. If assume role credentials options is set to nil,
  530. // the assume role credentials value will be ignored. If multiple
  531. // WithAssumeRoleCredentialOptions calls are made, the last call overrides
  532. // the previous call values.
  533. func WithAssumeRoleCredentialOptions(v func(*stscreds.AssumeRoleOptions)) LoadOptionsFunc {
  534. return func(o *LoadOptions) error {
  535. o.AssumeRoleCredentialOptions = v
  536. return nil
  537. }
  538. }
  539. func (o LoadOptions) getHTTPClient(ctx context.Context) (HTTPClient, bool, error) {
  540. if o.HTTPClient == nil {
  541. return nil, false, nil
  542. }
  543. return o.HTTPClient, true, nil
  544. }
  545. // WithHTTPClient is a helper function to construct functional options
  546. // that sets HTTPClient on LoadOptions. If HTTPClient is set to nil,
  547. // the HTTPClient value will be ignored.
  548. // If multiple WithHTTPClient calls are made, the last call overrides
  549. // the previous call values.
  550. func WithHTTPClient(v HTTPClient) LoadOptionsFunc {
  551. return func(o *LoadOptions) error {
  552. o.HTTPClient = v
  553. return nil
  554. }
  555. }
  556. func (o LoadOptions) getAPIOptions(ctx context.Context) ([]func(*middleware.Stack) error, bool, error) {
  557. if o.APIOptions == nil {
  558. return nil, false, nil
  559. }
  560. return o.APIOptions, true, nil
  561. }
  562. // WithAPIOptions is a helper function to construct functional options
  563. // that sets APIOptions on LoadOptions. If APIOptions is set to nil, the
  564. // APIOptions value is ignored. If multiple WithAPIOptions calls are
  565. // made, the last call overrides the previous call values.
  566. func WithAPIOptions(v []func(*middleware.Stack) error) LoadOptionsFunc {
  567. return func(o *LoadOptions) error {
  568. if v == nil {
  569. return nil
  570. }
  571. o.APIOptions = append(o.APIOptions, v...)
  572. return nil
  573. }
  574. }
  575. func (o LoadOptions) getRetryMaxAttempts(ctx context.Context) (int, bool, error) {
  576. if o.RetryMaxAttempts == 0 {
  577. return 0, false, nil
  578. }
  579. return o.RetryMaxAttempts, true, nil
  580. }
  581. // WithRetryMaxAttempts is a helper function to construct functional options that sets
  582. // RetryMaxAttempts on LoadOptions. If RetryMaxAttempts is unset, the RetryMaxAttempts value is
  583. // ignored. If multiple WithRetryMaxAttempts calls are made, the last call overrides
  584. // the previous call values.
  585. //
  586. // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
  587. func WithRetryMaxAttempts(v int) LoadOptionsFunc {
  588. return func(o *LoadOptions) error {
  589. o.RetryMaxAttempts = v
  590. return nil
  591. }
  592. }
  593. func (o LoadOptions) getRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
  594. if o.RetryMode == "" {
  595. return "", false, nil
  596. }
  597. return o.RetryMode, true, nil
  598. }
  599. // WithRetryMode is a helper function to construct functional options that sets
  600. // RetryMode on LoadOptions. If RetryMode is unset, the RetryMode value is
  601. // ignored. If multiple WithRetryMode calls are made, the last call overrides
  602. // the previous call values.
  603. //
  604. // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
  605. func WithRetryMode(v aws.RetryMode) LoadOptionsFunc {
  606. return func(o *LoadOptions) error {
  607. o.RetryMode = v
  608. return nil
  609. }
  610. }
  611. func (o LoadOptions) getRetryer(ctx context.Context) (func() aws.Retryer, bool, error) {
  612. if o.Retryer == nil {
  613. return nil, false, nil
  614. }
  615. return o.Retryer, true, nil
  616. }
  617. // WithRetryer is a helper function to construct functional options
  618. // that sets Retryer on LoadOptions. If Retryer is set to nil, the
  619. // Retryer value is ignored. If multiple WithRetryer calls are
  620. // made, the last call overrides the previous call values.
  621. func WithRetryer(v func() aws.Retryer) LoadOptionsFunc {
  622. return func(o *LoadOptions) error {
  623. o.Retryer = v
  624. return nil
  625. }
  626. }
  627. func (o LoadOptions) getEndpointResolver(ctx context.Context) (aws.EndpointResolver, bool, error) {
  628. if o.EndpointResolver == nil {
  629. return nil, false, nil
  630. }
  631. return o.EndpointResolver, true, nil
  632. }
  633. // WithEndpointResolver is a helper function to construct functional options
  634. // that sets the EndpointResolver on LoadOptions. If the EndpointResolver is set to nil,
  635. // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
  636. // are made, the last call overrides the previous call values.
  637. //
  638. // Deprecated: See WithEndpointResolverWithOptions
  639. func WithEndpointResolver(v aws.EndpointResolver) LoadOptionsFunc {
  640. return func(o *LoadOptions) error {
  641. o.EndpointResolver = v
  642. return nil
  643. }
  644. }
  645. func (o LoadOptions) getEndpointResolverWithOptions(ctx context.Context) (aws.EndpointResolverWithOptions, bool, error) {
  646. if o.EndpointResolverWithOptions == nil {
  647. return nil, false, nil
  648. }
  649. return o.EndpointResolverWithOptions, true, nil
  650. }
  651. // WithEndpointResolverWithOptions is a helper function to construct functional options
  652. // that sets the EndpointResolverWithOptions on LoadOptions. If the EndpointResolverWithOptions is set to nil,
  653. // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
  654. // are made, the last call overrides the previous call values.
  655. func WithEndpointResolverWithOptions(v aws.EndpointResolverWithOptions) LoadOptionsFunc {
  656. return func(o *LoadOptions) error {
  657. o.EndpointResolverWithOptions = v
  658. return nil
  659. }
  660. }
  661. func (o LoadOptions) getLogger(ctx context.Context) (logging.Logger, bool, error) {
  662. if o.Logger == nil {
  663. return nil, false, nil
  664. }
  665. return o.Logger, true, nil
  666. }
  667. // WithLogger is a helper function to construct functional options
  668. // that sets Logger on LoadOptions. If Logger is set to nil, the
  669. // Logger value will be ignored. If multiple WithLogger calls are made,
  670. // the last call overrides the previous call values.
  671. func WithLogger(v logging.Logger) LoadOptionsFunc {
  672. return func(o *LoadOptions) error {
  673. o.Logger = v
  674. return nil
  675. }
  676. }
  677. func (o LoadOptions) getClientLogMode(ctx context.Context) (aws.ClientLogMode, bool, error) {
  678. if o.ClientLogMode == nil {
  679. return 0, false, nil
  680. }
  681. return *o.ClientLogMode, true, nil
  682. }
  683. // WithClientLogMode is a helper function to construct functional options
  684. // that sets client log mode on LoadOptions. If client log mode is set to nil,
  685. // the client log mode value will be ignored. If multiple WithClientLogMode calls are made,
  686. // the last call overrides the previous call values.
  687. func WithClientLogMode(v aws.ClientLogMode) LoadOptionsFunc {
  688. return func(o *LoadOptions) error {
  689. o.ClientLogMode = &v
  690. return nil
  691. }
  692. }
  693. func (o LoadOptions) getLogConfigurationWarnings(ctx context.Context) (v bool, found bool, err error) {
  694. if o.LogConfigurationWarnings == nil {
  695. return false, false, nil
  696. }
  697. return *o.LogConfigurationWarnings, true, nil
  698. }
  699. // WithLogConfigurationWarnings is a helper function to construct
  700. // functional options that can be used to set LogConfigurationWarnings
  701. // on LoadOptions.
  702. //
  703. // If multiple WithLogConfigurationWarnings calls are made, the last call
  704. // overrides the previous call values.
  705. func WithLogConfigurationWarnings(v bool) LoadOptionsFunc {
  706. return func(o *LoadOptions) error {
  707. o.LogConfigurationWarnings = &v
  708. return nil
  709. }
  710. }
  711. // GetS3UseARNRegion returns whether to allow ARNs to direct the region
  712. // the S3 client's requests are sent to.
  713. func (o LoadOptions) GetS3UseARNRegion(ctx context.Context) (v bool, found bool, err error) {
  714. if o.S3UseARNRegion == nil {
  715. return false, false, nil
  716. }
  717. return *o.S3UseARNRegion, true, nil
  718. }
  719. // WithS3UseARNRegion is a helper function to construct functional options
  720. // that can be used to set S3UseARNRegion on LoadOptions.
  721. // If multiple WithS3UseARNRegion calls are made, the last call overrides
  722. // the previous call values.
  723. func WithS3UseARNRegion(v bool) LoadOptionsFunc {
  724. return func(o *LoadOptions) error {
  725. o.S3UseARNRegion = &v
  726. return nil
  727. }
  728. }
  729. // GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
  730. func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
  731. if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {
  732. return aws.EndpointDiscoveryUnset, false, nil
  733. }
  734. return o.EnableEndpointDiscovery, true, nil
  735. }
  736. // WithEndpointDiscovery is a helper function to construct functional options
  737. // that can be used to enable endpoint discovery on LoadOptions for supported clients.
  738. // If multiple WithEndpointDiscovery calls are made, the last call overrides
  739. // the previous call values.
  740. func WithEndpointDiscovery(v aws.EndpointDiscoveryEnableState) LoadOptionsFunc {
  741. return func(o *LoadOptions) error {
  742. o.EnableEndpointDiscovery = v
  743. return nil
  744. }
  745. }
  746. // getSSOProviderOptions returns AssumeRoleCredentialOptions from LoadOptions
  747. func (o LoadOptions) getSSOProviderOptions(context.Context) (func(options *ssocreds.Options), bool, error) {
  748. if o.SSOProviderOptions == nil {
  749. return nil, false, nil
  750. }
  751. return o.SSOProviderOptions, true, nil
  752. }
  753. // WithSSOProviderOptions is a helper function to construct
  754. // functional options that sets a function to use ssocreds.Options
  755. // on config's LoadOptions. If the SSO credential provider options is set to nil,
  756. // the sso provider options value will be ignored. If multiple
  757. // WithSSOProviderOptions calls are made, the last call overrides
  758. // the previous call values.
  759. func WithSSOProviderOptions(v func(*ssocreds.Options)) LoadOptionsFunc {
  760. return func(o *LoadOptions) error {
  761. o.SSOProviderOptions = v
  762. return nil
  763. }
  764. }
  765. // GetEC2IMDSClientEnableState implements a EC2IMDSClientEnableState options resolver interface.
  766. func (o LoadOptions) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error) {
  767. if o.EC2IMDSClientEnableState == imds.ClientDefaultEnableState {
  768. return imds.ClientDefaultEnableState, false, nil
  769. }
  770. return o.EC2IMDSClientEnableState, true, nil
  771. }
  772. // GetEC2IMDSEndpointMode implements a EC2IMDSEndpointMode option resolver interface.
  773. func (o LoadOptions) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error) {
  774. if o.EC2IMDSEndpointMode == imds.EndpointModeStateUnset {
  775. return imds.EndpointModeStateUnset, false, nil
  776. }
  777. return o.EC2IMDSEndpointMode, true, nil
  778. }
  779. // GetEC2IMDSEndpoint implements a EC2IMDSEndpoint option resolver interface.
  780. func (o LoadOptions) GetEC2IMDSEndpoint() (string, bool, error) {
  781. if len(o.EC2IMDSEndpoint) == 0 {
  782. return "", false, nil
  783. }
  784. return o.EC2IMDSEndpoint, true, nil
  785. }
  786. // WithEC2IMDSClientEnableState is a helper function to construct functional options that sets the EC2IMDSClientEnableState.
  787. func WithEC2IMDSClientEnableState(v imds.ClientEnableState) LoadOptionsFunc {
  788. return func(o *LoadOptions) error {
  789. o.EC2IMDSClientEnableState = v
  790. return nil
  791. }
  792. }
  793. // WithEC2IMDSEndpointMode is a helper function to construct functional options that sets the EC2IMDSEndpointMode.
  794. func WithEC2IMDSEndpointMode(v imds.EndpointModeState) LoadOptionsFunc {
  795. return func(o *LoadOptions) error {
  796. o.EC2IMDSEndpointMode = v
  797. return nil
  798. }
  799. }
  800. // WithEC2IMDSEndpoint is a helper function to construct functional options that sets the EC2IMDSEndpoint.
  801. func WithEC2IMDSEndpoint(v string) LoadOptionsFunc {
  802. return func(o *LoadOptions) error {
  803. o.EC2IMDSEndpoint = v
  804. return nil
  805. }
  806. }
  807. // WithUseDualStackEndpoint is a helper function to construct
  808. // functional options that can be used to set UseDualStackEndpoint on LoadOptions.
  809. func WithUseDualStackEndpoint(v aws.DualStackEndpointState) LoadOptionsFunc {
  810. return func(o *LoadOptions) error {
  811. o.UseDualStackEndpoint = v
  812. return nil
  813. }
  814. }
  815. // GetUseDualStackEndpoint returns whether the service's dual-stack endpoint should be
  816. // used for requests.
  817. func (o LoadOptions) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error) {
  818. if o.UseDualStackEndpoint == aws.DualStackEndpointStateUnset {
  819. return aws.DualStackEndpointStateUnset, false, nil
  820. }
  821. return o.UseDualStackEndpoint, true, nil
  822. }
  823. // WithUseFIPSEndpoint is a helper function to construct
  824. // functional options that can be used to set UseFIPSEndpoint on LoadOptions.
  825. func WithUseFIPSEndpoint(v aws.FIPSEndpointState) LoadOptionsFunc {
  826. return func(o *LoadOptions) error {
  827. o.UseFIPSEndpoint = v
  828. return nil
  829. }
  830. }
  831. // GetUseFIPSEndpoint returns whether the service's FIPS endpoint should be
  832. // used for requests.
  833. func (o LoadOptions) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEndpointState, found bool, err error) {
  834. if o.UseFIPSEndpoint == aws.FIPSEndpointStateUnset {
  835. return aws.FIPSEndpointStateUnset, false, nil
  836. }
  837. return o.UseFIPSEndpoint, true, nil
  838. }
  839. // WithDefaultsMode sets the SDK defaults configuration mode to the value provided.
  840. //
  841. // Zero or more functional options can be provided to provide configuration options for performing
  842. // environment discovery when using aws.DefaultsModeAuto.
  843. func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsModeOptions)) LoadOptionsFunc {
  844. do := DefaultsModeOptions{
  845. Mode: mode,
  846. }
  847. for _, fn := range optFns {
  848. fn(&do)
  849. }
  850. return func(options *LoadOptions) error {
  851. options.DefaultsModeOptions = do
  852. return nil
  853. }
  854. }