endpoints.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package organizations
  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/organizations/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 = "organizations"
  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_ORGANIZATIONS")
  176. if g && !s {
  177. return
  178. }
  179. value, found, err := internalConfig.ResolveServiceBaseEndpoint(context.Background(), "Organizations", 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. // The AWS region used to dispatch the request.
  197. //
  198. // Parameter is
  199. // required.
  200. //
  201. // AWS::Region
  202. Region *string
  203. // When true, use the dual-stack endpoint. If the configured endpoint does not
  204. // support dual-stack, dispatching the request MAY return an error.
  205. //
  206. // Defaults to
  207. // false if no value is provided.
  208. //
  209. // AWS::UseDualStack
  210. UseDualStack *bool
  211. // When true, send this request to the FIPS-compliant regional endpoint. If the
  212. // configured endpoint does not have a FIPS compliant endpoint, dispatching the
  213. // request will return an error.
  214. //
  215. // Defaults to false if no value is
  216. // provided.
  217. //
  218. // AWS::UseFIPS
  219. UseFIPS *bool
  220. // Override the endpoint used to send this request
  221. //
  222. // Parameter is
  223. // required.
  224. //
  225. // SDK::Endpoint
  226. Endpoint *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 == false {
  313. uriString := "https://organizations.us-east-1.amazonaws.com"
  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.SetSigV4SigningName(&sp, "organizations")
  329. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  330. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  331. return sp
  332. }(),
  333. },
  334. })
  335. return out
  336. }(),
  337. }, nil
  338. }
  339. }
  340. }
  341. if _PartitionResult.Name == "aws" {
  342. if _UseFIPS == true {
  343. if _UseDualStack == false {
  344. uriString := "https://organizations-fips.us-east-1.amazonaws.com"
  345. uri, err := url.Parse(uriString)
  346. if err != nil {
  347. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  348. }
  349. return smithyendpoints.Endpoint{
  350. URI: *uri,
  351. Headers: http.Header{},
  352. Properties: func() smithy.Properties {
  353. var out smithy.Properties
  354. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  355. {
  356. SchemeID: "aws.auth#sigv4",
  357. SignerProperties: func() smithy.Properties {
  358. var sp smithy.Properties
  359. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  360. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  361. smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
  362. return sp
  363. }(),
  364. },
  365. })
  366. return out
  367. }(),
  368. }, nil
  369. }
  370. }
  371. }
  372. if _PartitionResult.Name == "aws-cn" {
  373. if _UseFIPS == false {
  374. if _UseDualStack == false {
  375. uriString := "https://organizations.cn-northwest-1.amazonaws.com.cn"
  376. uri, err := url.Parse(uriString)
  377. if err != nil {
  378. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  379. }
  380. return smithyendpoints.Endpoint{
  381. URI: *uri,
  382. Headers: http.Header{},
  383. Properties: func() smithy.Properties {
  384. var out smithy.Properties
  385. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  386. {
  387. SchemeID: "aws.auth#sigv4",
  388. SignerProperties: func() smithy.Properties {
  389. var sp smithy.Properties
  390. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  391. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  392. smithyhttp.SetSigV4SigningRegion(&sp, "cn-northwest-1")
  393. return sp
  394. }(),
  395. },
  396. })
  397. return out
  398. }(),
  399. }, nil
  400. }
  401. }
  402. }
  403. if _PartitionResult.Name == "aws-us-gov" {
  404. if _UseFIPS == false {
  405. if _UseDualStack == false {
  406. uriString := "https://organizations.us-gov-west-1.amazonaws.com"
  407. uri, err := url.Parse(uriString)
  408. if err != nil {
  409. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  410. }
  411. return smithyendpoints.Endpoint{
  412. URI: *uri,
  413. Headers: http.Header{},
  414. Properties: func() smithy.Properties {
  415. var out smithy.Properties
  416. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  417. {
  418. SchemeID: "aws.auth#sigv4",
  419. SignerProperties: func() smithy.Properties {
  420. var sp smithy.Properties
  421. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  422. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  423. smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
  424. return sp
  425. }(),
  426. },
  427. })
  428. return out
  429. }(),
  430. }, nil
  431. }
  432. }
  433. }
  434. if _PartitionResult.Name == "aws-us-gov" {
  435. if _UseFIPS == true {
  436. if _UseDualStack == false {
  437. uriString := "https://organizations.us-gov-west-1.amazonaws.com"
  438. uri, err := url.Parse(uriString)
  439. if err != nil {
  440. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  441. }
  442. return smithyendpoints.Endpoint{
  443. URI: *uri,
  444. Headers: http.Header{},
  445. Properties: func() smithy.Properties {
  446. var out smithy.Properties
  447. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  448. {
  449. SchemeID: "aws.auth#sigv4",
  450. SignerProperties: func() smithy.Properties {
  451. var sp smithy.Properties
  452. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  453. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  454. smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
  455. return sp
  456. }(),
  457. },
  458. })
  459. return out
  460. }(),
  461. }, nil
  462. }
  463. }
  464. }
  465. if _PartitionResult.Name == "aws-iso" {
  466. if _UseFIPS == false {
  467. if _UseDualStack == false {
  468. uriString := "https://organizations.us-iso-east-1.c2s.ic.gov"
  469. uri, err := url.Parse(uriString)
  470. if err != nil {
  471. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  472. }
  473. return smithyendpoints.Endpoint{
  474. URI: *uri,
  475. Headers: http.Header{},
  476. Properties: func() smithy.Properties {
  477. var out smithy.Properties
  478. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  479. {
  480. SchemeID: "aws.auth#sigv4",
  481. SignerProperties: func() smithy.Properties {
  482. var sp smithy.Properties
  483. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  484. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  485. smithyhttp.SetSigV4SigningRegion(&sp, "us-iso-east-1")
  486. return sp
  487. }(),
  488. },
  489. })
  490. return out
  491. }(),
  492. }, nil
  493. }
  494. }
  495. }
  496. if _PartitionResult.Name == "aws-iso-b" {
  497. if _UseFIPS == false {
  498. if _UseDualStack == false {
  499. uriString := "https://organizations.us-isob-east-1.sc2s.sgov.gov"
  500. uri, err := url.Parse(uriString)
  501. if err != nil {
  502. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  503. }
  504. return smithyendpoints.Endpoint{
  505. URI: *uri,
  506. Headers: http.Header{},
  507. Properties: func() smithy.Properties {
  508. var out smithy.Properties
  509. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  510. {
  511. SchemeID: "aws.auth#sigv4",
  512. SignerProperties: func() smithy.Properties {
  513. var sp smithy.Properties
  514. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  515. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  516. smithyhttp.SetSigV4SigningRegion(&sp, "us-isob-east-1")
  517. return sp
  518. }(),
  519. },
  520. })
  521. return out
  522. }(),
  523. }, nil
  524. }
  525. }
  526. }
  527. if _PartitionResult.Name == "aws-iso-f" {
  528. if _UseFIPS == false {
  529. if _UseDualStack == false {
  530. uriString := "https://organizations.us-isof-south-1.csp.hci.ic.gov"
  531. uri, err := url.Parse(uriString)
  532. if err != nil {
  533. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  534. }
  535. return smithyendpoints.Endpoint{
  536. URI: *uri,
  537. Headers: http.Header{},
  538. Properties: func() smithy.Properties {
  539. var out smithy.Properties
  540. smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
  541. {
  542. SchemeID: "aws.auth#sigv4",
  543. SignerProperties: func() smithy.Properties {
  544. var sp smithy.Properties
  545. smithyhttp.SetSigV4SigningName(&sp, "organizations")
  546. smithyhttp.SetSigV4ASigningName(&sp, "organizations")
  547. smithyhttp.SetSigV4SigningRegion(&sp, "us-isof-south-1")
  548. return sp
  549. }(),
  550. },
  551. })
  552. return out
  553. }(),
  554. }, nil
  555. }
  556. }
  557. }
  558. if _UseFIPS == true {
  559. if _UseDualStack == true {
  560. if true == _PartitionResult.SupportsFIPS {
  561. if true == _PartitionResult.SupportsDualStack {
  562. uriString := func() string {
  563. var out strings.Builder
  564. out.WriteString("https://organizations-fips.")
  565. out.WriteString(_Region)
  566. out.WriteString(".")
  567. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  568. return out.String()
  569. }()
  570. uri, err := url.Parse(uriString)
  571. if err != nil {
  572. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  573. }
  574. return smithyendpoints.Endpoint{
  575. URI: *uri,
  576. Headers: http.Header{},
  577. }, nil
  578. }
  579. }
  580. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS and DualStack are enabled, but this partition does not support one or both")
  581. }
  582. }
  583. if _UseFIPS == true {
  584. if _PartitionResult.SupportsFIPS == true {
  585. uriString := func() string {
  586. var out strings.Builder
  587. out.WriteString("https://organizations-fips.")
  588. out.WriteString(_Region)
  589. out.WriteString(".")
  590. out.WriteString(_PartitionResult.DnsSuffix)
  591. return out.String()
  592. }()
  593. uri, err := url.Parse(uriString)
  594. if err != nil {
  595. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  596. }
  597. return smithyendpoints.Endpoint{
  598. URI: *uri,
  599. Headers: http.Header{},
  600. }, nil
  601. }
  602. return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS is enabled but this partition does not support FIPS")
  603. }
  604. if _UseDualStack == true {
  605. if true == _PartitionResult.SupportsDualStack {
  606. uriString := func() string {
  607. var out strings.Builder
  608. out.WriteString("https://organizations.")
  609. out.WriteString(_Region)
  610. out.WriteString(".")
  611. out.WriteString(_PartitionResult.DualStackDnsSuffix)
  612. return out.String()
  613. }()
  614. uri, err := url.Parse(uriString)
  615. if err != nil {
  616. return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
  617. }
  618. return smithyendpoints.Endpoint{
  619. URI: *uri,
  620. Headers: http.Header{},
  621. }, nil
  622. }
  623. return endpoint, fmt.Errorf("endpoint rule error, %s", "DualStack is enabled but this partition does not support DualStack")
  624. }
  625. uriString := func() string {
  626. var out strings.Builder
  627. out.WriteString("https://organizations.")
  628. out.WriteString(_Region)
  629. out.WriteString(".")
  630. out.WriteString(_PartitionResult.DnsSuffix)
  631. return out.String()
  632. }()
  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. }, nil
  641. }
  642. return endpoint, fmt.Errorf("Endpoint resolution failed. Invalid operation or environment input.")
  643. }
  644. return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Missing Region")
  645. }
  646. type endpointParamsBinder interface {
  647. bindEndpointParams(*EndpointParameters)
  648. }
  649. func bindEndpointParams(ctx context.Context, input interface{}, options Options) (*EndpointParameters, error) {
  650. params := &EndpointParameters{}
  651. region, err := bindRegion(options.Region)
  652. if err != nil {
  653. return nil, err
  654. }
  655. params.Region = region
  656. params.UseDualStack = aws.Bool(options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled)
  657. params.UseFIPS = aws.Bool(options.EndpointOptions.UseFIPSEndpoint == aws.FIPSEndpointStateEnabled)
  658. params.Endpoint = options.BaseEndpoint
  659. if b, ok := input.(endpointParamsBinder); ok {
  660. b.bindEndpointParams(params)
  661. }
  662. return params, nil
  663. }
  664. type resolveEndpointV2Middleware struct {
  665. options Options
  666. }
  667. func (*resolveEndpointV2Middleware) ID() string {
  668. return "ResolveEndpointV2"
  669. }
  670. func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
  671. out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
  672. ) {
  673. _, span := tracing.StartSpan(ctx, "ResolveEndpoint")
  674. defer span.End()
  675. if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
  676. return next.HandleFinalize(ctx, in)
  677. }
  678. req, ok := in.Request.(*smithyhttp.Request)
  679. if !ok {
  680. return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
  681. }
  682. if m.options.EndpointResolverV2 == nil {
  683. return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
  684. }
  685. params, err := bindEndpointParams(ctx, getOperationInput(ctx), m.options)
  686. if err != nil {
  687. return out, metadata, fmt.Errorf("failed to bind endpoint params, %w", err)
  688. }
  689. endpt, err := timeOperationMetric(ctx, "client.call.resolve_endpoint_duration",
  690. func() (smithyendpoints.Endpoint, error) {
  691. return m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
  692. })
  693. if err != nil {
  694. return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
  695. }
  696. span.SetProperty("client.call.resolved_endpoint", endpt.URI.String())
  697. if endpt.URI.RawPath == "" && req.URL.RawPath != "" {
  698. endpt.URI.RawPath = endpt.URI.Path
  699. }
  700. req.URL.Scheme = endpt.URI.Scheme
  701. req.URL.Host = endpt.URI.Host
  702. req.URL.Path = smithyhttp.JoinPath(endpt.URI.Path, req.URL.Path)
  703. req.URL.RawPath = smithyhttp.JoinPath(endpt.URI.RawPath, req.URL.RawPath)
  704. for k := range endpt.Headers {
  705. req.Header.Set(k, endpt.Headers.Get(k))
  706. }
  707. rscheme := getResolvedAuthScheme(ctx)
  708. if rscheme == nil {
  709. return out, metadata, fmt.Errorf("no resolved auth scheme")
  710. }
  711. opts, _ := smithyauth.GetAuthOptions(&endpt.Properties)
  712. for _, o := range opts {
  713. rscheme.SignerProperties.SetAll(&o.SignerProperties)
  714. }
  715. span.End()
  716. return next.HandleFinalize(ctx, in)
  717. }