load_options.go 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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. smithyhttp "github.com/aws/smithy-go/transport/http"
  16. )
  17. // LoadOptionsFunc is a type alias for LoadOptions functional option
  18. type LoadOptionsFunc func(*LoadOptions) error
  19. // LoadOptions are discrete set of options that are valid for loading the
  20. // configuration
  21. type LoadOptions struct {
  22. // Region is the region to send requests to.
  23. Region string
  24. // Credentials object to use when signing requests.
  25. Credentials aws.CredentialsProvider
  26. // Token provider for authentication operations with bearer authentication.
  27. BearerAuthTokenProvider smithybearer.TokenProvider
  28. // HTTPClient the SDK's API clients will use to invoke HTTP requests.
  29. HTTPClient HTTPClient
  30. // EndpointResolver that can be used to provide or override an endpoint for
  31. // the given service and region.
  32. //
  33. // See the `aws.EndpointResolver` documentation on usage.
  34. //
  35. // Deprecated: See EndpointResolverWithOptions
  36. EndpointResolver aws.EndpointResolver
  37. // EndpointResolverWithOptions that can be used to provide or override an
  38. // endpoint for the given service and region.
  39. //
  40. // See the `aws.EndpointResolverWithOptions` documentation on usage.
  41. EndpointResolverWithOptions aws.EndpointResolverWithOptions
  42. // RetryMaxAttempts specifies the maximum number attempts an API client
  43. // will call an operation that fails with a retryable error.
  44. //
  45. // This value will only be used if Retryer option is nil.
  46. RetryMaxAttempts int
  47. // RetryMode specifies the retry model the API client will be created with.
  48. //
  49. // This value will only be used if Retryer option is nil.
  50. RetryMode aws.RetryMode
  51. // Retryer is a function that provides a Retryer implementation. A Retryer
  52. // guides how HTTP requests should be retried in case of recoverable
  53. // failures.
  54. //
  55. // If not nil, RetryMaxAttempts, and RetryMode will be ignored.
  56. Retryer func() aws.Retryer
  57. // APIOptions provides the set of middleware mutations modify how the API
  58. // client requests will be handled. This is useful for adding additional
  59. // tracing data to a request, or changing behavior of the SDK's client.
  60. APIOptions []func(*middleware.Stack) error
  61. // Logger writer interface to write logging messages to.
  62. Logger logging.Logger
  63. // ClientLogMode is used to configure the events that will be sent to the
  64. // configured logger. This can be used to configure the logging of signing,
  65. // retries, request, and responses of the SDK clients.
  66. //
  67. // See the ClientLogMode type documentation for the complete set of logging
  68. // modes and available configuration.
  69. ClientLogMode *aws.ClientLogMode
  70. // SharedConfigProfile is the profile to be used when loading the SharedConfig
  71. SharedConfigProfile string
  72. // SharedConfigFiles is the slice of custom shared config files to use when
  73. // loading the SharedConfig. A non-default profile used within config file
  74. // must have name defined with prefix 'profile '. eg [profile xyz]
  75. // indicates a profile with name 'xyz'. To read more on the format of the
  76. // config file, please refer the documentation at
  77. // https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-config
  78. //
  79. // If duplicate profiles are provided within the same, or across multiple
  80. // shared config files, the next parsed profile will override only the
  81. // properties that conflict with the previously defined profile. Note that
  82. // if duplicate profiles are provided within the SharedCredentialsFiles and
  83. // SharedConfigFiles, the properties defined in shared credentials file
  84. // take precedence.
  85. SharedConfigFiles []string
  86. // SharedCredentialsFile is the slice of custom shared credentials files to
  87. // use when loading the SharedConfig. The profile name used within
  88. // credentials file must not prefix 'profile '. eg [xyz] indicates a
  89. // profile with name 'xyz'. Profile declared as [profile xyz] will be
  90. // ignored. To read more on the format of the credentials file, please
  91. // refer the documentation at
  92. // https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-creds
  93. //
  94. // If duplicate profiles are provided with a same, or across multiple
  95. // shared credentials files, the next parsed profile will override only
  96. // properties that conflict with the previously defined profile. Note that
  97. // if duplicate profiles are provided within the SharedCredentialsFiles and
  98. // SharedConfigFiles, the properties defined in shared credentials file
  99. // take precedence.
  100. SharedCredentialsFiles []string
  101. // CustomCABundle is CA bundle PEM bytes reader
  102. CustomCABundle io.Reader
  103. // DefaultRegion is the fall back region, used if a region was not resolved
  104. // from other sources
  105. DefaultRegion string
  106. // UseEC2IMDSRegion indicates if SDK should retrieve the region
  107. // from the EC2 Metadata service
  108. UseEC2IMDSRegion *UseEC2IMDSRegion
  109. // CredentialsCacheOptions is a function for setting the
  110. // aws.CredentialsCacheOptions
  111. CredentialsCacheOptions func(*aws.CredentialsCacheOptions)
  112. // BearerAuthTokenCacheOptions is a function for setting the smithy-go
  113. // auth/bearer#TokenCacheOptions
  114. BearerAuthTokenCacheOptions func(*smithybearer.TokenCacheOptions)
  115. // SSOTokenProviderOptions is a function for setting the
  116. // credentials/ssocreds.SSOTokenProviderOptions
  117. SSOTokenProviderOptions func(*ssocreds.SSOTokenProviderOptions)
  118. // ProcessCredentialOptions is a function for setting
  119. // the processcreds.Options
  120. ProcessCredentialOptions func(*processcreds.Options)
  121. // EC2RoleCredentialOptions is a function for setting
  122. // the ec2rolecreds.Options
  123. EC2RoleCredentialOptions func(*ec2rolecreds.Options)
  124. // EndpointCredentialOptions is a function for setting
  125. // the endpointcreds.Options
  126. EndpointCredentialOptions func(*endpointcreds.Options)
  127. // WebIdentityRoleCredentialOptions is a function for setting
  128. // the stscreds.WebIdentityRoleOptions
  129. WebIdentityRoleCredentialOptions func(*stscreds.WebIdentityRoleOptions)
  130. // AssumeRoleCredentialOptions is a function for setting the
  131. // stscreds.AssumeRoleOptions
  132. AssumeRoleCredentialOptions func(*stscreds.AssumeRoleOptions)
  133. // SSOProviderOptions is a function for setting
  134. // the ssocreds.Options
  135. SSOProviderOptions func(options *ssocreds.Options)
  136. // LogConfigurationWarnings when set to true, enables logging
  137. // configuration warnings
  138. LogConfigurationWarnings *bool
  139. // S3UseARNRegion specifies if the S3 service should allow ARNs to direct
  140. // the region, the client's requests are sent to.
  141. S3UseARNRegion *bool
  142. // S3DisableMultiRegionAccessPoints specifies if the S3 service should disable
  143. // the S3 Multi-Region access points feature.
  144. S3DisableMultiRegionAccessPoints *bool
  145. // EnableEndpointDiscovery specifies if endpoint discovery is enable for
  146. // the client.
  147. EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
  148. // Specifies if the EC2 IMDS service client is enabled.
  149. //
  150. // AWS_EC2_METADATA_DISABLED=true
  151. EC2IMDSClientEnableState imds.ClientEnableState
  152. // Specifies the EC2 Instance Metadata Service default endpoint selection
  153. // mode (IPv4 or IPv6)
  154. EC2IMDSEndpointMode imds.EndpointModeState
  155. // Specifies the EC2 Instance Metadata Service endpoint to use. If
  156. // specified it overrides EC2IMDSEndpointMode.
  157. EC2IMDSEndpoint string
  158. // Specifies that SDK clients must resolve a dual-stack endpoint for
  159. // services.
  160. UseDualStackEndpoint aws.DualStackEndpointState
  161. // Specifies that SDK clients must resolve a FIPS endpoint for
  162. // services.
  163. UseFIPSEndpoint aws.FIPSEndpointState
  164. // Specifies the SDK configuration mode for defaults.
  165. DefaultsModeOptions DefaultsModeOptions
  166. // The sdk app ID retrieved from env var or shared config to be added to request user agent header
  167. AppID string
  168. // Specifies whether an operation request could be compressed
  169. DisableRequestCompression *bool
  170. // The inclusive min bytes of a request body that could be compressed
  171. RequestMinCompressSizeBytes *int64
  172. // Whether S3 Express auth is disabled.
  173. S3DisableExpressAuth *bool
  174. // Whether account id should be built into endpoint resolution
  175. AccountIDEndpointMode aws.AccountIDEndpointMode
  176. // Specify if request checksum should be calculated
  177. RequestChecksumCalculation aws.RequestChecksumCalculation
  178. // Specifies if response checksum should be validated
  179. ResponseChecksumValidation aws.ResponseChecksumValidation
  180. // Service endpoint override. This value is not necessarily final and is
  181. // passed to the service's EndpointResolverV2 for further delegation.
  182. BaseEndpoint string
  183. // Registry of operation interceptors.
  184. Interceptors smithyhttp.InterceptorRegistry
  185. // Priority list of preferred auth scheme names (e.g. sigv4a).
  186. AuthSchemePreference []string
  187. // ServiceOptions provides service specific configuration options that will be applied
  188. // when constructing clients for specific services. Each callback function receives the service ID
  189. // and the service's Options struct, allowing for dynamic configuration based on the service.
  190. ServiceOptions []func(string, any)
  191. }
  192. func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
  193. if len(o.DefaultsModeOptions.Mode) == 0 {
  194. return "", false, nil
  195. }
  196. return o.DefaultsModeOptions.Mode, true, nil
  197. }
  198. // GetRetryMaxAttempts returns the RetryMaxAttempts if specified in the
  199. // LoadOptions and not 0.
  200. func (o LoadOptions) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) {
  201. if o.RetryMaxAttempts == 0 {
  202. return 0, false, nil
  203. }
  204. return o.RetryMaxAttempts, true, nil
  205. }
  206. // GetRetryMode returns the RetryMode specified in the LoadOptions.
  207. func (o LoadOptions) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
  208. if len(o.RetryMode) == 0 {
  209. return "", false, nil
  210. }
  211. return o.RetryMode, true, nil
  212. }
  213. func (o LoadOptions) getDefaultsModeIMDSClient(ctx context.Context) (*imds.Client, bool, error) {
  214. if o.DefaultsModeOptions.IMDSClient == nil {
  215. return nil, false, nil
  216. }
  217. return o.DefaultsModeOptions.IMDSClient, true, nil
  218. }
  219. // getRegion returns Region from config's LoadOptions
  220. func (o LoadOptions) getRegion(ctx context.Context) (string, bool, error) {
  221. if len(o.Region) == 0 {
  222. return "", false, nil
  223. }
  224. return o.Region, true, nil
  225. }
  226. // getAppID returns AppID from config's LoadOptions
  227. func (o LoadOptions) getAppID(ctx context.Context) (string, bool, error) {
  228. return o.AppID, len(o.AppID) > 0, nil
  229. }
  230. // getDisableRequestCompression returns DisableRequestCompression from config's LoadOptions
  231. func (o LoadOptions) getDisableRequestCompression(ctx context.Context) (bool, bool, error) {
  232. if o.DisableRequestCompression == nil {
  233. return false, false, nil
  234. }
  235. return *o.DisableRequestCompression, true, nil
  236. }
  237. // getRequestMinCompressSizeBytes returns RequestMinCompressSizeBytes from config's LoadOptions
  238. func (o LoadOptions) getRequestMinCompressSizeBytes(ctx context.Context) (int64, bool, error) {
  239. if o.RequestMinCompressSizeBytes == nil {
  240. return 0, false, nil
  241. }
  242. return *o.RequestMinCompressSizeBytes, true, nil
  243. }
  244. func (o LoadOptions) getAccountIDEndpointMode(ctx context.Context) (aws.AccountIDEndpointMode, bool, error) {
  245. return o.AccountIDEndpointMode, len(o.AccountIDEndpointMode) > 0, nil
  246. }
  247. func (o LoadOptions) getRequestChecksumCalculation(ctx context.Context) (aws.RequestChecksumCalculation, bool, error) {
  248. return o.RequestChecksumCalculation, o.RequestChecksumCalculation > 0, nil
  249. }
  250. func (o LoadOptions) getResponseChecksumValidation(ctx context.Context) (aws.ResponseChecksumValidation, bool, error) {
  251. return o.ResponseChecksumValidation, o.ResponseChecksumValidation > 0, nil
  252. }
  253. func (o LoadOptions) getBaseEndpoint(context.Context) (string, bool, error) {
  254. return o.BaseEndpoint, o.BaseEndpoint != "", nil
  255. }
  256. func (o LoadOptions) getServiceOptions(context.Context) ([]func(string, any), bool, error) {
  257. return o.ServiceOptions, len(o.ServiceOptions) > 0, nil
  258. }
  259. // GetServiceBaseEndpoint satisfies (internal/configsources).ServiceBaseEndpointProvider.
  260. //
  261. // The sdkID value is unused because LoadOptions only supports setting a GLOBAL
  262. // endpoint override. In-code, per-service endpoint overrides are performed via
  263. // functional options in service client space.
  264. func (o LoadOptions) GetServiceBaseEndpoint(context.Context, string) (string, bool, error) {
  265. return o.BaseEndpoint, o.BaseEndpoint != "", nil
  266. }
  267. // WithRegion is a helper function to construct functional options
  268. // that sets Region on config's LoadOptions. Setting the region to
  269. // an empty string, will result in the region value being ignored.
  270. // If multiple WithRegion calls are made, the last call overrides
  271. // the previous call values.
  272. func WithRegion(v string) LoadOptionsFunc {
  273. return func(o *LoadOptions) error {
  274. o.Region = v
  275. return nil
  276. }
  277. }
  278. // WithAppID is a helper function to construct functional options
  279. // that sets AppID on config's LoadOptions.
  280. func WithAppID(ID string) LoadOptionsFunc {
  281. return func(o *LoadOptions) error {
  282. o.AppID = ID
  283. return nil
  284. }
  285. }
  286. // WithDisableRequestCompression is a helper function to construct functional options
  287. // that sets DisableRequestCompression on config's LoadOptions.
  288. func WithDisableRequestCompression(DisableRequestCompression *bool) LoadOptionsFunc {
  289. return func(o *LoadOptions) error {
  290. if DisableRequestCompression == nil {
  291. return nil
  292. }
  293. o.DisableRequestCompression = DisableRequestCompression
  294. return nil
  295. }
  296. }
  297. // WithRequestMinCompressSizeBytes is a helper function to construct functional options
  298. // that sets RequestMinCompressSizeBytes on config's LoadOptions.
  299. func WithRequestMinCompressSizeBytes(RequestMinCompressSizeBytes *int64) LoadOptionsFunc {
  300. return func(o *LoadOptions) error {
  301. if RequestMinCompressSizeBytes == nil {
  302. return nil
  303. }
  304. o.RequestMinCompressSizeBytes = RequestMinCompressSizeBytes
  305. return nil
  306. }
  307. }
  308. // WithAccountIDEndpointMode is a helper function to construct functional options
  309. // that sets AccountIDEndpointMode on config's LoadOptions
  310. func WithAccountIDEndpointMode(m aws.AccountIDEndpointMode) LoadOptionsFunc {
  311. return func(o *LoadOptions) error {
  312. if m != "" {
  313. o.AccountIDEndpointMode = m
  314. }
  315. return nil
  316. }
  317. }
  318. // WithRequestChecksumCalculation is a helper function to construct functional options
  319. // that sets RequestChecksumCalculation on config's LoadOptions
  320. func WithRequestChecksumCalculation(c aws.RequestChecksumCalculation) LoadOptionsFunc {
  321. return func(o *LoadOptions) error {
  322. if c > 0 {
  323. o.RequestChecksumCalculation = c
  324. }
  325. return nil
  326. }
  327. }
  328. // WithResponseChecksumValidation is a helper function to construct functional options
  329. // that sets ResponseChecksumValidation on config's LoadOptions
  330. func WithResponseChecksumValidation(v aws.ResponseChecksumValidation) LoadOptionsFunc {
  331. return func(o *LoadOptions) error {
  332. o.ResponseChecksumValidation = v
  333. return nil
  334. }
  335. }
  336. // getDefaultRegion returns DefaultRegion from config's LoadOptions
  337. func (o LoadOptions) getDefaultRegion(ctx context.Context) (string, bool, error) {
  338. if len(o.DefaultRegion) == 0 {
  339. return "", false, nil
  340. }
  341. return o.DefaultRegion, true, nil
  342. }
  343. // WithDefaultRegion is a helper function to construct functional options
  344. // that sets a DefaultRegion on config's LoadOptions. Setting the default
  345. // region to an empty string, will result in the default region value
  346. // being ignored. If multiple WithDefaultRegion calls are made, the last
  347. // call overrides the previous call values. Note that both WithRegion and
  348. // WithEC2IMDSRegion call takes precedence over WithDefaultRegion call
  349. // when resolving region.
  350. func WithDefaultRegion(v string) LoadOptionsFunc {
  351. return func(o *LoadOptions) error {
  352. o.DefaultRegion = v
  353. return nil
  354. }
  355. }
  356. // getSharedConfigProfile returns SharedConfigProfile from config's LoadOptions
  357. func (o LoadOptions) getSharedConfigProfile(ctx context.Context) (string, bool, error) {
  358. if len(o.SharedConfigProfile) == 0 {
  359. return "", false, nil
  360. }
  361. return o.SharedConfigProfile, true, nil
  362. }
  363. // WithSharedConfigProfile is a helper function to construct functional options
  364. // that sets SharedConfigProfile on config's LoadOptions. Setting the shared
  365. // config profile to an empty string, will result in the shared config profile
  366. // value being ignored.
  367. // If multiple WithSharedConfigProfile calls are made, the last call overrides
  368. // the previous call values.
  369. func WithSharedConfigProfile(v string) LoadOptionsFunc {
  370. return func(o *LoadOptions) error {
  371. o.SharedConfigProfile = v
  372. return nil
  373. }
  374. }
  375. // getSharedConfigFiles returns SharedConfigFiles set on config's LoadOptions
  376. func (o LoadOptions) getSharedConfigFiles(ctx context.Context) ([]string, bool, error) {
  377. if o.SharedConfigFiles == nil {
  378. return nil, false, nil
  379. }
  380. return o.SharedConfigFiles, true, nil
  381. }
  382. // WithSharedConfigFiles is a helper function to construct functional options
  383. // that sets slice of SharedConfigFiles on config's LoadOptions.
  384. // Setting the shared config files to an nil string slice, will result in the
  385. // shared config files value being ignored.
  386. // If multiple WithSharedConfigFiles calls are made, the last call overrides
  387. // the previous call values.
  388. func WithSharedConfigFiles(v []string) LoadOptionsFunc {
  389. return func(o *LoadOptions) error {
  390. o.SharedConfigFiles = v
  391. return nil
  392. }
  393. }
  394. // getSharedCredentialsFiles returns SharedCredentialsFiles set on config's LoadOptions
  395. func (o LoadOptions) getSharedCredentialsFiles(ctx context.Context) ([]string, bool, error) {
  396. if o.SharedCredentialsFiles == nil {
  397. return nil, false, nil
  398. }
  399. return o.SharedCredentialsFiles, true, nil
  400. }
  401. // WithSharedCredentialsFiles is a helper function to construct functional options
  402. // that sets slice of SharedCredentialsFiles on config's LoadOptions.
  403. // Setting the shared credentials files to an nil string slice, will result in the
  404. // shared credentials files value being ignored.
  405. // If multiple WithSharedCredentialsFiles calls are made, the last call overrides
  406. // the previous call values.
  407. func WithSharedCredentialsFiles(v []string) LoadOptionsFunc {
  408. return func(o *LoadOptions) error {
  409. o.SharedCredentialsFiles = v
  410. return nil
  411. }
  412. }
  413. // getCustomCABundle returns CustomCABundle from LoadOptions
  414. func (o LoadOptions) getCustomCABundle(ctx context.Context) (io.Reader, bool, error) {
  415. if o.CustomCABundle == nil {
  416. return nil, false, nil
  417. }
  418. return o.CustomCABundle, true, nil
  419. }
  420. // WithCustomCABundle is a helper function to construct functional options
  421. // that sets CustomCABundle on config's LoadOptions. Setting the custom CA Bundle
  422. // to nil will result in custom CA Bundle value being ignored.
  423. // If multiple WithCustomCABundle calls are made, the last call overrides the
  424. // previous call values.
  425. func WithCustomCABundle(v io.Reader) LoadOptionsFunc {
  426. return func(o *LoadOptions) error {
  427. o.CustomCABundle = v
  428. return nil
  429. }
  430. }
  431. // UseEC2IMDSRegion provides a regionProvider that retrieves the region
  432. // from the EC2 Metadata service.
  433. type UseEC2IMDSRegion struct {
  434. // If unset will default to generic EC2 IMDS client.
  435. Client *imds.Client
  436. }
  437. // getRegion attempts to retrieve the region from EC2 Metadata service.
  438. func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error) {
  439. if ctx == nil {
  440. ctx = context.Background()
  441. }
  442. client := p.Client
  443. if client == nil {
  444. client = imds.New(imds.Options{})
  445. }
  446. result, err := client.GetRegion(ctx, nil)
  447. if err != nil {
  448. return "", false, err
  449. }
  450. if len(result.Region) != 0 {
  451. return result.Region, true, nil
  452. }
  453. return "", false, nil
  454. }
  455. // getEC2IMDSRegion returns the value of EC2 IMDS region.
  456. func (o LoadOptions) getEC2IMDSRegion(ctx context.Context) (string, bool, error) {
  457. if o.UseEC2IMDSRegion == nil {
  458. return "", false, nil
  459. }
  460. return o.UseEC2IMDSRegion.getRegion(ctx)
  461. }
  462. // WithEC2IMDSRegion is a helper function to construct functional options
  463. // that enables resolving EC2IMDS region. The function takes
  464. // in a UseEC2IMDSRegion functional option, and can be used to set the
  465. // EC2IMDS client which will be used to resolve EC2IMDSRegion.
  466. // If no functional option is provided, an EC2IMDS client is built and used
  467. // by the resolver. If multiple WithEC2IMDSRegion calls are made, the last
  468. // call overrides the previous call values. Note that the WithRegion calls takes
  469. // precedence over WithEC2IMDSRegion when resolving region.
  470. func WithEC2IMDSRegion(fnOpts ...func(o *UseEC2IMDSRegion)) LoadOptionsFunc {
  471. return func(o *LoadOptions) error {
  472. o.UseEC2IMDSRegion = &UseEC2IMDSRegion{}
  473. for _, fn := range fnOpts {
  474. fn(o.UseEC2IMDSRegion)
  475. }
  476. return nil
  477. }
  478. }
  479. // getCredentialsProvider returns the credentials value
  480. func (o LoadOptions) getCredentialsProvider(ctx context.Context) (aws.CredentialsProvider, bool, error) {
  481. if o.Credentials == nil {
  482. return nil, false, nil
  483. }
  484. return o.Credentials, true, nil
  485. }
  486. // WithCredentialsProvider is a helper function to construct functional options
  487. // that sets Credential provider value on config's LoadOptions. If credentials
  488. // provider is set to nil, the credentials provider value will be ignored.
  489. // If multiple WithCredentialsProvider calls are made, the last call overrides
  490. // the previous call values.
  491. func WithCredentialsProvider(v aws.CredentialsProvider) LoadOptionsFunc {
  492. return func(o *LoadOptions) error {
  493. o.Credentials = v
  494. return nil
  495. }
  496. }
  497. // getCredentialsCacheOptionsProvider returns the wrapped function to set aws.CredentialsCacheOptions
  498. func (o LoadOptions) getCredentialsCacheOptions(ctx context.Context) (func(*aws.CredentialsCacheOptions), bool, error) {
  499. if o.CredentialsCacheOptions == nil {
  500. return nil, false, nil
  501. }
  502. return o.CredentialsCacheOptions, true, nil
  503. }
  504. // WithCredentialsCacheOptions is a helper function to construct functional
  505. // options that sets a function to modify the aws.CredentialsCacheOptions the
  506. // aws.CredentialsCache will be configured with, if the CredentialsCache is used
  507. // by the configuration loader.
  508. //
  509. // If multiple WithCredentialsCacheOptions calls are made, the last call
  510. // overrides the previous call values.
  511. func WithCredentialsCacheOptions(v func(*aws.CredentialsCacheOptions)) LoadOptionsFunc {
  512. return func(o *LoadOptions) error {
  513. o.CredentialsCacheOptions = v
  514. return nil
  515. }
  516. }
  517. // getBearerAuthTokenProvider returns the credentials value
  518. func (o LoadOptions) getBearerAuthTokenProvider(ctx context.Context) (smithybearer.TokenProvider, bool, error) {
  519. if o.BearerAuthTokenProvider == nil {
  520. return nil, false, nil
  521. }
  522. return o.BearerAuthTokenProvider, true, nil
  523. }
  524. // WithBearerAuthTokenProvider is a helper function to construct functional options
  525. // that sets Credential provider value on config's LoadOptions. If credentials
  526. // provider is set to nil, the credentials provider value will be ignored.
  527. // If multiple WithBearerAuthTokenProvider calls are made, the last call overrides
  528. // the previous call values.
  529. func WithBearerAuthTokenProvider(v smithybearer.TokenProvider) LoadOptionsFunc {
  530. return func(o *LoadOptions) error {
  531. o.BearerAuthTokenProvider = v
  532. return nil
  533. }
  534. }
  535. // getBearerAuthTokenCacheOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
  536. func (o LoadOptions) getBearerAuthTokenCacheOptions(ctx context.Context) (func(*smithybearer.TokenCacheOptions), bool, error) {
  537. if o.BearerAuthTokenCacheOptions == nil {
  538. return nil, false, nil
  539. }
  540. return o.BearerAuthTokenCacheOptions, true, nil
  541. }
  542. // WithBearerAuthTokenCacheOptions is a helper function to construct functional options
  543. // that sets a function to modify the TokenCacheOptions the smithy-go
  544. // auth/bearer#TokenCache will be configured with, if the TokenCache is used by
  545. // the configuration loader.
  546. //
  547. // If multiple WithBearerAuthTokenCacheOptions calls are made, the last call overrides
  548. // the previous call values.
  549. func WithBearerAuthTokenCacheOptions(v func(*smithybearer.TokenCacheOptions)) LoadOptionsFunc {
  550. return func(o *LoadOptions) error {
  551. o.BearerAuthTokenCacheOptions = v
  552. return nil
  553. }
  554. }
  555. // getSSOTokenProviderOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
  556. func (o LoadOptions) getSSOTokenProviderOptions(ctx context.Context) (func(*ssocreds.SSOTokenProviderOptions), bool, error) {
  557. if o.SSOTokenProviderOptions == nil {
  558. return nil, false, nil
  559. }
  560. return o.SSOTokenProviderOptions, true, nil
  561. }
  562. // WithSSOTokenProviderOptions is a helper function to construct functional
  563. // options that sets a function to modify the SSOtokenProviderOptions the SDK's
  564. // credentials/ssocreds#SSOProvider will be configured with, if the
  565. // SSOTokenProvider is used by the configuration loader.
  566. //
  567. // If multiple WithSSOTokenProviderOptions calls are made, the last call overrides
  568. // the previous call values.
  569. func WithSSOTokenProviderOptions(v func(*ssocreds.SSOTokenProviderOptions)) LoadOptionsFunc {
  570. return func(o *LoadOptions) error {
  571. o.SSOTokenProviderOptions = v
  572. return nil
  573. }
  574. }
  575. // getProcessCredentialOptions returns the wrapped function to set processcreds.Options
  576. func (o LoadOptions) getProcessCredentialOptions(ctx context.Context) (func(*processcreds.Options), bool, error) {
  577. if o.ProcessCredentialOptions == nil {
  578. return nil, false, nil
  579. }
  580. return o.ProcessCredentialOptions, true, nil
  581. }
  582. // WithProcessCredentialOptions is a helper function to construct functional options
  583. // that sets a function to use processcreds.Options on config's LoadOptions.
  584. // If process credential options is set to nil, the process credential value will
  585. // be ignored. If multiple WithProcessCredentialOptions calls are made, the last call
  586. // overrides the previous call values.
  587. func WithProcessCredentialOptions(v func(*processcreds.Options)) LoadOptionsFunc {
  588. return func(o *LoadOptions) error {
  589. o.ProcessCredentialOptions = v
  590. return nil
  591. }
  592. }
  593. // getEC2RoleCredentialOptions returns the wrapped function to set the ec2rolecreds.Options
  594. func (o LoadOptions) getEC2RoleCredentialOptions(ctx context.Context) (func(*ec2rolecreds.Options), bool, error) {
  595. if o.EC2RoleCredentialOptions == nil {
  596. return nil, false, nil
  597. }
  598. return o.EC2RoleCredentialOptions, true, nil
  599. }
  600. // WithEC2RoleCredentialOptions is a helper function to construct functional options
  601. // that sets a function to use ec2rolecreds.Options on config's LoadOptions. If
  602. // EC2 role credential options is set to nil, the EC2 role credential options value
  603. // will be ignored. If multiple WithEC2RoleCredentialOptions calls are made,
  604. // the last call overrides the previous call values.
  605. func WithEC2RoleCredentialOptions(v func(*ec2rolecreds.Options)) LoadOptionsFunc {
  606. return func(o *LoadOptions) error {
  607. o.EC2RoleCredentialOptions = v
  608. return nil
  609. }
  610. }
  611. // getEndpointCredentialOptions returns the wrapped function to set endpointcreds.Options
  612. func (o LoadOptions) getEndpointCredentialOptions(context.Context) (func(*endpointcreds.Options), bool, error) {
  613. if o.EndpointCredentialOptions == nil {
  614. return nil, false, nil
  615. }
  616. return o.EndpointCredentialOptions, true, nil
  617. }
  618. // WithEndpointCredentialOptions is a helper function to construct functional options
  619. // that sets a function to use endpointcreds.Options on config's LoadOptions. If
  620. // endpoint credential options is set to nil, the endpoint credential options
  621. // value will be ignored. If multiple WithEndpointCredentialOptions calls are made,
  622. // the last call overrides the previous call values.
  623. func WithEndpointCredentialOptions(v func(*endpointcreds.Options)) LoadOptionsFunc {
  624. return func(o *LoadOptions) error {
  625. o.EndpointCredentialOptions = v
  626. return nil
  627. }
  628. }
  629. // getWebIdentityRoleCredentialOptions returns the wrapped function
  630. func (o LoadOptions) getWebIdentityRoleCredentialOptions(context.Context) (func(*stscreds.WebIdentityRoleOptions), bool, error) {
  631. if o.WebIdentityRoleCredentialOptions == nil {
  632. return nil, false, nil
  633. }
  634. return o.WebIdentityRoleCredentialOptions, true, nil
  635. }
  636. // WithWebIdentityRoleCredentialOptions is a helper function to construct
  637. // functional options that sets a function to use stscreds.WebIdentityRoleOptions
  638. // on config's LoadOptions. If web identity role credentials options is set to nil,
  639. // the web identity role credentials value will be ignored. If multiple
  640. // WithWebIdentityRoleCredentialOptions calls are made, the last call
  641. // overrides the previous call values.
  642. func WithWebIdentityRoleCredentialOptions(v func(*stscreds.WebIdentityRoleOptions)) LoadOptionsFunc {
  643. return func(o *LoadOptions) error {
  644. o.WebIdentityRoleCredentialOptions = v
  645. return nil
  646. }
  647. }
  648. // getAssumeRoleCredentialOptions returns AssumeRoleCredentialOptions from LoadOptions
  649. func (o LoadOptions) getAssumeRoleCredentialOptions(context.Context) (func(options *stscreds.AssumeRoleOptions), bool, error) {
  650. if o.AssumeRoleCredentialOptions == nil {
  651. return nil, false, nil
  652. }
  653. return o.AssumeRoleCredentialOptions, true, nil
  654. }
  655. // WithAssumeRoleCredentialOptions is a helper function to construct
  656. // functional options that sets a function to use stscreds.AssumeRoleOptions
  657. // on config's LoadOptions. If assume role credentials options is set to nil,
  658. // the assume role credentials value will be ignored. If multiple
  659. // WithAssumeRoleCredentialOptions calls are made, the last call overrides
  660. // the previous call values.
  661. func WithAssumeRoleCredentialOptions(v func(*stscreds.AssumeRoleOptions)) LoadOptionsFunc {
  662. return func(o *LoadOptions) error {
  663. o.AssumeRoleCredentialOptions = v
  664. return nil
  665. }
  666. }
  667. func (o LoadOptions) getHTTPClient(ctx context.Context) (HTTPClient, bool, error) {
  668. if o.HTTPClient == nil {
  669. return nil, false, nil
  670. }
  671. return o.HTTPClient, true, nil
  672. }
  673. // WithHTTPClient is a helper function to construct functional options
  674. // that sets HTTPClient on LoadOptions. If HTTPClient is set to nil,
  675. // the HTTPClient value will be ignored.
  676. // If multiple WithHTTPClient calls are made, the last call overrides
  677. // the previous call values.
  678. func WithHTTPClient(v HTTPClient) LoadOptionsFunc {
  679. return func(o *LoadOptions) error {
  680. o.HTTPClient = v
  681. return nil
  682. }
  683. }
  684. func (o LoadOptions) getAPIOptions(ctx context.Context) ([]func(*middleware.Stack) error, bool, error) {
  685. if o.APIOptions == nil {
  686. return nil, false, nil
  687. }
  688. return o.APIOptions, true, nil
  689. }
  690. // WithAPIOptions is a helper function to construct functional options
  691. // that sets APIOptions on LoadOptions. If APIOptions is set to nil, the
  692. // APIOptions value is ignored. If multiple WithAPIOptions calls are
  693. // made, the last call overrides the previous call values.
  694. func WithAPIOptions(v []func(*middleware.Stack) error) LoadOptionsFunc {
  695. return func(o *LoadOptions) error {
  696. if v == nil {
  697. return nil
  698. }
  699. o.APIOptions = append(o.APIOptions, v...)
  700. return nil
  701. }
  702. }
  703. func (o LoadOptions) getRetryMaxAttempts(ctx context.Context) (int, bool, error) {
  704. if o.RetryMaxAttempts == 0 {
  705. return 0, false, nil
  706. }
  707. return o.RetryMaxAttempts, true, nil
  708. }
  709. // WithRetryMaxAttempts is a helper function to construct functional options that sets
  710. // RetryMaxAttempts on LoadOptions. If RetryMaxAttempts is unset, the RetryMaxAttempts value is
  711. // ignored. If multiple WithRetryMaxAttempts calls are made, the last call overrides
  712. // the previous call values.
  713. //
  714. // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
  715. func WithRetryMaxAttempts(v int) LoadOptionsFunc {
  716. return func(o *LoadOptions) error {
  717. o.RetryMaxAttempts = v
  718. return nil
  719. }
  720. }
  721. func (o LoadOptions) getRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
  722. if o.RetryMode == "" {
  723. return "", false, nil
  724. }
  725. return o.RetryMode, true, nil
  726. }
  727. // WithRetryMode is a helper function to construct functional options that sets
  728. // RetryMode on LoadOptions. If RetryMode is unset, the RetryMode value is
  729. // ignored. If multiple WithRetryMode calls are made, the last call overrides
  730. // the previous call values.
  731. //
  732. // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
  733. func WithRetryMode(v aws.RetryMode) LoadOptionsFunc {
  734. return func(o *LoadOptions) error {
  735. o.RetryMode = v
  736. return nil
  737. }
  738. }
  739. func (o LoadOptions) getRetryer(ctx context.Context) (func() aws.Retryer, bool, error) {
  740. if o.Retryer == nil {
  741. return nil, false, nil
  742. }
  743. return o.Retryer, true, nil
  744. }
  745. // WithRetryer is a helper function to construct functional options
  746. // that sets Retryer on LoadOptions. If Retryer is set to nil, the
  747. // Retryer value is ignored. If multiple WithRetryer calls are
  748. // made, the last call overrides the previous call values.
  749. func WithRetryer(v func() aws.Retryer) LoadOptionsFunc {
  750. return func(o *LoadOptions) error {
  751. o.Retryer = v
  752. return nil
  753. }
  754. }
  755. func (o LoadOptions) getEndpointResolver(ctx context.Context) (aws.EndpointResolver, bool, error) {
  756. if o.EndpointResolver == nil {
  757. return nil, false, nil
  758. }
  759. return o.EndpointResolver, true, nil
  760. }
  761. // WithEndpointResolver is a helper function to construct functional options
  762. // that sets the EndpointResolver on LoadOptions. If the EndpointResolver is set to nil,
  763. // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
  764. // are made, the last call overrides the previous call values.
  765. //
  766. // Deprecated: The global endpoint resolution interface is deprecated. The API
  767. // for endpoint resolution is now unique to each service and is set via the
  768. // EndpointResolverV2 field on service client options. Use of
  769. // WithEndpointResolver or WithEndpointResolverWithOptions will prevent you
  770. // from using any endpoint-related service features released after the
  771. // introduction of EndpointResolverV2. You may also encounter broken or
  772. // unexpected behavior when using the old global interface with services that
  773. // use many endpoint-related customizations such as S3.
  774. func WithEndpointResolver(v aws.EndpointResolver) LoadOptionsFunc {
  775. return func(o *LoadOptions) error {
  776. o.EndpointResolver = v
  777. return nil
  778. }
  779. }
  780. func (o LoadOptions) getEndpointResolverWithOptions(ctx context.Context) (aws.EndpointResolverWithOptions, bool, error) {
  781. if o.EndpointResolverWithOptions == nil {
  782. return nil, false, nil
  783. }
  784. return o.EndpointResolverWithOptions, true, nil
  785. }
  786. // WithEndpointResolverWithOptions is a helper function to construct functional options
  787. // that sets the EndpointResolverWithOptions on LoadOptions. If the EndpointResolverWithOptions is set to nil,
  788. // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
  789. // are made, the last call overrides the previous call values.
  790. //
  791. // Deprecated: The global endpoint resolution interface is deprecated. See
  792. // deprecation docs on [WithEndpointResolver].
  793. func WithEndpointResolverWithOptions(v aws.EndpointResolverWithOptions) LoadOptionsFunc {
  794. return func(o *LoadOptions) error {
  795. o.EndpointResolverWithOptions = v
  796. return nil
  797. }
  798. }
  799. func (o LoadOptions) getLogger(ctx context.Context) (logging.Logger, bool, error) {
  800. if o.Logger == nil {
  801. return nil, false, nil
  802. }
  803. return o.Logger, true, nil
  804. }
  805. // WithLogger is a helper function to construct functional options
  806. // that sets Logger on LoadOptions. If Logger is set to nil, the
  807. // Logger value will be ignored. If multiple WithLogger calls are made,
  808. // the last call overrides the previous call values.
  809. func WithLogger(v logging.Logger) LoadOptionsFunc {
  810. return func(o *LoadOptions) error {
  811. o.Logger = v
  812. return nil
  813. }
  814. }
  815. func (o LoadOptions) getClientLogMode(ctx context.Context) (aws.ClientLogMode, bool, error) {
  816. if o.ClientLogMode == nil {
  817. return 0, false, nil
  818. }
  819. return *o.ClientLogMode, true, nil
  820. }
  821. // WithClientLogMode is a helper function to construct functional options
  822. // that sets client log mode on LoadOptions. If client log mode is set to nil,
  823. // the client log mode value will be ignored. If multiple WithClientLogMode calls are made,
  824. // the last call overrides the previous call values.
  825. func WithClientLogMode(v aws.ClientLogMode) LoadOptionsFunc {
  826. return func(o *LoadOptions) error {
  827. o.ClientLogMode = &v
  828. return nil
  829. }
  830. }
  831. func (o LoadOptions) getLogConfigurationWarnings(ctx context.Context) (v bool, found bool, err error) {
  832. if o.LogConfigurationWarnings == nil {
  833. return false, false, nil
  834. }
  835. return *o.LogConfigurationWarnings, true, nil
  836. }
  837. // WithLogConfigurationWarnings is a helper function to construct
  838. // functional options that can be used to set LogConfigurationWarnings
  839. // on LoadOptions.
  840. //
  841. // If multiple WithLogConfigurationWarnings calls are made, the last call
  842. // overrides the previous call values.
  843. func WithLogConfigurationWarnings(v bool) LoadOptionsFunc {
  844. return func(o *LoadOptions) error {
  845. o.LogConfigurationWarnings = &v
  846. return nil
  847. }
  848. }
  849. // GetS3UseARNRegion returns whether to allow ARNs to direct the region
  850. // the S3 client's requests are sent to.
  851. func (o LoadOptions) GetS3UseARNRegion(ctx context.Context) (v bool, found bool, err error) {
  852. if o.S3UseARNRegion == nil {
  853. return false, false, nil
  854. }
  855. return *o.S3UseARNRegion, true, nil
  856. }
  857. // WithS3UseARNRegion is a helper function to construct functional options
  858. // that can be used to set S3UseARNRegion on LoadOptions.
  859. // If multiple WithS3UseARNRegion calls are made, the last call overrides
  860. // the previous call values.
  861. func WithS3UseARNRegion(v bool) LoadOptionsFunc {
  862. return func(o *LoadOptions) error {
  863. o.S3UseARNRegion = &v
  864. return nil
  865. }
  866. }
  867. // GetS3DisableMultiRegionAccessPoints returns whether to disable
  868. // the S3 multi-region access points feature.
  869. func (o LoadOptions) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (v bool, found bool, err error) {
  870. if o.S3DisableMultiRegionAccessPoints == nil {
  871. return false, false, nil
  872. }
  873. return *o.S3DisableMultiRegionAccessPoints, true, nil
  874. }
  875. // WithS3DisableMultiRegionAccessPoints is a helper function to construct functional options
  876. // that can be used to set S3DisableMultiRegionAccessPoints on LoadOptions.
  877. // If multiple WithS3DisableMultiRegionAccessPoints calls are made, the last call overrides
  878. // the previous call values.
  879. func WithS3DisableMultiRegionAccessPoints(v bool) LoadOptionsFunc {
  880. return func(o *LoadOptions) error {
  881. o.S3DisableMultiRegionAccessPoints = &v
  882. return nil
  883. }
  884. }
  885. // GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
  886. func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
  887. if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {
  888. return aws.EndpointDiscoveryUnset, false, nil
  889. }
  890. return o.EnableEndpointDiscovery, true, nil
  891. }
  892. // WithEndpointDiscovery is a helper function to construct functional options
  893. // that can be used to enable endpoint discovery on LoadOptions for supported clients.
  894. // If multiple WithEndpointDiscovery calls are made, the last call overrides
  895. // the previous call values.
  896. func WithEndpointDiscovery(v aws.EndpointDiscoveryEnableState) LoadOptionsFunc {
  897. return func(o *LoadOptions) error {
  898. o.EnableEndpointDiscovery = v
  899. return nil
  900. }
  901. }
  902. // getSSOProviderOptions returns AssumeRoleCredentialOptions from LoadOptions
  903. func (o LoadOptions) getSSOProviderOptions(context.Context) (func(options *ssocreds.Options), bool, error) {
  904. if o.SSOProviderOptions == nil {
  905. return nil, false, nil
  906. }
  907. return o.SSOProviderOptions, true, nil
  908. }
  909. // WithSSOProviderOptions is a helper function to construct
  910. // functional options that sets a function to use ssocreds.Options
  911. // on config's LoadOptions. If the SSO credential provider options is set to nil,
  912. // the sso provider options value will be ignored. If multiple
  913. // WithSSOProviderOptions calls are made, the last call overrides
  914. // the previous call values.
  915. func WithSSOProviderOptions(v func(*ssocreds.Options)) LoadOptionsFunc {
  916. return func(o *LoadOptions) error {
  917. o.SSOProviderOptions = v
  918. return nil
  919. }
  920. }
  921. // GetEC2IMDSClientEnableState implements a EC2IMDSClientEnableState options resolver interface.
  922. func (o LoadOptions) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error) {
  923. if o.EC2IMDSClientEnableState == imds.ClientDefaultEnableState {
  924. return imds.ClientDefaultEnableState, false, nil
  925. }
  926. return o.EC2IMDSClientEnableState, true, nil
  927. }
  928. // GetEC2IMDSEndpointMode implements a EC2IMDSEndpointMode option resolver interface.
  929. func (o LoadOptions) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error) {
  930. if o.EC2IMDSEndpointMode == imds.EndpointModeStateUnset {
  931. return imds.EndpointModeStateUnset, false, nil
  932. }
  933. return o.EC2IMDSEndpointMode, true, nil
  934. }
  935. // GetEC2IMDSEndpoint implements a EC2IMDSEndpoint option resolver interface.
  936. func (o LoadOptions) GetEC2IMDSEndpoint() (string, bool, error) {
  937. if len(o.EC2IMDSEndpoint) == 0 {
  938. return "", false, nil
  939. }
  940. return o.EC2IMDSEndpoint, true, nil
  941. }
  942. // WithEC2IMDSClientEnableState is a helper function to construct functional options that sets the EC2IMDSClientEnableState.
  943. func WithEC2IMDSClientEnableState(v imds.ClientEnableState) LoadOptionsFunc {
  944. return func(o *LoadOptions) error {
  945. o.EC2IMDSClientEnableState = v
  946. return nil
  947. }
  948. }
  949. // WithEC2IMDSEndpointMode is a helper function to construct functional options that sets the EC2IMDSEndpointMode.
  950. func WithEC2IMDSEndpointMode(v imds.EndpointModeState) LoadOptionsFunc {
  951. return func(o *LoadOptions) error {
  952. o.EC2IMDSEndpointMode = v
  953. return nil
  954. }
  955. }
  956. // WithEC2IMDSEndpoint is a helper function to construct functional options that sets the EC2IMDSEndpoint.
  957. func WithEC2IMDSEndpoint(v string) LoadOptionsFunc {
  958. return func(o *LoadOptions) error {
  959. o.EC2IMDSEndpoint = v
  960. return nil
  961. }
  962. }
  963. // WithUseDualStackEndpoint is a helper function to construct
  964. // functional options that can be used to set UseDualStackEndpoint on LoadOptions.
  965. func WithUseDualStackEndpoint(v aws.DualStackEndpointState) LoadOptionsFunc {
  966. return func(o *LoadOptions) error {
  967. o.UseDualStackEndpoint = v
  968. return nil
  969. }
  970. }
  971. // GetUseDualStackEndpoint returns whether the service's dual-stack endpoint should be
  972. // used for requests.
  973. func (o LoadOptions) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error) {
  974. if o.UseDualStackEndpoint == aws.DualStackEndpointStateUnset {
  975. return aws.DualStackEndpointStateUnset, false, nil
  976. }
  977. return o.UseDualStackEndpoint, true, nil
  978. }
  979. // WithUseFIPSEndpoint is a helper function to construct
  980. // functional options that can be used to set UseFIPSEndpoint on LoadOptions.
  981. func WithUseFIPSEndpoint(v aws.FIPSEndpointState) LoadOptionsFunc {
  982. return func(o *LoadOptions) error {
  983. o.UseFIPSEndpoint = v
  984. return nil
  985. }
  986. }
  987. // GetUseFIPSEndpoint returns whether the service's FIPS endpoint should be
  988. // used for requests.
  989. func (o LoadOptions) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEndpointState, found bool, err error) {
  990. if o.UseFIPSEndpoint == aws.FIPSEndpointStateUnset {
  991. return aws.FIPSEndpointStateUnset, false, nil
  992. }
  993. return o.UseFIPSEndpoint, true, nil
  994. }
  995. // WithDefaultsMode sets the SDK defaults configuration mode to the value provided.
  996. //
  997. // Zero or more functional options can be provided to provide configuration options for performing
  998. // environment discovery when using aws.DefaultsModeAuto.
  999. func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsModeOptions)) LoadOptionsFunc {
  1000. do := DefaultsModeOptions{
  1001. Mode: mode,
  1002. }
  1003. for _, fn := range optFns {
  1004. fn(&do)
  1005. }
  1006. return func(options *LoadOptions) error {
  1007. options.DefaultsModeOptions = do
  1008. return nil
  1009. }
  1010. }
  1011. // GetS3DisableExpressAuth returns the configured value for
  1012. // [EnvConfig.S3DisableExpressAuth].
  1013. func (o LoadOptions) GetS3DisableExpressAuth() (value, ok bool) {
  1014. if o.S3DisableExpressAuth == nil {
  1015. return false, false
  1016. }
  1017. return *o.S3DisableExpressAuth, true
  1018. }
  1019. // WithS3DisableExpressAuth sets [LoadOptions.S3DisableExpressAuth]
  1020. // to the value provided.
  1021. func WithS3DisableExpressAuth(v bool) LoadOptionsFunc {
  1022. return func(o *LoadOptions) error {
  1023. o.S3DisableExpressAuth = &v
  1024. return nil
  1025. }
  1026. }
  1027. // WithBaseEndpoint is a helper function to construct functional options that
  1028. // sets BaseEndpoint on config's LoadOptions. Empty values have no effect, and
  1029. // subsequent calls to this API override previous ones.
  1030. //
  1031. // This is an in-code setting, therefore, any value set using this hook takes
  1032. // precedence over and will override ALL environment and shared config
  1033. // directives that set endpoint URLs. Functional options on service clients
  1034. // have higher specificity, and functional options that modify the value of
  1035. // BaseEndpoint on a client will take precedence over this setting.
  1036. func WithBaseEndpoint(v string) LoadOptionsFunc {
  1037. return func(o *LoadOptions) error {
  1038. o.BaseEndpoint = v
  1039. return nil
  1040. }
  1041. }
  1042. // WithServiceOptions is a helper function to construct functional options
  1043. // that sets ServiceOptions on config's LoadOptions.
  1044. func WithServiceOptions(callbacks ...func(string, any)) LoadOptionsFunc {
  1045. return func(o *LoadOptions) error {
  1046. o.ServiceOptions = append(o.ServiceOptions, callbacks...)
  1047. return nil
  1048. }
  1049. }
  1050. // WithBeforeExecution adds the BeforeExecutionInterceptor to config.
  1051. func WithBeforeExecution(i smithyhttp.BeforeExecutionInterceptor) LoadOptionsFunc {
  1052. return func(o *LoadOptions) error {
  1053. o.Interceptors.BeforeExecution = append(o.Interceptors.BeforeExecution, i)
  1054. return nil
  1055. }
  1056. }
  1057. // WithBeforeSerialization adds the BeforeSerializationInterceptor to config.
  1058. func WithBeforeSerialization(i smithyhttp.BeforeSerializationInterceptor) LoadOptionsFunc {
  1059. return func(o *LoadOptions) error {
  1060. o.Interceptors.BeforeSerialization = append(o.Interceptors.BeforeSerialization, i)
  1061. return nil
  1062. }
  1063. }
  1064. // WithAfterSerialization adds the AfterSerializationInterceptor to config.
  1065. func WithAfterSerialization(i smithyhttp.AfterSerializationInterceptor) LoadOptionsFunc {
  1066. return func(o *LoadOptions) error {
  1067. o.Interceptors.AfterSerialization = append(o.Interceptors.AfterSerialization, i)
  1068. return nil
  1069. }
  1070. }
  1071. // WithBeforeRetryLoop adds the BeforeRetryLoopInterceptor to config.
  1072. func WithBeforeRetryLoop(i smithyhttp.BeforeRetryLoopInterceptor) LoadOptionsFunc {
  1073. return func(o *LoadOptions) error {
  1074. o.Interceptors.BeforeRetryLoop = append(o.Interceptors.BeforeRetryLoop, i)
  1075. return nil
  1076. }
  1077. }
  1078. // WithBeforeAttempt adds the BeforeAttemptInterceptor to config.
  1079. func WithBeforeAttempt(i smithyhttp.BeforeAttemptInterceptor) LoadOptionsFunc {
  1080. return func(o *LoadOptions) error {
  1081. o.Interceptors.BeforeAttempt = append(o.Interceptors.BeforeAttempt, i)
  1082. return nil
  1083. }
  1084. }
  1085. // WithBeforeSigning adds the BeforeSigningInterceptor to config.
  1086. func WithBeforeSigning(i smithyhttp.BeforeSigningInterceptor) LoadOptionsFunc {
  1087. return func(o *LoadOptions) error {
  1088. o.Interceptors.BeforeSigning = append(o.Interceptors.BeforeSigning, i)
  1089. return nil
  1090. }
  1091. }
  1092. // WithAfterSigning adds the AfterSigningInterceptor to config.
  1093. func WithAfterSigning(i smithyhttp.AfterSigningInterceptor) LoadOptionsFunc {
  1094. return func(o *LoadOptions) error {
  1095. o.Interceptors.AfterSigning = append(o.Interceptors.AfterSigning, i)
  1096. return nil
  1097. }
  1098. }
  1099. // WithBeforeTransmit adds the BeforeTransmitInterceptor to config.
  1100. func WithBeforeTransmit(i smithyhttp.BeforeTransmitInterceptor) LoadOptionsFunc {
  1101. return func(o *LoadOptions) error {
  1102. o.Interceptors.BeforeTransmit = append(o.Interceptors.BeforeTransmit, i)
  1103. return nil
  1104. }
  1105. }
  1106. // WithAfterTransmit adds the AfterTransmitInterceptor to config.
  1107. func WithAfterTransmit(i smithyhttp.AfterTransmitInterceptor) LoadOptionsFunc {
  1108. return func(o *LoadOptions) error {
  1109. o.Interceptors.AfterTransmit = append(o.Interceptors.AfterTransmit, i)
  1110. return nil
  1111. }
  1112. }
  1113. // WithBeforeDeserialization adds the BeforeDeserializationInterceptor to config.
  1114. func WithBeforeDeserialization(i smithyhttp.BeforeDeserializationInterceptor) LoadOptionsFunc {
  1115. return func(o *LoadOptions) error {
  1116. o.Interceptors.BeforeDeserialization = append(o.Interceptors.BeforeDeserialization, i)
  1117. return nil
  1118. }
  1119. }
  1120. // WithAfterDeserialization adds the AfterDeserializationInterceptor to config.
  1121. func WithAfterDeserialization(i smithyhttp.AfterDeserializationInterceptor) LoadOptionsFunc {
  1122. return func(o *LoadOptions) error {
  1123. o.Interceptors.AfterDeserialization = append(o.Interceptors.AfterDeserialization, i)
  1124. return nil
  1125. }
  1126. }
  1127. // WithAfterAttempt adds the AfterAttemptInterceptor to config.
  1128. func WithAfterAttempt(i smithyhttp.AfterAttemptInterceptor) LoadOptionsFunc {
  1129. return func(o *LoadOptions) error {
  1130. o.Interceptors.AfterAttempt = append(o.Interceptors.AfterAttempt, i)
  1131. return nil
  1132. }
  1133. }
  1134. // WithAfterExecution adds the AfterExecutionInterceptor to config.
  1135. func WithAfterExecution(i smithyhttp.AfterExecutionInterceptor) LoadOptionsFunc {
  1136. return func(o *LoadOptions) error {
  1137. o.Interceptors.AfterExecution = append(o.Interceptors.AfterExecution, i)
  1138. return nil
  1139. }
  1140. }
  1141. // WithAuthSchemePreference sets the priority order of auth schemes on config.
  1142. //
  1143. // Schemes are expressed as names e.g. sigv4a or sigv4.
  1144. func WithAuthSchemePreference(schemeIDs ...string) LoadOptionsFunc {
  1145. return func(o *LoadOptions) error {
  1146. o.AuthSchemePreference = schemeIDs
  1147. return nil
  1148. }
  1149. }
  1150. func (o LoadOptions) getAuthSchemePreference() ([]string, bool) {
  1151. if len(o.AuthSchemePreference) > 0 {
  1152. return o.AuthSchemePreference, true
  1153. }
  1154. return nil, false
  1155. }