endpoints.go raw

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