endpoints.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package sts
  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/sts/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/middleware"
  17. "github.com/aws/smithy-go/ptr"
  18. "github.com/aws/smithy-go/tracing"
  19. smithyhttp "github.com/aws/smithy-go/transport/http"
  20. "net/http"
  21. "net/url"
  22. "os"
  23. "strings"
  24. )
  25. // EndpointResolverOptions is the service endpoint resolver options
  26. type EndpointResolverOptions = internalendpoints.Options
  27. // EndpointResolver interface for resolving service endpoints.
  28. type EndpointResolver interface {
  29. ResolveEndpoint(region string, options EndpointResolverOptions) (aws.Endpoint, error)
  30. }
  31. var _ EndpointResolver = &internalendpoints.Resolver{}
  32. // NewDefaultEndpointResolver constructs a new service endpoint resolver
  33. func NewDefaultEndpointResolver() *internalendpoints.Resolver {
  34. return internalendpoints.New()
  35. }
  36. // EndpointResolverFunc is a helper utility that wraps a function so it satisfies
  37. // the EndpointResolver interface. This is useful when you want to add additional
  38. // endpoint resolving logic, or stub out specific endpoints with custom values.
  39. type EndpointResolverFunc func(region string, options EndpointResolverOptions) (aws.Endpoint, error)
  40. func (fn EndpointResolverFunc) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
  41. return fn(region, options)
  42. }
  43. // EndpointResolverFromURL returns an EndpointResolver configured using the
  44. // provided endpoint url. By default, the resolved endpoint resolver uses the
  45. // client region as signing region, and the endpoint source is set to
  46. // EndpointSourceCustom.You can provide functional options to configure endpoint
  47. // values for the resolved endpoint.
  48. func EndpointResolverFromURL(url string, optFns ...func(*aws.Endpoint)) EndpointResolver {
  49. e := aws.Endpoint{URL: url, Source: aws.EndpointSourceCustom}
  50. for _, fn := range optFns {
  51. fn(&e)
  52. }
  53. return EndpointResolverFunc(
  54. func(region string, options EndpointResolverOptions) (aws.Endpoint, error) {
  55. if len(e.SigningRegion) == 0 {
  56. e.SigningRegion = region
  57. }
  58. return e, nil
  59. },
  60. )
  61. }
  62. type ResolveEndpoint struct {
  63. Resolver EndpointResolver
  64. Options EndpointResolverOptions
  65. }
  66. func (*ResolveEndpoint) ID() string {
  67. return "ResolveEndpoint"
  68. }
  69. func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
  70. out middleware.SerializeOutput, metadata middleware.Metadata, err error,
  71. ) {
  72. if !awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
  73. return next.HandleSerialize(ctx, in)
  74. }
  75. req, ok := in.Request.(*smithyhttp.Request)
  76. if !ok {
  77. return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
  78. }
  79. if m.Resolver == nil {
  80. return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
  81. }
  82. eo := m.Options
  83. eo.Logger = middleware.GetLogger(ctx)
  84. var endpoint aws.Endpoint
  85. endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo)
  86. if err != nil {
  87. nf := (&aws.EndpointNotFoundError{})
  88. if errors.As(err, &nf) {
  89. ctx = awsmiddleware.SetRequiresLegacyEndpoints(ctx, false)
  90. return next.HandleSerialize(ctx, in)
  91. }
  92. return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
  93. }
  94. req.URL, err = url.Parse(endpoint.URL)
  95. if err != nil {
  96. return out, metadata, fmt.Errorf("failed to parse endpoint URL: %w", err)
  97. }
  98. if len(awsmiddleware.GetSigningName(ctx)) == 0 {
  99. signingName := endpoint.SigningName
  100. if len(signingName) == 0 {
  101. signingName = "sts"
  102. }
  103. ctx = awsmiddleware.SetSigningName(ctx, signingName)
  104. }
  105. ctx = awsmiddleware.SetEndpointSource(ctx, endpoint.Source)
  106. ctx = smithyhttp.SetHostnameImmutable(ctx, endpoint.HostnameImmutable)
  107. ctx = awsmiddleware.SetSigningRegion(ctx, endpoint.SigningRegion)
  108. ctx = awsmiddleware.SetPartitionID(ctx, endpoint.PartitionID)
  109. return next.HandleSerialize(ctx, in)
  110. }
  111. func addResolveEndpointMiddleware(stack *middleware.Stack, o Options) error {
  112. return stack.Serialize.Insert(&ResolveEndpoint{
  113. Resolver: o.EndpointResolver,
  114. Options: o.EndpointOptions,
  115. }, "OperationSerializer", middleware.Before)
  116. }
  117. func removeResolveEndpointMiddleware(stack *middleware.Stack) error {
  118. _, err := stack.Serialize.Remove((&ResolveEndpoint{}).ID())
  119. return err
  120. }
  121. type wrappedEndpointResolver struct {
  122. awsResolver aws.EndpointResolverWithOptions
  123. }
  124. func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
  125. return w.awsResolver.ResolveEndpoint(ServiceID, region, options)
  126. }
  127. type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error)
  128. func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) {
  129. return a(service, region)
  130. }
  131. var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil)
  132. // withEndpointResolver returns an aws.EndpointResolverWithOptions that first delegates endpoint resolution to the awsResolver.
  133. // If awsResolver returns aws.EndpointNotFoundError error, the v1 resolver middleware will swallow the error,
  134. // and set an appropriate context flag such that fallback will occur when EndpointResolverV2 is invoked
  135. // via its middleware.
  136. //
  137. // If another error (besides aws.EndpointNotFoundError) is returned, then that error will be propagated.
  138. func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions) EndpointResolver {
  139. var resolver aws.EndpointResolverWithOptions
  140. if awsResolverWithOptions != nil {
  141. resolver = awsResolverWithOptions
  142. } else if awsResolver != nil {
  143. resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint)
  144. }
  145. return &wrappedEndpointResolver{
  146. awsResolver: resolver,
  147. }
  148. }
  149. func finalizeClientEndpointResolverOptions(options *Options) {
  150. options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage()
  151. if len(options.EndpointOptions.ResolvedRegion) == 0 {
  152. const fipsInfix = "-fips-"
  153. const fipsPrefix = "fips-"
  154. const fipsSuffix = "-fips"
  155. if strings.Contains(options.Region, fipsInfix) ||
  156. strings.Contains(options.Region, fipsPrefix) ||
  157. strings.Contains(options.Region, fipsSuffix) {
  158. options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(
  159. options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "")
  160. options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled
  161. }
  162. }
  163. }
  164. func resolveEndpointResolverV2(options *Options) {
  165. if options.EndpointResolverV2 == nil {
  166. options.EndpointResolverV2 = NewDefaultEndpointResolverV2()
  167. }
  168. }
  169. func resolveBaseEndpoint(cfg aws.Config, o *Options) {
  170. if cfg.BaseEndpoint != nil {
  171. o.BaseEndpoint = cfg.BaseEndpoint
  172. }
  173. _, g := os.LookupEnv("AWS_ENDPOINT_URL")
  174. _, s := os.LookupEnv("AWS_ENDPOINT_URL_STS")
  175. if g && !s {
  176. return
  177. }
  178. value, found, err := internalConfig.ResolveServiceBaseEndpoint(context.Background(), "STS", cfg.ConfigSources)
  179. if found && err == nil {
  180. o.BaseEndpoint = &value
  181. }
  182. }
  183. func bindRegion(region string) *string {
  184. if region == "" {
  185. return nil
  186. }
  187. return aws.String(endpoints.MapFIPSRegion(region))
  188. }
  189. // EndpointParameters provides the parameters that influence how endpoints are
  190. // resolved.
  191. type EndpointParameters struct {
  192. // The AWS region used to dispatch the request.
  193. //
  194. // Parameter is
  195. // required.
  196. //
  197. // AWS::Region
  198. Region *string
  199. // When true, use the dual-stack endpoint. If the configured endpoint does not
  200. // support dual-stack, dispatching the request MAY return an error.
  201. //
  202. // Defaults to
  203. // false if no value is provided.
  204. //
  205. // AWS::UseDualStack
  206. UseDualStack *bool
  207. // When true, send this request to the FIPS-compliant regional endpoint. If the
  208. // configured endpoint does not have a FIPS compliant endpoint, dispatching the
  209. // request will return an error.
  210. //
  211. // Defaults to false if no value is
  212. // provided.
  213. //
  214. // AWS::UseFIPS
  215. UseFIPS *bool
  216. // Override the endpoint used to send this request
  217. //
  218. // Parameter is
  219. // required.
  220. //
  221. // SDK::Endpoint
  222. Endpoint *string
  223. // Whether the global endpoint should be used, rather then the regional endpoint
  224. // for us-east-1.
  225. //
  226. // Defaults to false if no value is
  227. // provided.
  228. //
  229. // AWS::STS::UseGlobalEndpoint
  230. UseGlobalEndpoint *bool
  231. }
  232. // ValidateRequired validates required parameters are set.
  233. func (p EndpointParameters) ValidateRequired() error {
  234. if p.UseDualStack == nil {
  235. return fmt.Errorf("parameter UseDualStack is required")
  236. }
  237. if p.UseFIPS == nil {
  238. return fmt.Errorf("parameter UseFIPS is required")
  239. }
  240. if p.UseGlobalEndpoint == nil {
  241. return fmt.Errorf("parameter UseGlobalEndpoint is required")
  242. }
  243. return nil
  244. }
  245. // WithDefaults returns a shallow copy of EndpointParameterswith default values
  246. // applied to members where applicable.
  247. func (p EndpointParameters) WithDefaults() EndpointParameters {
  248. if p.UseDualStack == nil {
  249. p.UseDualStack = ptr.Bool(false)
  250. }
  251. if p.UseFIPS == nil {
  252. p.UseFIPS = ptr.Bool(false)
  253. }
  254. if p.UseGlobalEndpoint == nil {
  255. p.UseGlobalEndpoint = ptr.Bool(false)
  256. }
  257. return p
  258. }
  259. type stringSlice []string
  260. func (s stringSlice) Get(i int) *string {
  261. if i < 0 || i >= len(s) {
  262. return nil
  263. }
  264. v := s[i]
  265. return &v
  266. }
  267. // EndpointResolverV2 provides the interface for resolving service endpoints.
  268. type EndpointResolverV2 interface {
  269. // ResolveEndpoint attempts to resolve the endpoint with the provided options,
  270. // returning the endpoint if found. Otherwise an error is returned.
  271. ResolveEndpoint(ctx context.Context, params EndpointParameters) (
  272. smithyendpoints.Endpoint, error,
  273. )
  274. }
  275. // resolver provides the implementation for resolving endpoints.
  276. type resolver struct{}
  277. func NewDefaultEndpointResolverV2() EndpointResolverV2 {
  278. return &resolver{}
  279. }
  280. // ResolveEndpoint attempts to resolve the endpoint with the provided options,
  281. // returning the endpoint if found. Otherwise an error is returned.
  282. func (r *resolver) ResolveEndpoint(
  283. ctx context.Context, params EndpointParameters,
  284. ) (
  285. endpoint smithyendpoints.Endpoint, err error,
  286. ) {
  287. params = params.WithDefaults()
  288. if err = params.ValidateRequired(); err != nil {
  289. return endpoint, fmt.Errorf("endpoint parameters are not valid, %w", err)
  290. }
  291. _UseDualStack := *params.UseDualStack
  292. _ = _UseDualStack
  293. _UseFIPS := *params.UseFIPS
  294. _ = _UseFIPS
  295. _UseGlobalEndpoint := *params.UseGlobalEndpoint
  296. _ = _UseGlobalEndpoint
  297. if _UseGlobalEndpoint == true {
  298. if !(params.Endpoint != nil) {
  299. if exprVal := params.Region; exprVal != nil {
  300. _Region := *exprVal
  301. _ = _Region
  302. if exprVal := awsrulesfn.GetPartition(_Region); exprVal != nil {
  303. _PartitionResult := *exprVal
  304. _ = _PartitionResult
  305. if _UseFIPS == false {
  306. if _UseDualStack == false {
  307. if _Region == "ap-northeast-1" {
  308. uriString := "https://sts.amazonaws.com"
  309. uri, err := url.Parse(uriString)
  310. if err != nil {
  311. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  312. }
  313. return smithyendpoints.Endpoint{
  314. URI: *uri,
  315. Headers: http.Header{},
  316. Properties: func() smithy.Properties {
  317. var out smithy.Properties
  318. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  319. {
  320. SchemeID: "aws.auth#sigv4",
  321. SignerProperties: func() smithy.Properties {
  322. var sp smithy.Properties
  323. smithyhttp.SetSigV4SigningName(&sp, "sts")
  324. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  325. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  326. return sp
  327. }(),
  328. },
  329. })
  330. return out
  331. }(),
  332. }, nil
  333. }
  334. if _Region == "ap-south-1" {
  335. uriString := "https://sts.amazonaws.com"
  336. uri, err := url.Parse(uriString)
  337. if err != nil {
  338. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  339. }
  340. return smithyendpoints.Endpoint{
  341. URI: *uri,
  342. Headers: http.Header{},
  343. Properties: func() smithy.Properties {
  344. var out smithy.Properties
  345. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  346. {
  347. SchemeID: "aws.auth#sigv4",
  348. SignerProperties: func() smithy.Properties {
  349. var sp smithy.Properties
  350. smithyhttp.SetSigV4SigningName(&sp, "sts")
  351. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  352. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  353. return sp
  354. }(),
  355. },
  356. })
  357. return out
  358. }(),
  359. }, nil
  360. }
  361. if _Region == "ap-southeast-1" {
  362. uriString := "https://sts.amazonaws.com"
  363. uri, err := url.Parse(uriString)
  364. if err != nil {
  365. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  366. }
  367. return smithyendpoints.Endpoint{
  368. URI: *uri,
  369. Headers: http.Header{},
  370. Properties: func() smithy.Properties {
  371. var out smithy.Properties
  372. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  373. {
  374. SchemeID: "aws.auth#sigv4",
  375. SignerProperties: func() smithy.Properties {
  376. var sp smithy.Properties
  377. smithyhttp.SetSigV4SigningName(&sp, "sts")
  378. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  379. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  380. return sp
  381. }(),
  382. },
  383. })
  384. return out
  385. }(),
  386. }, nil
  387. }
  388. if _Region == "ap-southeast-2" {
  389. uriString := "https://sts.amazonaws.com"
  390. uri, err := url.Parse(uriString)
  391. if err != nil {
  392. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  393. }
  394. return smithyendpoints.Endpoint{
  395. URI: *uri,
  396. Headers: http.Header{},
  397. Properties: func() smithy.Properties {
  398. var out smithy.Properties
  399. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  400. {
  401. SchemeID: "aws.auth#sigv4",
  402. SignerProperties: func() smithy.Properties {
  403. var sp smithy.Properties
  404. smithyhttp.SetSigV4SigningName(&sp, "sts")
  405. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  406. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  407. return sp
  408. }(),
  409. },
  410. })
  411. return out
  412. }(),
  413. }, nil
  414. }
  415. if _Region == "aws-global" {
  416. uriString := "https://sts.amazonaws.com"
  417. uri, err := url.Parse(uriString)
  418. if err != nil {
  419. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  420. }
  421. return smithyendpoints.Endpoint{
  422. URI: *uri,
  423. Headers: http.Header{},
  424. Properties: func() smithy.Properties {
  425. var out smithy.Properties
  426. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  427. {
  428. SchemeID: "aws.auth#sigv4",
  429. SignerProperties: func() smithy.Properties {
  430. var sp smithy.Properties
  431. smithyhttp.SetSigV4SigningName(&sp, "sts")
  432. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  433. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  434. return sp
  435. }(),
  436. },
  437. })
  438. return out
  439. }(),
  440. }, nil
  441. }
  442. if _Region == "ca-central-1" {
  443. uriString := "https://sts.amazonaws.com"
  444. uri, err := url.Parse(uriString)
  445. if err != nil {
  446. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  447. }
  448. return smithyendpoints.Endpoint{
  449. URI: *uri,
  450. Headers: http.Header{},
  451. Properties: func() smithy.Properties {
  452. var out smithy.Properties
  453. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  454. {
  455. SchemeID: "aws.auth#sigv4",
  456. SignerProperties: func() smithy.Properties {
  457. var sp smithy.Properties
  458. smithyhttp.SetSigV4SigningName(&sp, "sts")
  459. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  460. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  461. return sp
  462. }(),
  463. },
  464. })
  465. return out
  466. }(),
  467. }, nil
  468. }
  469. if _Region == "eu-central-1" {
  470. uriString := "https://sts.amazonaws.com"
  471. uri, err := url.Parse(uriString)
  472. if err != nil {
  473. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  474. }
  475. return smithyendpoints.Endpoint{
  476. URI: *uri,
  477. Headers: http.Header{},
  478. Properties: func() smithy.Properties {
  479. var out smithy.Properties
  480. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  481. {
  482. SchemeID: "aws.auth#sigv4",
  483. SignerProperties: func() smithy.Properties {
  484. var sp smithy.Properties
  485. smithyhttp.SetSigV4SigningName(&sp, "sts")
  486. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  487. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  488. return sp
  489. }(),
  490. },
  491. })
  492. return out
  493. }(),
  494. }, nil
  495. }
  496. if _Region == "eu-north-1" {
  497. uriString := "https://sts.amazonaws.com"
  498. uri, err := url.Parse(uriString)
  499. if err != nil {
  500. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  501. }
  502. return smithyendpoints.Endpoint{
  503. URI: *uri,
  504. Headers: http.Header{},
  505. Properties: func() smithy.Properties {
  506. var out smithy.Properties
  507. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  508. {
  509. SchemeID: "aws.auth#sigv4",
  510. SignerProperties: func() smithy.Properties {
  511. var sp smithy.Properties
  512. smithyhttp.SetSigV4SigningName(&sp, "sts")
  513. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  514. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  515. return sp
  516. }(),
  517. },
  518. })
  519. return out
  520. }(),
  521. }, nil
  522. }
  523. if _Region == "eu-west-1" {
  524. uriString := "https://sts.amazonaws.com"
  525. uri, err := url.Parse(uriString)
  526. if err != nil {
  527. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  528. }
  529. return smithyendpoints.Endpoint{
  530. URI: *uri,
  531. Headers: http.Header{},
  532. Properties: func() smithy.Properties {
  533. var out smithy.Properties
  534. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  535. {
  536. SchemeID: "aws.auth#sigv4",
  537. SignerProperties: func() smithy.Properties {
  538. var sp smithy.Properties
  539. smithyhttp.SetSigV4SigningName(&sp, "sts")
  540. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  541. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  542. return sp
  543. }(),
  544. },
  545. })
  546. return out
  547. }(),
  548. }, nil
  549. }
  550. if _Region == "eu-west-2" {
  551. uriString := "https://sts.amazonaws.com"
  552. uri, err := url.Parse(uriString)
  553. if err != nil {
  554. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  555. }
  556. return smithyendpoints.Endpoint{
  557. URI: *uri,
  558. Headers: http.Header{},
  559. Properties: func() smithy.Properties {
  560. var out smithy.Properties
  561. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  562. {
  563. SchemeID: "aws.auth#sigv4",
  564. SignerProperties: func() smithy.Properties {
  565. var sp smithy.Properties
  566. smithyhttp.SetSigV4SigningName(&sp, "sts")
  567. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  568. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  569. return sp
  570. }(),
  571. },
  572. })
  573. return out
  574. }(),
  575. }, nil
  576. }
  577. if _Region == "eu-west-3" {
  578. uriString := "https://sts.amazonaws.com"
  579. uri, err := url.Parse(uriString)
  580. if err != nil {
  581. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  582. }
  583. return smithyendpoints.Endpoint{
  584. URI: *uri,
  585. Headers: http.Header{},
  586. Properties: func() smithy.Properties {
  587. var out smithy.Properties
  588. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  589. {
  590. SchemeID: "aws.auth#sigv4",
  591. SignerProperties: func() smithy.Properties {
  592. var sp smithy.Properties
  593. smithyhttp.SetSigV4SigningName(&sp, "sts")
  594. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  595. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  596. return sp
  597. }(),
  598. },
  599. })
  600. return out
  601. }(),
  602. }, nil
  603. }
  604. if _Region == "sa-east-1" {
  605. uriString := "https://sts.amazonaws.com"
  606. uri, err := url.Parse(uriString)
  607. if err != nil {
  608. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  609. }
  610. return smithyendpoints.Endpoint{
  611. URI: *uri,
  612. Headers: http.Header{},
  613. Properties: func() smithy.Properties {
  614. var out smithy.Properties
  615. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  616. {
  617. SchemeID: "aws.auth#sigv4",
  618. SignerProperties: func() smithy.Properties {
  619. var sp smithy.Properties
  620. smithyhttp.SetSigV4SigningName(&sp, "sts")
  621. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  622. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  623. return sp
  624. }(),
  625. },
  626. })
  627. return out
  628. }(),
  629. }, nil
  630. }
  631. if _Region == "us-east-1" {
  632. uriString := "https://sts.amazonaws.com"
  633. uri, err := url.Parse(uriString)
  634. if err != nil {
  635. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  636. }
  637. return smithyendpoints.Endpoint{
  638. URI: *uri,
  639. Headers: http.Header{},
  640. Properties: func() smithy.Properties {
  641. var out smithy.Properties
  642. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  643. {
  644. SchemeID: "aws.auth#sigv4",
  645. SignerProperties: func() smithy.Properties {
  646. var sp smithy.Properties
  647. smithyhttp.SetSigV4SigningName(&sp, "sts")
  648. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  649. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  650. return sp
  651. }(),
  652. },
  653. })
  654. return out
  655. }(),
  656. }, nil
  657. }
  658. if _Region == "us-east-2" {
  659. uriString := "https://sts.amazonaws.com"
  660. uri, err := url.Parse(uriString)
  661. if err != nil {
  662. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  663. }
  664. return smithyendpoints.Endpoint{
  665. URI: *uri,
  666. Headers: http.Header{},
  667. Properties: func() smithy.Properties {
  668. var out smithy.Properties
  669. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  670. {
  671. SchemeID: "aws.auth#sigv4",
  672. SignerProperties: func() smithy.Properties {
  673. var sp smithy.Properties
  674. smithyhttp.SetSigV4SigningName(&sp, "sts")
  675. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  676. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  677. return sp
  678. }(),
  679. },
  680. })
  681. return out
  682. }(),
  683. }, nil
  684. }
  685. if _Region == "us-west-1" {
  686. uriString := "https://sts.amazonaws.com"
  687. uri, err := url.Parse(uriString)
  688. if err != nil {
  689. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  690. }
  691. return smithyendpoints.Endpoint{
  692. URI: *uri,
  693. Headers: http.Header{},
  694. Properties: func() smithy.Properties {
  695. var out smithy.Properties
  696. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  697. {
  698. SchemeID: "aws.auth#sigv4",
  699. SignerProperties: func() smithy.Properties {
  700. var sp smithy.Properties
  701. smithyhttp.SetSigV4SigningName(&sp, "sts")
  702. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  703. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  704. return sp
  705. }(),
  706. },
  707. })
  708. return out
  709. }(),
  710. }, nil
  711. }
  712. if _Region == "us-west-2" {
  713. uriString := "https://sts.amazonaws.com"
  714. uri, err := url.Parse(uriString)
  715. if err != nil {
  716. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  717. }
  718. return smithyendpoints.Endpoint{
  719. URI: *uri,
  720. Headers: http.Header{},
  721. Properties: func() smithy.Properties {
  722. var out smithy.Properties
  723. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  724. {
  725. SchemeID: "aws.auth#sigv4",
  726. SignerProperties: func() smithy.Properties {
  727. var sp smithy.Properties
  728. smithyhttp.SetSigV4SigningName(&sp, "sts")
  729. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  730. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  731. return sp
  732. }(),
  733. },
  734. })
  735. return out
  736. }(),
  737. }, nil
  738. }
  739. uriString := func() string {
  740. var out strings.Builder
  741. out.WriteString("https://sts.")
  742. out.WriteString(_Region)
  743. out.WriteString(".")
  744. out.WriteString(_PartitionResult.DnsSuffix)
  745. return out.String()
  746. }()
  747. uri, err := url.Parse(uriString)
  748. if err != nil {
  749. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  750. }
  751. return smithyendpoints.Endpoint{
  752. URI: *uri,
  753. Headers: http.Header{},
  754. Properties: func() smithy.Properties {
  755. var out smithy.Properties
  756. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  757. {
  758. SchemeID: "aws.auth#sigv4",
  759. SignerProperties: func() smithy.Properties {
  760. var sp smithy.Properties
  761. smithyhttp.SetSigV4SigningName(&sp, "sts")
  762. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  763. smithyhttp.SetSigV4SigningRegion(&sp, _Region)
  764. return sp
  765. }(),
  766. },
  767. })
  768. return out
  769. }(),
  770. }, nil
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. if exprVal := params.Endpoint; exprVal != nil {
  778. _Endpoint := *exprVal
  779. _ = _Endpoint
  780. if _UseFIPS == true {
  781. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: FIPS and custom endpoint are not supported")
  782. }
  783. if _UseDualStack == true {
  784. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Dualstack and custom endpoint are not supported")
  785. }
  786. uriString := _Endpoint
  787. uri, err := url.Parse(uriString)
  788. if err != nil {
  789. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  790. }
  791. return smithyendpoints.Endpoint{
  792. URI: *uri,
  793. Headers: http.Header{},
  794. }, nil
  795. }
  796. if exprVal := params.Region; exprVal != nil {
  797. _Region := *exprVal
  798. _ = _Region
  799. if exprVal := awsrulesfn.GetPartition(_Region); exprVal != nil {
  800. _PartitionResult := *exprVal
  801. _ = _PartitionResult
  802. if _UseFIPS == true {
  803. if _UseDualStack == true {
  804. if true == _PartitionResult.SupportsFIPS {
  805. if true == _PartitionResult.SupportsDualStack {
  806. uriString := func() string {
  807. var out strings.Builder
  808. out.WriteString("https://sts-fips.")
  809. out.WriteString(_Region)
  810. out.WriteString(".")
  811. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  812. return out.String()
  813. }()
  814. uri, err := url.Parse(uriString)
  815. if err != nil {
  816. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  817. }
  818. return smithyendpoints.Endpoint{
  819. URI: *uri,
  820. Headers: http.Header{},
  821. }, nil
  822. }
  823. }
  824. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS and DualStack are enabled, but this partition does not support one or both")
  825. }
  826. }
  827. if _UseFIPS == true {
  828. if _PartitionResult.SupportsFIPS == true {
  829. if _PartitionResult.Name == "aws-us-gov" {
  830. uriString := func() string {
  831. var out strings.Builder
  832. out.WriteString("https://sts.")
  833. out.WriteString(_Region)
  834. out.WriteString(".amazonaws.com")
  835. return out.String()
  836. }()
  837. uri, err := url.Parse(uriString)
  838. if err != nil {
  839. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  840. }
  841. return smithyendpoints.Endpoint{
  842. URI: *uri,
  843. Headers: http.Header{},
  844. }, nil
  845. }
  846. uriString := func() string {
  847. var out strings.Builder
  848. out.WriteString("https://sts-fips.")
  849. out.WriteString(_Region)
  850. out.WriteString(".")
  851. out.WriteString(_PartitionResult.DnsSuffix)
  852. return out.String()
  853. }()
  854. uri, err := url.Parse(uriString)
  855. if err != nil {
  856. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  857. }
  858. return smithyendpoints.Endpoint{
  859. URI: *uri,
  860. Headers: http.Header{},
  861. }, nil
  862. }
  863. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS is enabled but this partition does not support FIPS")
  864. }
  865. if _UseDualStack == true {
  866. if true == _PartitionResult.SupportsDualStack {
  867. uriString := func() string {
  868. var out strings.Builder
  869. out.WriteString("https://sts.")
  870. out.WriteString(_Region)
  871. out.WriteString(".")
  872. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  873. return out.String()
  874. }()
  875. uri, err := url.Parse(uriString)
  876. if err != nil {
  877. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  878. }
  879. return smithyendpoints.Endpoint{
  880. URI: *uri,
  881. Headers: http.Header{},
  882. }, nil
  883. }
  884. return endpoint, fmt.Errorf("endpoint rule error, %s", "DualStack is enabled but this partition does not support DualStack")
  885. }
  886. if _Region == "aws-global" {
  887. uriString := "https://sts.amazonaws.com"
  888. uri, err := url.Parse(uriString)
  889. if err != nil {
  890. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  891. }
  892. return smithyendpoints.Endpoint{
  893. URI: *uri,
  894. Headers: http.Header{},
  895. Properties: func() smithy.Properties {
  896. var out smithy.Properties
  897. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  898. {
  899. SchemeID: "aws.auth#sigv4",
  900. SignerProperties: func() smithy.Properties {
  901. var sp smithy.Properties
  902. smithyhttp.SetSigV4SigningName(&sp, "sts")
  903. smithyhttp.SetSigV4ASigningName(&sp, "sts")
  904. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  905. return sp
  906. }(),
  907. },
  908. })
  909. return out
  910. }(),
  911. }, nil
  912. }
  913. uriString := func() string {
  914. var out strings.Builder
  915. out.WriteString("https://sts.")
  916. out.WriteString(_Region)
  917. out.WriteString(".")
  918. out.WriteString(_PartitionResult.DnsSuffix)
  919. return out.String()
  920. }()
  921. uri, err := url.Parse(uriString)
  922. if err != nil {
  923. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  924. }
  925. return smithyendpoints.Endpoint{
  926. URI: *uri,
  927. Headers: http.Header{},
  928. }, nil
  929. }
  930. return endpoint, fmt.Errorf("Endpoint resolution failed. Invalid operation or environment input.")
  931. }
  932. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Missing Region")
  933. }
  934. type endpointParamsBinder interface {
  935. bindEndpointParams(*EndpointParameters)
  936. }
  937. func bindEndpointParams(ctx context.Context, input interface{}, options Options) *EndpointParameters {
  938. params := &EndpointParameters{}
  939. params.Region = bindRegion(options.Region)
  940. params.UseDualStack = aws.Bool(options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled)
  941. params.UseFIPS = aws.Bool(options.EndpointOptions.UseFIPSEndpoint == aws.FIPSEndpointStateEnabled)
  942. params.Endpoint = options.BaseEndpoint
  943. if b, ok := input.(endpointParamsBinder); ok {
  944. b.bindEndpointParams(params)
  945. }
  946. return params
  947. }
  948. type resolveEndpointV2Middleware struct {
  949. options Options
  950. }
  951. func (*resolveEndpointV2Middleware) ID() string {
  952. return "ResolveEndpointV2"
  953. }
  954. func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
  955. out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
  956. ) {
  957. _, span := tracing.StartSpan(ctx, "ResolveEndpoint")
  958. defer span.End()
  959. if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
  960. return next.HandleFinalize(ctx, in)
  961. }
  962. req, ok := in.Request.(*smithyhttp.Request)
  963. if !ok {
  964. return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
  965. }
  966. if m.options.EndpointResolverV2 == nil {
  967. return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
  968. }
  969. params := bindEndpointParams(ctx, getOperationInput(ctx), m.options)
  970. endpt, err := timeOperationMetric(ctx, "client.call.resolve_endpoint_duration",
  971. func() (smithyendpoints.Endpoint, error) {
  972. return m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
  973. })
  974. if err != nil {
  975. return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
  976. }
  977. span.SetProperty("client.call.resolved_endpoint", endpt.URI.String())
  978. if endpt.URI.RawPath == "" && req.URL.RawPath != "" {
  979. endpt.URI.RawPath = endpt.URI.Path
  980. }
  981. req.URL.Scheme = endpt.URI.Scheme
  982. req.URL.Host = endpt.URI.Host
  983. req.URL.Path = smithyhttp.JoinPath(endpt.URI.Path, req.URL.Path)
  984. req.URL.RawPath = smithyhttp.JoinPath(endpt.URI.RawPath, req.URL.RawPath)
  985. for k := range endpt.Headers {
  986. req.Header.Set(k, endpt.Headers.Get(k))
  987. }
  988. rscheme := getResolvedAuthScheme(ctx)
  989. if rscheme == nil {
  990. return out, metadata, fmt.Errorf("no resolved auth scheme")
  991. }
  992. opts, _ := smithyauth.GetAuthOptions(&endpt.Properties)
  993. for _, o := range opts {
  994. rscheme.SignerProperties.SetAll(&o.SignerProperties)
  995. }
  996. span.End()
  997. return next.HandleFinalize(ctx, in)
  998. }