...

Source file src/github.com/aws/aws-sdk-go-v2/service/sts/endpoints.go

Documentation: github.com/aws/aws-sdk-go-v2/service/sts

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

View as plain text