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