endpoints.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package costexplorer
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "github.com/aws/aws-sdk-go-v2/aws"
  8. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  9. internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources"
  10. "github.com/aws/aws-sdk-go-v2/internal/endpoints"
  11. "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn"
  12. internalendpoints "github.com/aws/aws-sdk-go-v2/service/costexplorer/internal/endpoints"
  13. smithy "github.com/aws/smithy-go"
  14. smithyauth "github.com/aws/smithy-go/auth"
  15. smithyendpoints "github.com/aws/smithy-go/endpoints"
  16. "github.com/aws/smithy-go/endpoints/private/rulesfn"
  17. "github.com/aws/smithy-go/middleware"
  18. "github.com/aws/smithy-go/ptr"
  19. "github.com/aws/smithy-go/tracing"
  20. smithyhttp "github.com/aws/smithy-go/transport/http"
  21. "net/http"
  22. "net/url"
  23. "os"
  24. "strings"
  25. )
  26. // EndpointResolverOptions is the service endpoint resolver options
  27. type EndpointResolverOptions = internalendpoints.Options
  28. // EndpointResolver interface for resolving service endpoints.
  29. type EndpointResolver interface {
  30. ResolveEndpoint(region string, options EndpointResolverOptions) (aws.Endpoint, error)
  31. }
  32. var _ EndpointResolver = &internalendpoints.Resolver{}
  33. // NewDefaultEndpointResolver constructs a new service endpoint resolver
  34. func NewDefaultEndpointResolver() *internalendpoints.Resolver {
  35. return internalendpoints.New()
  36. }
  37. // EndpointResolverFunc is a helper utility that wraps a function so it satisfies
  38. // the EndpointResolver interface. This is useful when you want to add additional
  39. // endpoint resolving logic, or stub out specific endpoints with custom values.
  40. type EndpointResolverFunc func(region string, options EndpointResolverOptions) (aws.Endpoint, error)
  41. func (fn EndpointResolverFunc) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
  42. return fn(region, options)
  43. }
  44. // EndpointResolverFromURL returns an EndpointResolver configured using the
  45. // provided endpoint url. By default, the resolved endpoint resolver uses the
  46. // client region as signing region, and the endpoint source is set to
  47. // EndpointSourceCustom.You can provide functional options to configure endpoint
  48. // values for the resolved endpoint.
  49. func EndpointResolverFromURL(url string, optFns ...func(*aws.Endpoint)) EndpointResolver {
  50. e := aws.Endpoint{URL: url, Source: aws.EndpointSourceCustom}
  51. for _, fn := range optFns {
  52. fn(&e)
  53. }
  54. return EndpointResolverFunc(
  55. func(region string, options EndpointResolverOptions) (aws.Endpoint, error) {
  56. if len(e.SigningRegion) == 0 {
  57. e.SigningRegion = region
  58. }
  59. return e, nil
  60. },
  61. )
  62. }
  63. type ResolveEndpoint struct {
  64. Resolver EndpointResolver
  65. Options EndpointResolverOptions
  66. }
  67. func (*ResolveEndpoint) ID() string {
  68. return "ResolveEndpoint"
  69. }
  70. func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
  71. out middleware.SerializeOutput, metadata middleware.Metadata, err error,
  72. ) {
  73. if !awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
  74. return next.HandleSerialize(ctx, in)
  75. }
  76. req, ok := in.Request.(*smithyhttp.Request)
  77. if !ok {
  78. return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
  79. }
  80. if m.Resolver == nil {
  81. return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
  82. }
  83. eo := m.Options
  84. eo.Logger = middleware.GetLogger(ctx)
  85. var endpoint aws.Endpoint
  86. endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo)
  87. if err != nil {
  88. nf := (&aws.EndpointNotFoundError{})
  89. if errors.As(err, &nf) {
  90. ctx = awsmiddleware.SetRequiresLegacyEndpoints(ctx, false)
  91. return next.HandleSerialize(ctx, in)
  92. }
  93. return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
  94. }
  95. req.URL, err = url.Parse(endpoint.URL)
  96. if err != nil {
  97. return out, metadata, fmt.Errorf("failed to parse endpoint URL: %w", err)
  98. }
  99. if len(awsmiddleware.GetSigningName(ctx)) == 0 {
  100. signingName := endpoint.SigningName
  101. if len(signingName) == 0 {
  102. signingName = "ce"
  103. }
  104. ctx = awsmiddleware.SetSigningName(ctx, signingName)
  105. }
  106. ctx = awsmiddleware.SetEndpointSource(ctx, endpoint.Source)
  107. ctx = smithyhttp.SetHostnameImmutable(ctx, endpoint.HostnameImmutable)
  108. ctx = awsmiddleware.SetSigningRegion(ctx, endpoint.SigningRegion)
  109. ctx = awsmiddleware.SetPartitionID(ctx, endpoint.PartitionID)
  110. return next.HandleSerialize(ctx, in)
  111. }
  112. func addResolveEndpointMiddleware(stack *middleware.Stack, o Options) error {
  113. return stack.Serialize.Insert(&ResolveEndpoint{
  114. Resolver: o.EndpointResolver,
  115. Options: o.EndpointOptions,
  116. }, "OperationSerializer", middleware.Before)
  117. }
  118. func removeResolveEndpointMiddleware(stack *middleware.Stack) error {
  119. _, err := stack.Serialize.Remove((&ResolveEndpoint{}).ID())
  120. return err
  121. }
  122. type wrappedEndpointResolver struct {
  123. awsResolver aws.EndpointResolverWithOptions
  124. }
  125. func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
  126. return w.awsResolver.ResolveEndpoint(ServiceID, region, options)
  127. }
  128. type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error)
  129. func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) {
  130. return a(service, region)
  131. }
  132. var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil)
  133. // withEndpointResolver returns an aws.EndpointResolverWithOptions that first delegates endpoint resolution to the awsResolver.
  134. // If awsResolver returns aws.EndpointNotFoundError error, the v1 resolver middleware will swallow the error,
  135. // and set an appropriate context flag such that fallback will occur when EndpointResolverV2 is invoked
  136. // via its middleware.
  137. //
  138. // If another error (besides aws.EndpointNotFoundError) is returned, then that error will be propagated.
  139. func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions) EndpointResolver {
  140. var resolver aws.EndpointResolverWithOptions
  141. if awsResolverWithOptions != nil {
  142. resolver = awsResolverWithOptions
  143. } else if awsResolver != nil {
  144. resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint)
  145. }
  146. return &wrappedEndpointResolver{
  147. awsResolver: resolver,
  148. }
  149. }
  150. func finalizeClientEndpointResolverOptions(options *Options) {
  151. options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage()
  152. if len(options.EndpointOptions.ResolvedRegion) == 0 {
  153. const fipsInfix = "-fips-"
  154. const fipsPrefix = "fips-"
  155. const fipsSuffix = "-fips"
  156. if strings.Contains(options.Region, fipsInfix) ||
  157. strings.Contains(options.Region, fipsPrefix) ||
  158. strings.Contains(options.Region, fipsSuffix) {
  159. options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(
  160. options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "")
  161. options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled
  162. }
  163. }
  164. }
  165. func resolveEndpointResolverV2(options *Options) {
  166. if options.EndpointResolverV2 == nil {
  167. options.EndpointResolverV2 = NewDefaultEndpointResolverV2()
  168. }
  169. }
  170. func resolveBaseEndpoint(cfg aws.Config, o *Options) {
  171. if cfg.BaseEndpoint != nil {
  172. o.BaseEndpoint = cfg.BaseEndpoint
  173. }
  174. _, g := os.LookupEnv("AWS_ENDPOINT_URL")
  175. _, s := os.LookupEnv("AWS_ENDPOINT_URL_COST_EXPLORER")
  176. if g && !s {
  177. return
  178. }
  179. value, found, err := internalConfig.ResolveServiceBaseEndpoint(context.Background(), "Cost Explorer", cfg.ConfigSources)
  180. if found && err == nil {
  181. o.BaseEndpoint = &value
  182. }
  183. }
  184. func bindRegion(region string) (*string, error) {
  185. if region == "" {
  186. return nil, nil
  187. }
  188. if !rulesfn.IsValidHostLabel(region, true) {
  189. return nil, fmt.Errorf("invalid input region %s", region)
  190. }
  191. return aws.String(endpoints.MapFIPSRegion(region)), nil
  192. }
  193. // EndpointParameters provides the parameters that influence how endpoints are
  194. // resolved.
  195. type EndpointParameters struct {
  196. // When true, use the dual-stack endpoint. If the configured endpoint does not
  197. // support dual-stack, dispatching the request MAY return an error.
  198. //
  199. // Defaults to
  200. // false if no value is provided.
  201. //
  202. // AWS::UseDualStack
  203. UseDualStack *bool
  204. // When true, send this request to the FIPS-compliant regional endpoint. If the
  205. // configured endpoint does not have a FIPS compliant endpoint, dispatching the
  206. // request will return an error.
  207. //
  208. // Defaults to false if no value is
  209. // provided.
  210. //
  211. // AWS::UseFIPS
  212. UseFIPS *bool
  213. // Override the endpoint used to send this request
  214. //
  215. // Parameter is
  216. // required.
  217. //
  218. // SDK::Endpoint
  219. Endpoint *string
  220. // The AWS region used to dispatch the request.
  221. //
  222. // Parameter is
  223. // required.
  224. //
  225. // AWS::Region
  226. Region *string
  227. }
  228. // ValidateRequired validates required parameters are set.
  229. func (p EndpointParameters) ValidateRequired() error {
  230. if p.UseDualStack == nil {
  231. return fmt.Errorf("parameter UseDualStack is required")
  232. }
  233. if p.UseFIPS == nil {
  234. return fmt.Errorf("parameter UseFIPS is required")
  235. }
  236. return nil
  237. }
  238. // WithDefaults returns a shallow copy of EndpointParameterswith default values
  239. // applied to members where applicable.
  240. func (p EndpointParameters) WithDefaults() EndpointParameters {
  241. if p.UseDualStack == nil {
  242. p.UseDualStack = ptr.Bool(false)
  243. }
  244. if p.UseFIPS == nil {
  245. p.UseFIPS = ptr.Bool(false)
  246. }
  247. return p
  248. }
  249. type stringSlice []string
  250. func (s stringSlice) Get(i int) *string {
  251. if i < 0 || i >= len(s) {
  252. return nil
  253. }
  254. v := s[i]
  255. return &v
  256. }
  257. // EndpointResolverV2 provides the interface for resolving service endpoints.
  258. type EndpointResolverV2 interface {
  259. // ResolveEndpoint attempts to resolve the endpoint with the provided options,
  260. // returning the endpoint if found. Otherwise an error is returned.
  261. ResolveEndpoint(ctx context.Context, params EndpointParameters) (
  262. smithyendpoints.Endpoint, error,
  263. )
  264. }
  265. // resolver provides the implementation for resolving endpoints.
  266. type resolver struct{}
  267. func NewDefaultEndpointResolverV2() EndpointResolverV2 {
  268. return &resolver{}
  269. }
  270. // ResolveEndpoint attempts to resolve the endpoint with the provided options,
  271. // returning the endpoint if found. Otherwise an error is returned.
  272. func (r *resolver) ResolveEndpoint(
  273. ctx context.Context, params EndpointParameters,
  274. ) (
  275. endpoint smithyendpoints.Endpoint, err error,
  276. ) {
  277. params = params.WithDefaults()
  278. if err = params.ValidateRequired(); err != nil {
  279. return endpoint, fmt.Errorf("endpoint parameters are not valid, %w", err)
  280. }
  281. _UseDualStack := *params.UseDualStack
  282. _ = _UseDualStack
  283. _UseFIPS := *params.UseFIPS
  284. _ = _UseFIPS
  285. if exprVal := params.Endpoint; exprVal != nil {
  286. _Endpoint := *exprVal
  287. _ = _Endpoint
  288. if _UseFIPS == true {
  289. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: FIPS and custom endpoint are not supported")
  290. }
  291. if _UseDualStack == true {
  292. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Dualstack and custom endpoint are not supported")
  293. }
  294. uriString := _Endpoint
  295. uri, err := url.Parse(uriString)
  296. if err != nil {
  297. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  298. }
  299. return smithyendpoints.Endpoint{
  300. URI: *uri,
  301. Headers: http.Header{},
  302. }, nil
  303. }
  304. if exprVal := params.Region; exprVal != nil {
  305. _Region := *exprVal
  306. _ = _Region
  307. if exprVal := awsrulesfn.GetPartition(_Region); exprVal != nil {
  308. _PartitionResult := *exprVal
  309. _ = _PartitionResult
  310. if _PartitionResult.Name == "aws" {
  311. if _UseFIPS == false {
  312. if _UseDualStack == true {
  313. uriString := "https://ce.us-east-1.api.aws"
  314. uri, err := url.Parse(uriString)
  315. if err != nil {
  316. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  317. }
  318. return smithyendpoints.Endpoint{
  319. URI: *uri,
  320. Headers: http.Header{},
  321. Properties: func() smithy.Properties {
  322. var out smithy.Properties
  323. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  324. {
  325. SchemeID: "aws.auth#sigv4",
  326. SignerProperties: func() smithy.Properties {
  327. var sp smithy.Properties
  328. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  329. return sp
  330. }(),
  331. },
  332. })
  333. return out
  334. }(),
  335. }, nil
  336. }
  337. }
  338. }
  339. if _PartitionResult.Name == "aws-cn" {
  340. if _UseFIPS == false {
  341. if _UseDualStack == true {
  342. uriString := "https://ce.cn-northwest-1.api.amazonwebservices.com.cn"
  343. uri, err := url.Parse(uriString)
  344. if err != nil {
  345. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  346. }
  347. return smithyendpoints.Endpoint{
  348. URI: *uri,
  349. Headers: http.Header{},
  350. Properties: func() smithy.Properties {
  351. var out smithy.Properties
  352. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  353. {
  354. SchemeID: "aws.auth#sigv4",
  355. SignerProperties: func() smithy.Properties {
  356. var sp smithy.Properties
  357. smithyhttp.SetSigV4SigningRegion(&sp, "cn-northwest-1")
  358. return sp
  359. }(),
  360. },
  361. })
  362. return out
  363. }(),
  364. }, nil
  365. }
  366. }
  367. }
  368. if _PartitionResult.Name == "aws-iso" {
  369. if _UseFIPS == false {
  370. if _UseDualStack == false {
  371. uriString := "https://ce.us-iso-east-1.c2s.ic.gov"
  372. uri, err := url.Parse(uriString)
  373. if err != nil {
  374. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  375. }
  376. return smithyendpoints.Endpoint{
  377. URI: *uri,
  378. Headers: http.Header{},
  379. Properties: func() smithy.Properties {
  380. var out smithy.Properties
  381. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  382. {
  383. SchemeID: "aws.auth#sigv4",
  384. SignerProperties: func() smithy.Properties {
  385. var sp smithy.Properties
  386. smithyhttp.SetSigV4SigningRegion(&sp, "us-iso-east-1")
  387. return sp
  388. }(),
  389. },
  390. })
  391. return out
  392. }(),
  393. }, nil
  394. }
  395. }
  396. }
  397. if _PartitionResult.Name == "aws-iso-b" {
  398. if _UseFIPS == false {
  399. if _UseDualStack == false {
  400. uriString := "https://ce.us-isob-east-1.sc2s.sgov.gov"
  401. uri, err := url.Parse(uriString)
  402. if err != nil {
  403. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  404. }
  405. return smithyendpoints.Endpoint{
  406. URI: *uri,
  407. Headers: http.Header{},
  408. Properties: func() smithy.Properties {
  409. var out smithy.Properties
  410. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  411. {
  412. SchemeID: "aws.auth#sigv4",
  413. SignerProperties: func() smithy.Properties {
  414. var sp smithy.Properties
  415. smithyhttp.SetSigV4SigningRegion(&sp, "us-isob-east-1")
  416. return sp
  417. }(),
  418. },
  419. })
  420. return out
  421. }(),
  422. }, nil
  423. }
  424. }
  425. }
  426. if _PartitionResult.Name == "aws-iso-e" {
  427. if _UseFIPS == false {
  428. if _UseDualStack == false {
  429. uriString := "https://ce.eu-isoe-west-1.cloud.adc-e.uk"
  430. uri, err := url.Parse(uriString)
  431. if err != nil {
  432. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  433. }
  434. return smithyendpoints.Endpoint{
  435. URI: *uri,
  436. Headers: http.Header{},
  437. Properties: func() smithy.Properties {
  438. var out smithy.Properties
  439. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  440. {
  441. SchemeID: "aws.auth#sigv4",
  442. SignerProperties: func() smithy.Properties {
  443. var sp smithy.Properties
  444. smithyhttp.SetSigV4SigningRegion(&sp, "eu-isoe-west-1")
  445. return sp
  446. }(),
  447. },
  448. })
  449. return out
  450. }(),
  451. }, nil
  452. }
  453. }
  454. }
  455. if _PartitionResult.Name == "aws-iso-f" {
  456. if _UseFIPS == false {
  457. if _UseDualStack == false {
  458. uriString := "https://ce.us-isof-south-1.csp.hci.ic.gov"
  459. uri, err := url.Parse(uriString)
  460. if err != nil {
  461. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  462. }
  463. return smithyendpoints.Endpoint{
  464. URI: *uri,
  465. Headers: http.Header{},
  466. Properties: func() smithy.Properties {
  467. var out smithy.Properties
  468. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  469. {
  470. SchemeID: "aws.auth#sigv4",
  471. SignerProperties: func() smithy.Properties {
  472. var sp smithy.Properties
  473. smithyhttp.SetSigV4SigningRegion(&sp, "us-isof-south-1")
  474. return sp
  475. }(),
  476. },
  477. })
  478. return out
  479. }(),
  480. }, nil
  481. }
  482. }
  483. }
  484. if _PartitionResult.Name == "aws-eusc" {
  485. if _UseFIPS == false {
  486. if _UseDualStack == true {
  487. uriString := "https://ce.eusc-de-east-1.api.amazonwebservices.eu"
  488. uri, err := url.Parse(uriString)
  489. if err != nil {
  490. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  491. }
  492. return smithyendpoints.Endpoint{
  493. URI: *uri,
  494. Headers: http.Header{},
  495. Properties: func() smithy.Properties {
  496. var out smithy.Properties
  497. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  498. {
  499. SchemeID: "aws.auth#sigv4",
  500. SignerProperties: func() smithy.Properties {
  501. var sp smithy.Properties
  502. smithyhttp.SetSigV4SigningRegion(&sp, "eusc-de-east-1")
  503. return sp
  504. }(),
  505. },
  506. })
  507. return out
  508. }(),
  509. }, nil
  510. }
  511. }
  512. }
  513. if _PartitionResult.Name == "aws-eusc" {
  514. if _UseFIPS == false {
  515. if _UseDualStack == false {
  516. uriString := "https://ce.eusc-de-east-1.api.amazonwebservices.eu"
  517. uri, err := url.Parse(uriString)
  518. if err != nil {
  519. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  520. }
  521. return smithyendpoints.Endpoint{
  522. URI: *uri,
  523. Headers: http.Header{},
  524. Properties: func() smithy.Properties {
  525. var out smithy.Properties
  526. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  527. {
  528. SchemeID: "aws.auth#sigv4",
  529. SignerProperties: func() smithy.Properties {
  530. var sp smithy.Properties
  531. smithyhttp.SetSigV4SigningRegion(&sp, "eusc-de-east-1")
  532. return sp
  533. }(),
  534. },
  535. })
  536. return out
  537. }(),
  538. }, nil
  539. }
  540. }
  541. }
  542. if _UseFIPS == true {
  543. if _UseDualStack == true {
  544. if true == _PartitionResult.SupportsFIPS {
  545. if true == _PartitionResult.SupportsDualStack {
  546. uriString := func() string {
  547. var out strings.Builder
  548. out.WriteString("https://ce-fips.")
  549. out.WriteString(_PartitionResult.ImplicitGlobalRegion)
  550. out.WriteString(".")
  551. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  552. return out.String()
  553. }()
  554. uri, err := url.Parse(uriString)
  555. if err != nil {
  556. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  557. }
  558. return smithyendpoints.Endpoint{
  559. URI: *uri,
  560. Headers: http.Header{},
  561. Properties: func() smithy.Properties {
  562. var out smithy.Properties
  563. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  564. {
  565. SchemeID: "aws.auth#sigv4",
  566. SignerProperties: func() smithy.Properties {
  567. var sp smithy.Properties
  568. smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
  569. return sp
  570. }(),
  571. },
  572. })
  573. return out
  574. }(),
  575. }, nil
  576. }
  577. }
  578. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS and DualStack are enabled, but this partition does not support one or both")
  579. }
  580. }
  581. if _UseFIPS == true {
  582. if _UseDualStack == false {
  583. if _PartitionResult.SupportsFIPS == true {
  584. uriString := func() string {
  585. var out strings.Builder
  586. out.WriteString("https://ce-fips.")
  587. out.WriteString(_PartitionResult.ImplicitGlobalRegion)
  588. out.WriteString(".")
  589. out.WriteString(_PartitionResult.DnsSuffix)
  590. return out.String()
  591. }()
  592. uri, err := url.Parse(uriString)
  593. if err != nil {
  594. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  595. }
  596. return smithyendpoints.Endpoint{
  597. URI: *uri,
  598. Headers: http.Header{},
  599. Properties: func() smithy.Properties {
  600. var out smithy.Properties
  601. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  602. {
  603. SchemeID: "aws.auth#sigv4",
  604. SignerProperties: func() smithy.Properties {
  605. var sp smithy.Properties
  606. smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
  607. return sp
  608. }(),
  609. },
  610. })
  611. return out
  612. }(),
  613. }, nil
  614. }
  615. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS is enabled but this partition does not support FIPS")
  616. }
  617. }
  618. if _UseFIPS == false {
  619. if _UseDualStack == true {
  620. if true == _PartitionResult.SupportsDualStack {
  621. uriString := func() string {
  622. var out strings.Builder
  623. out.WriteString("https://ce.")
  624. out.WriteString(_PartitionResult.ImplicitGlobalRegion)
  625. out.WriteString(".")
  626. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  627. return out.String()
  628. }()
  629. uri, err := url.Parse(uriString)
  630. if err != nil {
  631. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  632. }
  633. return smithyendpoints.Endpoint{
  634. URI: *uri,
  635. Headers: http.Header{},
  636. Properties: func() smithy.Properties {
  637. var out smithy.Properties
  638. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  639. {
  640. SchemeID: "aws.auth#sigv4",
  641. SignerProperties: func() smithy.Properties {
  642. var sp smithy.Properties
  643. smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
  644. return sp
  645. }(),
  646. },
  647. })
  648. return out
  649. }(),
  650. }, nil
  651. }
  652. return endpoint, fmt.Errorf("endpoint rule error, %s", "DualStack is enabled but this partition does not support DualStack")
  653. }
  654. }
  655. uriString := func() string {
  656. var out strings.Builder
  657. out.WriteString("https://ce.")
  658. out.WriteString(_PartitionResult.ImplicitGlobalRegion)
  659. out.WriteString(".")
  660. out.WriteString(_PartitionResult.DnsSuffix)
  661. return out.String()
  662. }()
  663. uri, err := url.Parse(uriString)
  664. if err != nil {
  665. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  666. }
  667. return smithyendpoints.Endpoint{
  668. URI: *uri,
  669. Headers: http.Header{},
  670. Properties: func() smithy.Properties {
  671. var out smithy.Properties
  672. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  673. {
  674. SchemeID: "aws.auth#sigv4",
  675. SignerProperties: func() smithy.Properties {
  676. var sp smithy.Properties
  677. smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
  678. return sp
  679. }(),
  680. },
  681. })
  682. return out
  683. }(),
  684. }, nil
  685. }
  686. return endpoint, fmt.Errorf("Endpoint resolution failed. Invalid operation or environment input.")
  687. }
  688. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Missing Region")
  689. }
  690. type endpointParamsBinder interface {
  691. bindEndpointParams(*EndpointParameters)
  692. }
  693. func bindEndpointParams(ctx context.Context, input interface{}, options Options) (*EndpointParameters, error) {
  694. params := &EndpointParameters{}
  695. params.UseDualStack = aws.Bool(options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled)
  696. params.UseFIPS = aws.Bool(options.EndpointOptions.UseFIPSEndpoint == aws.FIPSEndpointStateEnabled)
  697. params.Endpoint = options.BaseEndpoint
  698. region, err := bindRegion(options.Region)
  699. if err != nil {
  700. return nil, err
  701. }
  702. params.Region = region
  703. if b, ok := input.(endpointParamsBinder); ok {
  704. b.bindEndpointParams(params)
  705. }
  706. return params, nil
  707. }
  708. type resolveEndpointV2Middleware struct {
  709. options Options
  710. }
  711. func (*resolveEndpointV2Middleware) ID() string {
  712. return "ResolveEndpointV2"
  713. }
  714. func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
  715. out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
  716. ) {
  717. _, span := tracing.StartSpan(ctx, "ResolveEndpoint")
  718. defer span.End()
  719. if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
  720. return next.HandleFinalize(ctx, in)
  721. }
  722. req, ok := in.Request.(*smithyhttp.Request)
  723. if !ok {
  724. return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
  725. }
  726. if m.options.EndpointResolverV2 == nil {
  727. return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
  728. }
  729. params, err := bindEndpointParams(ctx, getOperationInput(ctx), m.options)
  730. if err != nil {
  731. return out, metadata, fmt.Errorf("failed to bind endpoint params, %w", err)
  732. }
  733. endpt, err := timeOperationMetric(ctx, "client.call.resolve_endpoint_duration",
  734. func() (smithyendpoints.Endpoint, error) {
  735. return m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
  736. })
  737. if err != nil {
  738. return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
  739. }
  740. span.SetProperty("client.call.resolved_endpoint", endpt.URI.String())
  741. if endpt.URI.RawPath == "" && req.URL.RawPath != "" {
  742. endpt.URI.RawPath = endpt.URI.Path
  743. }
  744. req.URL.Scheme = endpt.URI.Scheme
  745. req.URL.Host = endpt.URI.Host
  746. req.URL.Path = smithyhttp.JoinPath(endpt.URI.Path, req.URL.Path)
  747. req.URL.RawPath = smithyhttp.JoinPath(endpt.URI.RawPath, req.URL.RawPath)
  748. for k := range endpt.Headers {
  749. req.Header.Set(k, endpt.Headers.Get(k))
  750. }
  751. rscheme := getResolvedAuthScheme(ctx)
  752. if rscheme == nil {
  753. return out, metadata, fmt.Errorf("no resolved auth scheme")
  754. }
  755. opts, _ := smithyauth.GetAuthOptions(&endpt.Properties)
  756. for _, o := range opts {
  757. rscheme.SignerProperties.SetAll(&o.SignerProperties)
  758. }
  759. span.End()
  760. return next.HandleFinalize(ctx, in)
  761. }