endpoints.go raw

   1  // Code generated by smithy-go-codegen DO NOT EDIT.
   2  
   3  package route53
   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/route53/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 = "route53"
 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_ROUTE_53")
 211  
 212  	if g && !s {
 213  		return
 214  	}
 215  
 216  	value, found, err := internalConfig.ResolveServiceBaseEndpoint(context.Background(), "Route 53", 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  	// When true, use the dual-stack endpoint. If the configured endpoint does not
 237  	// support dual-stack, dispatching the request MAY return an error.
 238  	//
 239  	// Defaults to
 240  	// false if no value is provided.
 241  	//
 242  	// AWS::UseDualStack
 243  	UseDualStack *bool
 244  
 245  	// When true, send this request to the FIPS-compliant regional endpoint. If the
 246  	// configured endpoint does not have a FIPS compliant endpoint, dispatching the
 247  	// request will return an error.
 248  	//
 249  	// Defaults to false if no value is
 250  	// provided.
 251  	//
 252  	// AWS::UseFIPS
 253  	UseFIPS *bool
 254  
 255  	// Override the endpoint used to send this request
 256  	//
 257  	// Parameter is
 258  	// required.
 259  	//
 260  	// SDK::Endpoint
 261  	Endpoint *string
 262  
 263  	// The AWS region used to dispatch the request.
 264  	//
 265  	// Parameter is
 266  	// required.
 267  	//
 268  	// AWS::Region
 269  	Region *string
 270  }
 271  
 272  // ValidateRequired validates required parameters are set.
 273  func (p EndpointParameters) ValidateRequired() error {
 274  	if p.UseDualStack == nil {
 275  		return fmt.Errorf("parameter UseDualStack is required")
 276  	}
 277  
 278  	if p.UseFIPS == nil {
 279  		return fmt.Errorf("parameter UseFIPS is required")
 280  	}
 281  
 282  	return nil
 283  }
 284  
 285  // WithDefaults returns a shallow copy of EndpointParameterswith default values
 286  // applied to members where applicable.
 287  func (p EndpointParameters) WithDefaults() EndpointParameters {
 288  	if p.UseDualStack == nil {
 289  		p.UseDualStack = ptr.Bool(false)
 290  	}
 291  
 292  	if p.UseFIPS == nil {
 293  		p.UseFIPS = ptr.Bool(false)
 294  	}
 295  	return p
 296  }
 297  
 298  type stringSlice []string
 299  
 300  func (s stringSlice) Get(i int) *string {
 301  	if i < 0 || i >= len(s) {
 302  		return nil
 303  	}
 304  
 305  	v := s[i]
 306  	return &v
 307  }
 308  
 309  // EndpointResolverV2 provides the interface for resolving service endpoints.
 310  type EndpointResolverV2 interface {
 311  	// ResolveEndpoint attempts to resolve the endpoint with the provided options,
 312  	// returning the endpoint if found. Otherwise an error is returned.
 313  	ResolveEndpoint(ctx context.Context, params EndpointParameters) (
 314  		smithyendpoints.Endpoint, error,
 315  	)
 316  }
 317  
 318  // resolver provides the implementation for resolving endpoints.
 319  type resolver struct{}
 320  
 321  func NewDefaultEndpointResolverV2() EndpointResolverV2 {
 322  	return &resolver{}
 323  }
 324  
 325  // ResolveEndpoint attempts to resolve the endpoint with the provided options,
 326  // returning the endpoint if found. Otherwise an error is returned.
 327  func (r *resolver) ResolveEndpoint(
 328  	ctx context.Context, params EndpointParameters,
 329  ) (
 330  	endpoint smithyendpoints.Endpoint, err error,
 331  ) {
 332  	params = params.WithDefaults()
 333  	if err = params.ValidateRequired(); err != nil {
 334  		return endpoint, fmt.Errorf("endpoint parameters are not valid, %w", err)
 335  	}
 336  	_UseDualStack := *params.UseDualStack
 337  	_ = _UseDualStack
 338  	_UseFIPS := *params.UseFIPS
 339  	_ = _UseFIPS
 340  
 341  	if exprVal := params.Endpoint; exprVal != nil {
 342  		_Endpoint := *exprVal
 343  		_ = _Endpoint
 344  		if _UseFIPS == true {
 345  			return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: FIPS and custom endpoint are not supported")
 346  		}
 347  		if _UseDualStack == true {
 348  			return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Dualstack and custom endpoint are not supported")
 349  		}
 350  		uriString := _Endpoint
 351  
 352  		uri, err := url.Parse(uriString)
 353  		if err != nil {
 354  			return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 355  		}
 356  
 357  		return smithyendpoints.Endpoint{
 358  			URI:     *uri,
 359  			Headers: http.Header{},
 360  		}, nil
 361  	}
 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 _PartitionResult.Name == "aws" {
 369  				if _UseFIPS == false {
 370  					if _UseDualStack == false {
 371  						uriString := "https://route53.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.SetSigV4SigningRegion(&sp, "us-east-1")
 389  											return sp
 390  										}(),
 391  									},
 392  								})
 393  								return out
 394  							}(),
 395  						}, nil
 396  					}
 397  				}
 398  			}
 399  			if _PartitionResult.Name == "aws" {
 400  				if _UseFIPS == true {
 401  					if _UseDualStack == false {
 402  						uriString := "https://route53-fips.amazonaws.com"
 403  
 404  						uri, err := url.Parse(uriString)
 405  						if err != nil {
 406  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 407  						}
 408  
 409  						return smithyendpoints.Endpoint{
 410  							URI:     *uri,
 411  							Headers: http.Header{},
 412  							Properties: func() smithy.Properties {
 413  								var out smithy.Properties
 414  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 415  									{
 416  										SchemeID: "aws.auth#sigv4",
 417  										SignerProperties: func() smithy.Properties {
 418  											var sp smithy.Properties
 419  											smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
 420  											return sp
 421  										}(),
 422  									},
 423  								})
 424  								return out
 425  							}(),
 426  						}, nil
 427  					}
 428  				}
 429  			}
 430  			if _PartitionResult.Name == "aws" {
 431  				if _UseFIPS == false {
 432  					if _UseDualStack == true {
 433  						uriString := "https://route53.global.api.aws"
 434  
 435  						uri, err := url.Parse(uriString)
 436  						if err != nil {
 437  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 438  						}
 439  
 440  						return smithyendpoints.Endpoint{
 441  							URI:     *uri,
 442  							Headers: http.Header{},
 443  							Properties: func() smithy.Properties {
 444  								var out smithy.Properties
 445  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 446  									{
 447  										SchemeID: "aws.auth#sigv4",
 448  										SignerProperties: func() smithy.Properties {
 449  											var sp smithy.Properties
 450  											smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
 451  											return sp
 452  										}(),
 453  									},
 454  								})
 455  								return out
 456  							}(),
 457  						}, nil
 458  					}
 459  				}
 460  			}
 461  			if _PartitionResult.Name == "aws" {
 462  				if _UseFIPS == true {
 463  					if _UseDualStack == true {
 464  						uriString := "https://route53-fips.global.api.aws"
 465  
 466  						uri, err := url.Parse(uriString)
 467  						if err != nil {
 468  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 469  						}
 470  
 471  						return smithyendpoints.Endpoint{
 472  							URI:     *uri,
 473  							Headers: http.Header{},
 474  							Properties: func() smithy.Properties {
 475  								var out smithy.Properties
 476  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 477  									{
 478  										SchemeID: "aws.auth#sigv4",
 479  										SignerProperties: func() smithy.Properties {
 480  											var sp smithy.Properties
 481  											smithyhttp.SetSigV4SigningRegion(&sp, "us-east-1")
 482  											return sp
 483  										}(),
 484  									},
 485  								})
 486  								return out
 487  							}(),
 488  						}, nil
 489  					}
 490  				}
 491  			}
 492  			if _PartitionResult.Name == "aws-cn" {
 493  				if _UseFIPS == false {
 494  					if _UseDualStack == false {
 495  						uriString := "https://route53.amazonaws.com.cn"
 496  
 497  						uri, err := url.Parse(uriString)
 498  						if err != nil {
 499  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 500  						}
 501  
 502  						return smithyendpoints.Endpoint{
 503  							URI:     *uri,
 504  							Headers: http.Header{},
 505  							Properties: func() smithy.Properties {
 506  								var out smithy.Properties
 507  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 508  									{
 509  										SchemeID: "aws.auth#sigv4",
 510  										SignerProperties: func() smithy.Properties {
 511  											var sp smithy.Properties
 512  											smithyhttp.SetSigV4SigningRegion(&sp, "cn-northwest-1")
 513  											return sp
 514  										}(),
 515  									},
 516  								})
 517  								return out
 518  							}(),
 519  						}, nil
 520  					}
 521  				}
 522  			}
 523  			if _PartitionResult.Name == "aws-cn" {
 524  				if _UseFIPS == false {
 525  					if _UseDualStack == true {
 526  						uriString := "https://route53.global.api.amazonwebservices.com.cn"
 527  
 528  						uri, err := url.Parse(uriString)
 529  						if err != nil {
 530  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 531  						}
 532  
 533  						return smithyendpoints.Endpoint{
 534  							URI:     *uri,
 535  							Headers: http.Header{},
 536  							Properties: func() smithy.Properties {
 537  								var out smithy.Properties
 538  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 539  									{
 540  										SchemeID: "aws.auth#sigv4",
 541  										SignerProperties: func() smithy.Properties {
 542  											var sp smithy.Properties
 543  											smithyhttp.SetSigV4SigningRegion(&sp, "cn-northwest-1")
 544  											return sp
 545  										}(),
 546  									},
 547  								})
 548  								return out
 549  							}(),
 550  						}, nil
 551  					}
 552  				}
 553  			}
 554  			if _PartitionResult.Name == "aws-us-gov" {
 555  				if _UseFIPS == false {
 556  					if _UseDualStack == false {
 557  						uriString := "https://route53.us-gov.amazonaws.com"
 558  
 559  						uri, err := url.Parse(uriString)
 560  						if err != nil {
 561  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 562  						}
 563  
 564  						return smithyendpoints.Endpoint{
 565  							URI:     *uri,
 566  							Headers: http.Header{},
 567  							Properties: func() smithy.Properties {
 568  								var out smithy.Properties
 569  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 570  									{
 571  										SchemeID: "aws.auth#sigv4",
 572  										SignerProperties: func() smithy.Properties {
 573  											var sp smithy.Properties
 574  											smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
 575  											return sp
 576  										}(),
 577  									},
 578  								})
 579  								return out
 580  							}(),
 581  						}, nil
 582  					}
 583  				}
 584  			}
 585  			if _PartitionResult.Name == "aws-us-gov" {
 586  				if _UseFIPS == true {
 587  					if _UseDualStack == false {
 588  						uriString := "https://route53.us-gov.amazonaws.com"
 589  
 590  						uri, err := url.Parse(uriString)
 591  						if err != nil {
 592  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 593  						}
 594  
 595  						return smithyendpoints.Endpoint{
 596  							URI:     *uri,
 597  							Headers: http.Header{},
 598  							Properties: func() smithy.Properties {
 599  								var out smithy.Properties
 600  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 601  									{
 602  										SchemeID: "aws.auth#sigv4",
 603  										SignerProperties: func() smithy.Properties {
 604  											var sp smithy.Properties
 605  											smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
 606  											return sp
 607  										}(),
 608  									},
 609  								})
 610  								return out
 611  							}(),
 612  						}, nil
 613  					}
 614  				}
 615  			}
 616  			if _PartitionResult.Name == "aws-us-gov" {
 617  				if _UseFIPS == false {
 618  					if _UseDualStack == true {
 619  						uriString := "https://route53.us-gov.api.aws"
 620  
 621  						uri, err := url.Parse(uriString)
 622  						if err != nil {
 623  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 624  						}
 625  
 626  						return smithyendpoints.Endpoint{
 627  							URI:     *uri,
 628  							Headers: http.Header{},
 629  							Properties: func() smithy.Properties {
 630  								var out smithy.Properties
 631  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 632  									{
 633  										SchemeID: "aws.auth#sigv4",
 634  										SignerProperties: func() smithy.Properties {
 635  											var sp smithy.Properties
 636  											smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
 637  											return sp
 638  										}(),
 639  									},
 640  								})
 641  								return out
 642  							}(),
 643  						}, nil
 644  					}
 645  				}
 646  			}
 647  			if _PartitionResult.Name == "aws-us-gov" {
 648  				if _UseFIPS == true {
 649  					if _UseDualStack == true {
 650  						uriString := "https://route53.us-gov.api.aws"
 651  
 652  						uri, err := url.Parse(uriString)
 653  						if err != nil {
 654  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 655  						}
 656  
 657  						return smithyendpoints.Endpoint{
 658  							URI:     *uri,
 659  							Headers: http.Header{},
 660  							Properties: func() smithy.Properties {
 661  								var out smithy.Properties
 662  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 663  									{
 664  										SchemeID: "aws.auth#sigv4",
 665  										SignerProperties: func() smithy.Properties {
 666  											var sp smithy.Properties
 667  											smithyhttp.SetSigV4SigningRegion(&sp, "us-gov-west-1")
 668  											return sp
 669  										}(),
 670  									},
 671  								})
 672  								return out
 673  							}(),
 674  						}, nil
 675  					}
 676  				}
 677  			}
 678  			if _PartitionResult.Name == "aws-iso" {
 679  				if _UseFIPS == false {
 680  					if _UseDualStack == false {
 681  						uriString := "https://route53.c2s.ic.gov"
 682  
 683  						uri, err := url.Parse(uriString)
 684  						if err != nil {
 685  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 686  						}
 687  
 688  						return smithyendpoints.Endpoint{
 689  							URI:     *uri,
 690  							Headers: http.Header{},
 691  							Properties: func() smithy.Properties {
 692  								var out smithy.Properties
 693  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 694  									{
 695  										SchemeID: "aws.auth#sigv4",
 696  										SignerProperties: func() smithy.Properties {
 697  											var sp smithy.Properties
 698  											smithyhttp.SetSigV4SigningRegion(&sp, "us-iso-east-1")
 699  											return sp
 700  										}(),
 701  									},
 702  								})
 703  								return out
 704  							}(),
 705  						}, nil
 706  					}
 707  				}
 708  			}
 709  			if _PartitionResult.Name == "aws-iso-b" {
 710  				if _UseFIPS == false {
 711  					if _UseDualStack == false {
 712  						uriString := "https://route53.sc2s.sgov.gov"
 713  
 714  						uri, err := url.Parse(uriString)
 715  						if err != nil {
 716  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 717  						}
 718  
 719  						return smithyendpoints.Endpoint{
 720  							URI:     *uri,
 721  							Headers: http.Header{},
 722  							Properties: func() smithy.Properties {
 723  								var out smithy.Properties
 724  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 725  									{
 726  										SchemeID: "aws.auth#sigv4",
 727  										SignerProperties: func() smithy.Properties {
 728  											var sp smithy.Properties
 729  											smithyhttp.SetSigV4SigningRegion(&sp, "us-isob-east-1")
 730  											return sp
 731  										}(),
 732  									},
 733  								})
 734  								return out
 735  							}(),
 736  						}, nil
 737  					}
 738  				}
 739  			}
 740  			if _PartitionResult.Name == "aws-iso-e" {
 741  				if _UseFIPS == false {
 742  					if _UseDualStack == false {
 743  						uriString := "https://route53.cloud.adc-e.uk"
 744  
 745  						uri, err := url.Parse(uriString)
 746  						if err != nil {
 747  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 748  						}
 749  
 750  						return smithyendpoints.Endpoint{
 751  							URI:     *uri,
 752  							Headers: http.Header{},
 753  							Properties: func() smithy.Properties {
 754  								var out smithy.Properties
 755  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 756  									{
 757  										SchemeID: "aws.auth#sigv4",
 758  										SignerProperties: func() smithy.Properties {
 759  											var sp smithy.Properties
 760  											smithyhttp.SetSigV4SigningRegion(&sp, "eu-isoe-west-1")
 761  											return sp
 762  										}(),
 763  									},
 764  								})
 765  								return out
 766  							}(),
 767  						}, nil
 768  					}
 769  				}
 770  			}
 771  			if _PartitionResult.Name == "aws-iso-f" {
 772  				if _UseFIPS == false {
 773  					if _UseDualStack == false {
 774  						uriString := "https://route53.csp.hci.ic.gov"
 775  
 776  						uri, err := url.Parse(uriString)
 777  						if err != nil {
 778  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 779  						}
 780  
 781  						return smithyendpoints.Endpoint{
 782  							URI:     *uri,
 783  							Headers: http.Header{},
 784  							Properties: func() smithy.Properties {
 785  								var out smithy.Properties
 786  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 787  									{
 788  										SchemeID: "aws.auth#sigv4",
 789  										SignerProperties: func() smithy.Properties {
 790  											var sp smithy.Properties
 791  											smithyhttp.SetSigV4SigningRegion(&sp, "us-isof-south-1")
 792  											return sp
 793  										}(),
 794  									},
 795  								})
 796  								return out
 797  							}(),
 798  						}, nil
 799  					}
 800  				}
 801  			}
 802  			if _PartitionResult.Name == "aws-eusc" {
 803  				if _UseFIPS == false {
 804  					if _UseDualStack == false {
 805  						uriString := "https://route53.amazonaws.eu"
 806  
 807  						uri, err := url.Parse(uriString)
 808  						if err != nil {
 809  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 810  						}
 811  
 812  						return smithyendpoints.Endpoint{
 813  							URI:     *uri,
 814  							Headers: http.Header{},
 815  							Properties: func() smithy.Properties {
 816  								var out smithy.Properties
 817  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 818  									{
 819  										SchemeID: "aws.auth#sigv4",
 820  										SignerProperties: func() smithy.Properties {
 821  											var sp smithy.Properties
 822  											smithyhttp.SetSigV4SigningRegion(&sp, "eusc-de-east-1")
 823  											return sp
 824  										}(),
 825  									},
 826  								})
 827  								return out
 828  							}(),
 829  						}, nil
 830  					}
 831  				}
 832  			}
 833  			if _PartitionResult.Name == "aws-eusc" {
 834  				if _UseFIPS == false {
 835  					if _UseDualStack == true {
 836  						uriString := "https://route53.global.api.amazonwebservices.eu"
 837  
 838  						uri, err := url.Parse(uriString)
 839  						if err != nil {
 840  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 841  						}
 842  
 843  						return smithyendpoints.Endpoint{
 844  							URI:     *uri,
 845  							Headers: http.Header{},
 846  							Properties: func() smithy.Properties {
 847  								var out smithy.Properties
 848  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 849  									{
 850  										SchemeID: "aws.auth#sigv4",
 851  										SignerProperties: func() smithy.Properties {
 852  											var sp smithy.Properties
 853  											smithyhttp.SetSigV4SigningRegion(&sp, "eusc-de-east-1")
 854  											return sp
 855  										}(),
 856  									},
 857  								})
 858  								return out
 859  							}(),
 860  						}, nil
 861  					}
 862  				}
 863  			}
 864  			if _UseFIPS == true {
 865  				if _UseDualStack == true {
 866  					if true == _PartitionResult.SupportsFIPS {
 867  						if true == _PartitionResult.SupportsDualStack {
 868  							uriString := func() string {
 869  								var out strings.Builder
 870  								out.WriteString("https://route53-fips.")
 871  								out.WriteString(_PartitionResult.DualStackDnsSuffix)
 872  								return out.String()
 873  							}()
 874  
 875  							uri, err := url.Parse(uriString)
 876  							if err != nil {
 877  								return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 878  							}
 879  
 880  							return smithyendpoints.Endpoint{
 881  								URI:     *uri,
 882  								Headers: http.Header{},
 883  								Properties: func() smithy.Properties {
 884  									var out smithy.Properties
 885  									smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 886  										{
 887  											SchemeID: "aws.auth#sigv4",
 888  											SignerProperties: func() smithy.Properties {
 889  												var sp smithy.Properties
 890  												smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
 891  												return sp
 892  											}(),
 893  										},
 894  									})
 895  									return out
 896  								}(),
 897  							}, nil
 898  						}
 899  					}
 900  					return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS and DualStack are enabled, but this partition does not support one or both")
 901  				}
 902  			}
 903  			if _UseFIPS == true {
 904  				if _UseDualStack == false {
 905  					if _PartitionResult.SupportsFIPS == true {
 906  						uriString := func() string {
 907  							var out strings.Builder
 908  							out.WriteString("https://route53-fips.")
 909  							out.WriteString(_PartitionResult.DnsSuffix)
 910  							return out.String()
 911  						}()
 912  
 913  						uri, err := url.Parse(uriString)
 914  						if err != nil {
 915  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 916  						}
 917  
 918  						return smithyendpoints.Endpoint{
 919  							URI:     *uri,
 920  							Headers: http.Header{},
 921  							Properties: func() smithy.Properties {
 922  								var out smithy.Properties
 923  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 924  									{
 925  										SchemeID: "aws.auth#sigv4",
 926  										SignerProperties: func() smithy.Properties {
 927  											var sp smithy.Properties
 928  											smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
 929  											return sp
 930  										}(),
 931  									},
 932  								})
 933  								return out
 934  							}(),
 935  						}, nil
 936  					}
 937  					return endpoint, fmt.Errorf("endpoint rule error, %s", "FIPS is enabled but this partition does not support FIPS")
 938  				}
 939  			}
 940  			if _UseFIPS == false {
 941  				if _UseDualStack == true {
 942  					if true == _PartitionResult.SupportsDualStack {
 943  						uriString := func() string {
 944  							var out strings.Builder
 945  							out.WriteString("https://route53.")
 946  							out.WriteString(_PartitionResult.DualStackDnsSuffix)
 947  							return out.String()
 948  						}()
 949  
 950  						uri, err := url.Parse(uriString)
 951  						if err != nil {
 952  							return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 953  						}
 954  
 955  						return smithyendpoints.Endpoint{
 956  							URI:     *uri,
 957  							Headers: http.Header{},
 958  							Properties: func() smithy.Properties {
 959  								var out smithy.Properties
 960  								smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 961  									{
 962  										SchemeID: "aws.auth#sigv4",
 963  										SignerProperties: func() smithy.Properties {
 964  											var sp smithy.Properties
 965  											smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
 966  											return sp
 967  										}(),
 968  									},
 969  								})
 970  								return out
 971  							}(),
 972  						}, nil
 973  					}
 974  					return endpoint, fmt.Errorf("endpoint rule error, %s", "DualStack is enabled but this partition does not support DualStack")
 975  				}
 976  			}
 977  			uriString := func() string {
 978  				var out strings.Builder
 979  				out.WriteString("https://route53.")
 980  				out.WriteString(_PartitionResult.DnsSuffix)
 981  				return out.String()
 982  			}()
 983  
 984  			uri, err := url.Parse(uriString)
 985  			if err != nil {
 986  				return endpoint, fmt.Errorf("Failed to parse uri: %s", uriString)
 987  			}
 988  
 989  			return smithyendpoints.Endpoint{
 990  				URI:     *uri,
 991  				Headers: http.Header{},
 992  				Properties: func() smithy.Properties {
 993  					var out smithy.Properties
 994  					smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
 995  						{
 996  							SchemeID: "aws.auth#sigv4",
 997  							SignerProperties: func() smithy.Properties {
 998  								var sp smithy.Properties
 999  								smithyhttp.SetSigV4SigningRegion(&sp, _PartitionResult.ImplicitGlobalRegion)
1000  								return sp
1001  							}(),
1002  						},
1003  					})
1004  					return out
1005  				}(),
1006  			}, nil
1007  		}
1008  		return endpoint, fmt.Errorf("Endpoint resolution failed. Invalid operation or environment input.")
1009  	}
1010  	return endpoint, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Missing Region")
1011  }
1012  
1013  type endpointParamsBinder interface {
1014  	bindEndpointParams(*EndpointParameters)
1015  }
1016  
1017  func bindEndpointParams(ctx context.Context, input interface{}, options Options) (*EndpointParameters, error) {
1018  	params := &EndpointParameters{}
1019  
1020  	params.UseDualStack = aws.Bool(options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled)
1021  	params.UseFIPS = aws.Bool(options.EndpointOptions.UseFIPSEndpoint == aws.FIPSEndpointStateEnabled)
1022  	params.Endpoint = options.BaseEndpoint
1023  	region, err := bindRegion(options.Region)
1024  	if err != nil {
1025  		return nil, err
1026  	}
1027  	params.Region = region
1028  
1029  	if b, ok := input.(endpointParamsBinder); ok {
1030  		b.bindEndpointParams(params)
1031  	}
1032  
1033  	return params, nil
1034  }
1035  
1036  type resolveEndpointV2Middleware struct {
1037  	options Options
1038  }
1039  
1040  func (*resolveEndpointV2Middleware) ID() string {
1041  	return "ResolveEndpointV2"
1042  }
1043  
1044  func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
1045  	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
1046  ) {
1047  	_, span := tracing.StartSpan(ctx, "ResolveEndpoint")
1048  	defer span.End()
1049  
1050  	if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
1051  		return next.HandleFinalize(ctx, in)
1052  	}
1053  
1054  	req, ok := in.Request.(*smithyhttp.Request)
1055  	if !ok {
1056  		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
1057  	}
1058  
1059  	if m.options.EndpointResolverV2 == nil {
1060  		return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
1061  	}
1062  
1063  	params, err := bindEndpointParams(ctx, getOperationInput(ctx), m.options)
1064  	if err != nil {
1065  		return out, metadata, fmt.Errorf("failed to bind endpoint params, %w", err)
1066  	}
1067  	endpt, err := timeOperationMetric(ctx, "client.call.resolve_endpoint_duration",
1068  		func() (smithyendpoints.Endpoint, error) {
1069  			return m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
1070  		})
1071  	if err != nil {
1072  		return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
1073  	}
1074  
1075  	span.SetProperty("client.call.resolved_endpoint", endpt.URI.String())
1076  
1077  	if endpt.URI.RawPath == "" && req.URL.RawPath != "" {
1078  		endpt.URI.RawPath = endpt.URI.Path
1079  	}
1080  	req.URL.Scheme = endpt.URI.Scheme
1081  	req.URL.Host = endpt.URI.Host
1082  	req.URL.Path = smithyhttp.JoinPath(endpt.URI.Path, req.URL.Path)
1083  	req.URL.RawPath = smithyhttp.JoinPath(endpt.URI.RawPath, req.URL.RawPath)
1084  	for k := range endpt.Headers {
1085  		req.Header.Set(k, endpt.Headers.Get(k))
1086  	}
1087  
1088  	rscheme := getResolvedAuthScheme(ctx)
1089  	if rscheme == nil {
1090  		return out, metadata, fmt.Errorf("no resolved auth scheme")
1091  	}
1092  
1093  	opts, _ := smithyauth.GetAuthOptions(&endpt.Properties)
1094  	for _, o := range opts {
1095  		rscheme.SignerProperties.SetAll(&o.SignerProperties)
1096  	}
1097  
1098  	span.End()
1099  	return next.HandleFinalize(ctx, in)
1100  }
1101