provider.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. package config
  2. import (
  3. "context"
  4. "io"
  5. "net/http"
  6. "github.com/aws/aws-sdk-go-v2/aws"
  7. "github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds"
  8. "github.com/aws/aws-sdk-go-v2/credentials/endpointcreds"
  9. "github.com/aws/aws-sdk-go-v2/credentials/processcreds"
  10. "github.com/aws/aws-sdk-go-v2/credentials/ssocreds"
  11. "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
  12. "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
  13. smithybearer "github.com/aws/smithy-go/auth/bearer"
  14. "github.com/aws/smithy-go/logging"
  15. "github.com/aws/smithy-go/middleware"
  16. )
  17. // sharedConfigProfileProvider provides access to the shared config profile
  18. // name external configuration value.
  19. type sharedConfigProfileProvider interface {
  20. getSharedConfigProfile(ctx context.Context) (string, bool, error)
  21. }
  22. // getSharedConfigProfile searches the configs for a sharedConfigProfileProvider
  23. // and returns the value if found. Returns an error if a provider fails before a
  24. // value is found.
  25. func getSharedConfigProfile(ctx context.Context, configs configs) (value string, found bool, err error) {
  26. for _, cfg := range configs {
  27. if p, ok := cfg.(sharedConfigProfileProvider); ok {
  28. value, found, err = p.getSharedConfigProfile(ctx)
  29. if err != nil || found {
  30. break
  31. }
  32. }
  33. }
  34. return
  35. }
  36. // sharedConfigFilesProvider provides access to the shared config filesnames
  37. // external configuration value.
  38. type sharedConfigFilesProvider interface {
  39. getSharedConfigFiles(ctx context.Context) ([]string, bool, error)
  40. }
  41. // getSharedConfigFiles searches the configs for a sharedConfigFilesProvider
  42. // and returns the value if found. Returns an error if a provider fails before a
  43. // value is found.
  44. func getSharedConfigFiles(ctx context.Context, configs configs) (value []string, found bool, err error) {
  45. for _, cfg := range configs {
  46. if p, ok := cfg.(sharedConfigFilesProvider); ok {
  47. value, found, err = p.getSharedConfigFiles(ctx)
  48. if err != nil || found {
  49. break
  50. }
  51. }
  52. }
  53. return
  54. }
  55. // sharedCredentialsFilesProvider provides access to the shared credentials filesnames
  56. // external configuration value.
  57. type sharedCredentialsFilesProvider interface {
  58. getSharedCredentialsFiles(ctx context.Context) ([]string, bool, error)
  59. }
  60. // getSharedCredentialsFiles searches the configs for a sharedCredentialsFilesProvider
  61. // and returns the value if found. Returns an error if a provider fails before a
  62. // value is found.
  63. func getSharedCredentialsFiles(ctx context.Context, configs configs) (value []string, found bool, err error) {
  64. for _, cfg := range configs {
  65. if p, ok := cfg.(sharedCredentialsFilesProvider); ok {
  66. value, found, err = p.getSharedCredentialsFiles(ctx)
  67. if err != nil || found {
  68. break
  69. }
  70. }
  71. }
  72. return
  73. }
  74. // customCABundleProvider provides access to the custom CA bundle PEM bytes.
  75. type customCABundleProvider interface {
  76. getCustomCABundle(ctx context.Context) (io.Reader, bool, error)
  77. }
  78. // getCustomCABundle searches the configs for a customCABundleProvider
  79. // and returns the value if found. Returns an error if a provider fails before a
  80. // value is found.
  81. func getCustomCABundle(ctx context.Context, configs configs) (value io.Reader, found bool, err error) {
  82. for _, cfg := range configs {
  83. if p, ok := cfg.(customCABundleProvider); ok {
  84. value, found, err = p.getCustomCABundle(ctx)
  85. if err != nil || found {
  86. break
  87. }
  88. }
  89. }
  90. return
  91. }
  92. // regionProvider provides access to the region external configuration value.
  93. type regionProvider interface {
  94. getRegion(ctx context.Context) (string, bool, error)
  95. }
  96. // getRegion searches the configs for a regionProvider and returns the value
  97. // if found. Returns an error if a provider fails before a value is found.
  98. func getRegion(ctx context.Context, configs configs) (value string, found bool, err error) {
  99. for _, cfg := range configs {
  100. if p, ok := cfg.(regionProvider); ok {
  101. value, found, err = p.getRegion(ctx)
  102. if err != nil || found {
  103. break
  104. }
  105. }
  106. }
  107. return
  108. }
  109. // IgnoreConfiguredEndpointsProvider is needed to search for all providers
  110. // that provide a flag to disable configured endpoints.
  111. type IgnoreConfiguredEndpointsProvider interface {
  112. GetIgnoreConfiguredEndpoints(ctx context.Context) (bool, bool, error)
  113. }
  114. // GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
  115. // endpoints feature.
  116. func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []interface{}) (value bool, found bool, err error) {
  117. for _, cfg := range configs {
  118. if p, ok := cfg.(IgnoreConfiguredEndpointsProvider); ok {
  119. value, found, err = p.GetIgnoreConfiguredEndpoints(ctx)
  120. if err != nil || found {
  121. break
  122. }
  123. }
  124. }
  125. return
  126. }
  127. type baseEndpointProvider interface {
  128. getBaseEndpoint(ctx context.Context) (string, bool, error)
  129. }
  130. func getBaseEndpoint(ctx context.Context, configs configs) (value string, found bool, err error) {
  131. for _, cfg := range configs {
  132. if p, ok := cfg.(baseEndpointProvider); ok {
  133. value, found, err = p.getBaseEndpoint(ctx)
  134. if err != nil || found {
  135. break
  136. }
  137. }
  138. }
  139. return
  140. }
  141. type servicesObjectProvider interface {
  142. getServicesObject(ctx context.Context) (map[string]map[string]string, bool, error)
  143. }
  144. func getServicesObject(ctx context.Context, configs configs) (value map[string]map[string]string, found bool, err error) {
  145. for _, cfg := range configs {
  146. if p, ok := cfg.(servicesObjectProvider); ok {
  147. value, found, err = p.getServicesObject(ctx)
  148. if err != nil || found {
  149. break
  150. }
  151. }
  152. }
  153. return
  154. }
  155. // appIDProvider provides access to the sdk app ID value
  156. type appIDProvider interface {
  157. getAppID(ctx context.Context) (string, bool, error)
  158. }
  159. func getAppID(ctx context.Context, configs configs) (value string, found bool, err error) {
  160. for _, cfg := range configs {
  161. if p, ok := cfg.(appIDProvider); ok {
  162. value, found, err = p.getAppID(ctx)
  163. if err != nil || found {
  164. break
  165. }
  166. }
  167. }
  168. return
  169. }
  170. // disableRequestCompressionProvider provides access to the DisableRequestCompression
  171. type disableRequestCompressionProvider interface {
  172. getDisableRequestCompression(context.Context) (bool, bool, error)
  173. }
  174. func getDisableRequestCompression(ctx context.Context, configs configs) (value bool, found bool, err error) {
  175. for _, cfg := range configs {
  176. if p, ok := cfg.(disableRequestCompressionProvider); ok {
  177. value, found, err = p.getDisableRequestCompression(ctx)
  178. if err != nil || found {
  179. break
  180. }
  181. }
  182. }
  183. return
  184. }
  185. // requestMinCompressSizeBytesProvider provides access to the MinCompressSizeBytes
  186. type requestMinCompressSizeBytesProvider interface {
  187. getRequestMinCompressSizeBytes(context.Context) (int64, bool, error)
  188. }
  189. func getRequestMinCompressSizeBytes(ctx context.Context, configs configs) (value int64, found bool, err error) {
  190. for _, cfg := range configs {
  191. if p, ok := cfg.(requestMinCompressSizeBytesProvider); ok {
  192. value, found, err = p.getRequestMinCompressSizeBytes(ctx)
  193. if err != nil || found {
  194. break
  195. }
  196. }
  197. }
  198. return
  199. }
  200. // accountIDEndpointModeProvider provides access to the AccountIDEndpointMode
  201. type accountIDEndpointModeProvider interface {
  202. getAccountIDEndpointMode(context.Context) (aws.AccountIDEndpointMode, bool, error)
  203. }
  204. func getAccountIDEndpointMode(ctx context.Context, configs configs) (value aws.AccountIDEndpointMode, found bool, err error) {
  205. for _, cfg := range configs {
  206. if p, ok := cfg.(accountIDEndpointModeProvider); ok {
  207. value, found, err = p.getAccountIDEndpointMode(ctx)
  208. if err != nil || found {
  209. break
  210. }
  211. }
  212. }
  213. return
  214. }
  215. // requestChecksumCalculationProvider provides access to the RequestChecksumCalculation
  216. type requestChecksumCalculationProvider interface {
  217. getRequestChecksumCalculation(context.Context) (aws.RequestChecksumCalculation, bool, error)
  218. }
  219. func getRequestChecksumCalculation(ctx context.Context, configs configs) (value aws.RequestChecksumCalculation, found bool, err error) {
  220. for _, cfg := range configs {
  221. if p, ok := cfg.(requestChecksumCalculationProvider); ok {
  222. value, found, err = p.getRequestChecksumCalculation(ctx)
  223. if err != nil || found {
  224. break
  225. }
  226. }
  227. }
  228. return
  229. }
  230. // responseChecksumValidationProvider provides access to the ResponseChecksumValidation
  231. type responseChecksumValidationProvider interface {
  232. getResponseChecksumValidation(context.Context) (aws.ResponseChecksumValidation, bool, error)
  233. }
  234. func getResponseChecksumValidation(ctx context.Context, configs configs) (value aws.ResponseChecksumValidation, found bool, err error) {
  235. for _, cfg := range configs {
  236. if p, ok := cfg.(responseChecksumValidationProvider); ok {
  237. value, found, err = p.getResponseChecksumValidation(ctx)
  238. if err != nil || found {
  239. break
  240. }
  241. }
  242. }
  243. return
  244. }
  245. // ec2IMDSRegionProvider provides access to the ec2 imds region
  246. // configuration value
  247. type ec2IMDSRegionProvider interface {
  248. getEC2IMDSRegion(ctx context.Context) (string, bool, error)
  249. }
  250. // getEC2IMDSRegion searches the configs for a ec2IMDSRegionProvider and
  251. // returns the value if found. Returns an error if a provider fails before
  252. // a value is found.
  253. func getEC2IMDSRegion(ctx context.Context, configs configs) (region string, found bool, err error) {
  254. for _, cfg := range configs {
  255. if provider, ok := cfg.(ec2IMDSRegionProvider); ok {
  256. region, found, err = provider.getEC2IMDSRegion(ctx)
  257. if err != nil || found {
  258. break
  259. }
  260. }
  261. }
  262. return
  263. }
  264. // credentialsProviderProvider provides access to the credentials external
  265. // configuration value.
  266. type credentialsProviderProvider interface {
  267. getCredentialsProvider(ctx context.Context) (aws.CredentialsProvider, bool, error)
  268. }
  269. // getCredentialsProvider searches the configs for a credentialsProviderProvider
  270. // and returns the value if found. Returns an error if a provider fails before a
  271. // value is found.
  272. func getCredentialsProvider(ctx context.Context, configs configs) (p aws.CredentialsProvider, found bool, err error) {
  273. for _, cfg := range configs {
  274. if provider, ok := cfg.(credentialsProviderProvider); ok {
  275. p, found, err = provider.getCredentialsProvider(ctx)
  276. if err != nil || found {
  277. break
  278. }
  279. }
  280. }
  281. return
  282. }
  283. // credentialsCacheOptionsProvider is an interface for retrieving a function for setting
  284. // the aws.CredentialsCacheOptions.
  285. type credentialsCacheOptionsProvider interface {
  286. getCredentialsCacheOptions(ctx context.Context) (func(*aws.CredentialsCacheOptions), bool, error)
  287. }
  288. // getCredentialsCacheOptionsProvider is an interface for retrieving a function for setting
  289. // the aws.CredentialsCacheOptions.
  290. func getCredentialsCacheOptionsProvider(ctx context.Context, configs configs) (
  291. f func(*aws.CredentialsCacheOptions), found bool, err error,
  292. ) {
  293. for _, config := range configs {
  294. if p, ok := config.(credentialsCacheOptionsProvider); ok {
  295. f, found, err = p.getCredentialsCacheOptions(ctx)
  296. if err != nil || found {
  297. break
  298. }
  299. }
  300. }
  301. return
  302. }
  303. // bearerAuthTokenProviderProvider provides access to the bearer authentication
  304. // token external configuration value.
  305. type bearerAuthTokenProviderProvider interface {
  306. getBearerAuthTokenProvider(context.Context) (smithybearer.TokenProvider, bool, error)
  307. }
  308. // getBearerAuthTokenProvider searches the config sources for a
  309. // bearerAuthTokenProviderProvider and returns the value if found. Returns an
  310. // error if a provider fails before a value is found.
  311. func getBearerAuthTokenProvider(ctx context.Context, configs configs) (p smithybearer.TokenProvider, found bool, err error) {
  312. for _, cfg := range configs {
  313. if provider, ok := cfg.(bearerAuthTokenProviderProvider); ok {
  314. p, found, err = provider.getBearerAuthTokenProvider(ctx)
  315. if err != nil || found {
  316. break
  317. }
  318. }
  319. }
  320. return
  321. }
  322. // bearerAuthTokenCacheOptionsProvider is an interface for retrieving a function for
  323. // setting the smithy-go auth/bearer#TokenCacheOptions.
  324. type bearerAuthTokenCacheOptionsProvider interface {
  325. getBearerAuthTokenCacheOptions(context.Context) (func(*smithybearer.TokenCacheOptions), bool, error)
  326. }
  327. // getBearerAuthTokenCacheOptionsProvider is an interface for retrieving a function for
  328. // setting the smithy-go auth/bearer#TokenCacheOptions.
  329. func getBearerAuthTokenCacheOptions(ctx context.Context, configs configs) (
  330. f func(*smithybearer.TokenCacheOptions), found bool, err error,
  331. ) {
  332. for _, config := range configs {
  333. if p, ok := config.(bearerAuthTokenCacheOptionsProvider); ok {
  334. f, found, err = p.getBearerAuthTokenCacheOptions(ctx)
  335. if err != nil || found {
  336. break
  337. }
  338. }
  339. }
  340. return
  341. }
  342. // ssoTokenProviderOptionsProvider is an interface for retrieving a function for
  343. // setting the SDK's credentials/ssocreds#SSOTokenProviderOptions.
  344. type ssoTokenProviderOptionsProvider interface {
  345. getSSOTokenProviderOptions(context.Context) (func(*ssocreds.SSOTokenProviderOptions), bool, error)
  346. }
  347. // getSSOTokenProviderOptions is an interface for retrieving a function for
  348. // setting the SDK's credentials/ssocreds#SSOTokenProviderOptions.
  349. func getSSOTokenProviderOptions(ctx context.Context, configs configs) (
  350. f func(*ssocreds.SSOTokenProviderOptions), found bool, err error,
  351. ) {
  352. for _, config := range configs {
  353. if p, ok := config.(ssoTokenProviderOptionsProvider); ok {
  354. f, found, err = p.getSSOTokenProviderOptions(ctx)
  355. if err != nil || found {
  356. break
  357. }
  358. }
  359. }
  360. return
  361. }
  362. // ssoTokenProviderOptionsProvider
  363. // processCredentialOptions is an interface for retrieving a function for setting
  364. // the processcreds.Options.
  365. type processCredentialOptions interface {
  366. getProcessCredentialOptions(ctx context.Context) (func(*processcreds.Options), bool, error)
  367. }
  368. // getProcessCredentialOptions searches the slice of configs and returns the first function found
  369. func getProcessCredentialOptions(ctx context.Context, configs configs) (f func(*processcreds.Options), found bool, err error) {
  370. for _, config := range configs {
  371. if p, ok := config.(processCredentialOptions); ok {
  372. f, found, err = p.getProcessCredentialOptions(ctx)
  373. if err != nil || found {
  374. break
  375. }
  376. }
  377. }
  378. return
  379. }
  380. // ec2RoleCredentialOptionsProvider is an interface for retrieving a function
  381. // for setting the ec2rolecreds.Provider options.
  382. type ec2RoleCredentialOptionsProvider interface {
  383. getEC2RoleCredentialOptions(ctx context.Context) (func(*ec2rolecreds.Options), bool, error)
  384. }
  385. // getEC2RoleCredentialProviderOptions searches the slice of configs and returns the first function found
  386. func getEC2RoleCredentialProviderOptions(ctx context.Context, configs configs) (f func(*ec2rolecreds.Options), found bool, err error) {
  387. for _, config := range configs {
  388. if p, ok := config.(ec2RoleCredentialOptionsProvider); ok {
  389. f, found, err = p.getEC2RoleCredentialOptions(ctx)
  390. if err != nil || found {
  391. break
  392. }
  393. }
  394. }
  395. return
  396. }
  397. // defaultRegionProvider is an interface for retrieving a default region if a region was not resolved from other sources
  398. type defaultRegionProvider interface {
  399. getDefaultRegion(ctx context.Context) (string, bool, error)
  400. }
  401. // getDefaultRegion searches the slice of configs and returns the first fallback region found
  402. func getDefaultRegion(ctx context.Context, configs configs) (value string, found bool, err error) {
  403. for _, config := range configs {
  404. if p, ok := config.(defaultRegionProvider); ok {
  405. value, found, err = p.getDefaultRegion(ctx)
  406. if err != nil || found {
  407. break
  408. }
  409. }
  410. }
  411. return
  412. }
  413. // endpointCredentialOptionsProvider is an interface for retrieving a function for setting
  414. // the endpointcreds.ProviderOptions.
  415. type endpointCredentialOptionsProvider interface {
  416. getEndpointCredentialOptions(ctx context.Context) (func(*endpointcreds.Options), bool, error)
  417. }
  418. // getEndpointCredentialProviderOptions searches the slice of configs and returns the first function found
  419. func getEndpointCredentialProviderOptions(ctx context.Context, configs configs) (f func(*endpointcreds.Options), found bool, err error) {
  420. for _, config := range configs {
  421. if p, ok := config.(endpointCredentialOptionsProvider); ok {
  422. f, found, err = p.getEndpointCredentialOptions(ctx)
  423. if err != nil || found {
  424. break
  425. }
  426. }
  427. }
  428. return
  429. }
  430. // webIdentityRoleCredentialOptionsProvider is an interface for retrieving a function for setting
  431. // the stscreds.WebIdentityRoleProvider.
  432. type webIdentityRoleCredentialOptionsProvider interface {
  433. getWebIdentityRoleCredentialOptions(ctx context.Context) (func(*stscreds.WebIdentityRoleOptions), bool, error)
  434. }
  435. // getWebIdentityCredentialProviderOptions searches the slice of configs and returns the first function found
  436. func getWebIdentityCredentialProviderOptions(ctx context.Context, configs configs) (f func(*stscreds.WebIdentityRoleOptions), found bool, err error) {
  437. for _, config := range configs {
  438. if p, ok := config.(webIdentityRoleCredentialOptionsProvider); ok {
  439. f, found, err = p.getWebIdentityRoleCredentialOptions(ctx)
  440. if err != nil || found {
  441. break
  442. }
  443. }
  444. }
  445. return
  446. }
  447. // assumeRoleCredentialOptionsProvider is an interface for retrieving a function for setting
  448. // the stscreds.AssumeRoleOptions.
  449. type assumeRoleCredentialOptionsProvider interface {
  450. getAssumeRoleCredentialOptions(ctx context.Context) (func(*stscreds.AssumeRoleOptions), bool, error)
  451. }
  452. // getAssumeRoleCredentialProviderOptions searches the slice of configs and returns the first function found
  453. func getAssumeRoleCredentialProviderOptions(ctx context.Context, configs configs) (f func(*stscreds.AssumeRoleOptions), found bool, err error) {
  454. for _, config := range configs {
  455. if p, ok := config.(assumeRoleCredentialOptionsProvider); ok {
  456. f, found, err = p.getAssumeRoleCredentialOptions(ctx)
  457. if err != nil || found {
  458. break
  459. }
  460. }
  461. }
  462. return
  463. }
  464. // HTTPClient is an HTTP client implementation
  465. type HTTPClient interface {
  466. Do(*http.Request) (*http.Response, error)
  467. }
  468. // httpClientProvider is an interface for retrieving HTTPClient
  469. type httpClientProvider interface {
  470. getHTTPClient(ctx context.Context) (HTTPClient, bool, error)
  471. }
  472. // getHTTPClient searches the slice of configs and returns the HTTPClient set on configs
  473. func getHTTPClient(ctx context.Context, configs configs) (client HTTPClient, found bool, err error) {
  474. for _, config := range configs {
  475. if p, ok := config.(httpClientProvider); ok {
  476. client, found, err = p.getHTTPClient(ctx)
  477. if err != nil || found {
  478. break
  479. }
  480. }
  481. }
  482. return
  483. }
  484. // apiOptionsProvider is an interface for retrieving APIOptions
  485. type apiOptionsProvider interface {
  486. getAPIOptions(ctx context.Context) ([]func(*middleware.Stack) error, bool, error)
  487. }
  488. // getAPIOptions searches the slice of configs and returns the APIOptions set on configs
  489. func getAPIOptions(ctx context.Context, configs configs) (apiOptions []func(*middleware.Stack) error, found bool, err error) {
  490. for _, config := range configs {
  491. if p, ok := config.(apiOptionsProvider); ok {
  492. // retrieve APIOptions from configs and set it on cfg
  493. apiOptions, found, err = p.getAPIOptions(ctx)
  494. if err != nil || found {
  495. break
  496. }
  497. }
  498. }
  499. return
  500. }
  501. // endpointResolverProvider is an interface for retrieving an aws.EndpointResolver from a configuration source
  502. type endpointResolverProvider interface {
  503. getEndpointResolver(ctx context.Context) (aws.EndpointResolver, bool, error)
  504. }
  505. // getEndpointResolver searches the provided config sources for a EndpointResolverFunc that can be used
  506. // to configure the aws.Config.EndpointResolver value.
  507. func getEndpointResolver(ctx context.Context, configs configs) (f aws.EndpointResolver, found bool, err error) {
  508. for _, c := range configs {
  509. if p, ok := c.(endpointResolverProvider); ok {
  510. f, found, err = p.getEndpointResolver(ctx)
  511. if err != nil || found {
  512. break
  513. }
  514. }
  515. }
  516. return
  517. }
  518. // endpointResolverWithOptionsProvider is an interface for retrieving an aws.EndpointResolverWithOptions from a configuration source
  519. type endpointResolverWithOptionsProvider interface {
  520. getEndpointResolverWithOptions(ctx context.Context) (aws.EndpointResolverWithOptions, bool, error)
  521. }
  522. // getEndpointResolver searches the provided config sources for a EndpointResolverFunc that can be used
  523. // to configure the aws.Config.EndpointResolver value.
  524. func getEndpointResolverWithOptions(ctx context.Context, configs configs) (f aws.EndpointResolverWithOptions, found bool, err error) {
  525. for _, c := range configs {
  526. if p, ok := c.(endpointResolverWithOptionsProvider); ok {
  527. f, found, err = p.getEndpointResolverWithOptions(ctx)
  528. if err != nil || found {
  529. break
  530. }
  531. }
  532. }
  533. return
  534. }
  535. // loggerProvider is an interface for retrieving a logging.Logger from a configuration source.
  536. type loggerProvider interface {
  537. getLogger(ctx context.Context) (logging.Logger, bool, error)
  538. }
  539. // getLogger searches the provided config sources for a logging.Logger that can be used
  540. // to configure the aws.Config.Logger value.
  541. func getLogger(ctx context.Context, configs configs) (l logging.Logger, found bool, err error) {
  542. for _, c := range configs {
  543. if p, ok := c.(loggerProvider); ok {
  544. l, found, err = p.getLogger(ctx)
  545. if err != nil || found {
  546. break
  547. }
  548. }
  549. }
  550. return
  551. }
  552. // clientLogModeProvider is an interface for retrieving the aws.ClientLogMode from a configuration source.
  553. type clientLogModeProvider interface {
  554. getClientLogMode(ctx context.Context) (aws.ClientLogMode, bool, error)
  555. }
  556. func getClientLogMode(ctx context.Context, configs configs) (m aws.ClientLogMode, found bool, err error) {
  557. for _, c := range configs {
  558. if p, ok := c.(clientLogModeProvider); ok {
  559. m, found, err = p.getClientLogMode(ctx)
  560. if err != nil || found {
  561. break
  562. }
  563. }
  564. }
  565. return
  566. }
  567. // retryProvider is an configuration provider for custom Retryer.
  568. type retryProvider interface {
  569. getRetryer(ctx context.Context) (func() aws.Retryer, bool, error)
  570. }
  571. func getRetryer(ctx context.Context, configs configs) (v func() aws.Retryer, found bool, err error) {
  572. for _, c := range configs {
  573. if p, ok := c.(retryProvider); ok {
  574. v, found, err = p.getRetryer(ctx)
  575. if err != nil || found {
  576. break
  577. }
  578. }
  579. }
  580. return
  581. }
  582. // logConfigurationWarningsProvider is an configuration provider for
  583. // retrieving a boolean indicating whether configuration issues should
  584. // be logged when loading from config sources
  585. type logConfigurationWarningsProvider interface {
  586. getLogConfigurationWarnings(ctx context.Context) (bool, bool, error)
  587. }
  588. func getLogConfigurationWarnings(ctx context.Context, configs configs) (v bool, found bool, err error) {
  589. for _, c := range configs {
  590. if p, ok := c.(logConfigurationWarningsProvider); ok {
  591. v, found, err = p.getLogConfigurationWarnings(ctx)
  592. if err != nil || found {
  593. break
  594. }
  595. }
  596. }
  597. return
  598. }
  599. // ssoCredentialOptionsProvider is an interface for retrieving a function for setting
  600. // the ssocreds.Options.
  601. type ssoCredentialOptionsProvider interface {
  602. getSSOProviderOptions(context.Context) (func(*ssocreds.Options), bool, error)
  603. }
  604. func getSSOProviderOptions(ctx context.Context, configs configs) (v func(options *ssocreds.Options), found bool, err error) {
  605. for _, c := range configs {
  606. if p, ok := c.(ssoCredentialOptionsProvider); ok {
  607. v, found, err = p.getSSOProviderOptions(ctx)
  608. if err != nil || found {
  609. break
  610. }
  611. }
  612. }
  613. return v, found, err
  614. }
  615. type defaultsModeIMDSClientProvider interface {
  616. getDefaultsModeIMDSClient(context.Context) (*imds.Client, bool, error)
  617. }
  618. func getDefaultsModeIMDSClient(ctx context.Context, configs configs) (v *imds.Client, found bool, err error) {
  619. for _, c := range configs {
  620. if p, ok := c.(defaultsModeIMDSClientProvider); ok {
  621. v, found, err = p.getDefaultsModeIMDSClient(ctx)
  622. if err != nil || found {
  623. break
  624. }
  625. }
  626. }
  627. return v, found, err
  628. }
  629. type defaultsModeProvider interface {
  630. getDefaultsMode(context.Context) (aws.DefaultsMode, bool, error)
  631. }
  632. func getDefaultsMode(ctx context.Context, configs configs) (v aws.DefaultsMode, found bool, err error) {
  633. for _, c := range configs {
  634. if p, ok := c.(defaultsModeProvider); ok {
  635. v, found, err = p.getDefaultsMode(ctx)
  636. if err != nil || found {
  637. break
  638. }
  639. }
  640. }
  641. return v, found, err
  642. }
  643. type retryMaxAttemptsProvider interface {
  644. GetRetryMaxAttempts(context.Context) (int, bool, error)
  645. }
  646. func getRetryMaxAttempts(ctx context.Context, configs configs) (v int, found bool, err error) {
  647. for _, c := range configs {
  648. if p, ok := c.(retryMaxAttemptsProvider); ok {
  649. v, found, err = p.GetRetryMaxAttempts(ctx)
  650. if err != nil || found {
  651. break
  652. }
  653. }
  654. }
  655. return v, found, err
  656. }
  657. type retryModeProvider interface {
  658. GetRetryMode(context.Context) (aws.RetryMode, bool, error)
  659. }
  660. func getRetryMode(ctx context.Context, configs configs) (v aws.RetryMode, found bool, err error) {
  661. for _, c := range configs {
  662. if p, ok := c.(retryModeProvider); ok {
  663. v, found, err = p.GetRetryMode(ctx)
  664. if err != nil || found {
  665. break
  666. }
  667. }
  668. }
  669. return v, found, err
  670. }
  671. func getAuthSchemePreference(ctx context.Context, configs configs) ([]string, bool) {
  672. type provider interface {
  673. getAuthSchemePreference() ([]string, bool)
  674. }
  675. for _, cfg := range configs {
  676. if p, ok := cfg.(provider); ok {
  677. if v, ok := p.getAuthSchemePreference(); ok {
  678. return v, true
  679. }
  680. }
  681. }
  682. return nil, false
  683. }
  684. type serviceOptionsProvider interface {
  685. getServiceOptions(ctx context.Context) ([]func(string, any), bool, error)
  686. }
  687. func getServiceOptions(ctx context.Context, configs configs) (v []func(string, any), found bool, err error) {
  688. for _, c := range configs {
  689. if p, ok := c.(serviceOptionsProvider); ok {
  690. v, found, err = p.getServiceOptions(ctx)
  691. if err != nil || found {
  692. break
  693. }
  694. }
  695. }
  696. return v, found, err
  697. }