src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

endpoints.go (27707B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package signin
      4 
      5 import (
      6 	"context"
      7 	"errors"
      8 	"fmt"
      9 	"net/http"
     10 	"net/url"
     11 	"os"
     12 	"strings"
     13 
     14 	"github.com/aws/aws-sdk-go-v2/aws"
     15 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
     16 	internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources"
     17 	"github.com/aws/aws-sdk-go-v2/internal/endpoints"
     18 	"github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn"
     19 	internalendpoints "github.com/aws/aws-sdk-go-v2/service/signin/internal/endpoints"
     20 	smithy "github.com/aws/smithy-go"
     21 	smithyauth "github.com/aws/smithy-go/auth"
     22 	smithyendpoints "github.com/aws/smithy-go/endpoints"
     23 	"github.com/aws/smithy-go/endpoints/private/bdd"
     24 	"github.com/aws/smithy-go/endpoints/private/rulesfn"
     25 	"github.com/aws/smithy-go/middleware"
     26 	"github.com/aws/smithy-go/ptr"
     27 	"github.com/aws/smithy-go/tracing"
     28 	smithyhttp "github.com/aws/smithy-go/transport/http"
     29 )
     30 
     31 // EndpointResolverOptions is the service endpoint resolver options
     32 type EndpointResolverOptions = internalendpoints.Options
     33 
     34 // EndpointResolver interface for resolving service endpoints.
     35 type EndpointResolver interface {
     36 	ResolveEndpoint(region string, options EndpointResolverOptions) (aws.Endpoint, error)
     37 }
     38 
     39 var _ EndpointResolver = &internalendpoints.Resolver{}
     40 
     41 // NewDefaultEndpointResolver constructs a new service endpoint resolver
     42 func NewDefaultEndpointResolver() *internalendpoints.Resolver {
     43 	return internalendpoints.New()
     44 }
     45 
     46 // EndpointResolverFunc is a helper utility that wraps a function so it satisfies
     47 // the EndpointResolver interface. This is useful when you want to add additional
     48 // endpoint resolving logic, or stub out specific endpoints with custom values.
     49 type EndpointResolverFunc func(region string, options EndpointResolverOptions) (aws.Endpoint, error)
     50 
     51 func (fn EndpointResolverFunc) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
     52 	return fn(region, options)
     53 }
     54 
     55 // EndpointResolverFromURL returns an EndpointResolver configured using the
     56 // provided endpoint url. By default, the resolved endpoint resolver uses the
     57 // client region as signing region, and the endpoint source is set to
     58 // EndpointSourceCustom.You can provide functional options to configure endpoint
     59 // values for the resolved endpoint.
     60 func EndpointResolverFromURL(url string, optFns ...func(*aws.Endpoint)) EndpointResolver {
     61 	e := aws.Endpoint{URL: url, Source: aws.EndpointSourceCustom}
     62 	for _, fn := range optFns {
     63 		fn(&e)
     64 	}
     65 
     66 	return EndpointResolverFunc(
     67 		func(region string, options EndpointResolverOptions) (aws.Endpoint, error) {
     68 			if len(e.SigningRegion) == 0 {
     69 				e.SigningRegion = region
     70 			}
     71 			return e, nil
     72 		},
     73 	)
     74 }
     75 
     76 type ResolveEndpoint struct {
     77 	Resolver EndpointResolver
     78 	Options  EndpointResolverOptions
     79 }
     80 
     81 func (*ResolveEndpoint) ID() string {
     82 	return "ResolveEndpoint"
     83 }
     84 
     85 func (m *ResolveEndpoint) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
     86 	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
     87 ) {
     88 	if !awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
     89 		return next.HandleSerialize(ctx, in)
     90 	}
     91 
     92 	req, ok := in.Request.(*smithyhttp.Request)
     93 	if !ok {
     94 		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
     95 	}
     96 
     97 	if m.Resolver == nil {
     98 		return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
     99 	}
    100 
    101 	eo := m.Options
    102 	eo.Logger = middleware.GetLogger(ctx)
    103 
    104 	var endpoint aws.Endpoint
    105 	endpoint, err = m.Resolver.ResolveEndpoint(awsmiddleware.GetRegion(ctx), eo)
    106 	if err != nil {
    107 		nf := (&aws.EndpointNotFoundError{})
    108 		if errors.As(err, &nf) {
    109 			ctx = awsmiddleware.SetRequiresLegacyEndpoints(ctx, false)
    110 			return next.HandleSerialize(ctx, in)
    111 		}
    112 		return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
    113 	}
    114 
    115 	req.URL, err = url.Parse(endpoint.URL)
    116 	if err != nil {
    117 		return out, metadata, fmt.Errorf("failed to parse endpoint URL: %w", err)
    118 	}
    119 
    120 	if len(awsmiddleware.GetSigningName(ctx)) == 0 {
    121 		signingName := endpoint.SigningName
    122 		if len(signingName) == 0 {
    123 			signingName = "signin"
    124 		}
    125 		ctx = awsmiddleware.SetSigningName(ctx, signingName)
    126 	}
    127 	ctx = awsmiddleware.SetEndpointSource(ctx, endpoint.Source)
    128 	ctx = smithyhttp.SetHostnameImmutable(ctx, endpoint.HostnameImmutable)
    129 	ctx = awsmiddleware.SetSigningRegion(ctx, endpoint.SigningRegion)
    130 	ctx = awsmiddleware.SetPartitionID(ctx, endpoint.PartitionID)
    131 	return next.HandleSerialize(ctx, in)
    132 }
    133 func addResolveEndpointMiddleware(stack *middleware.Stack, o Options) error {
    134 	return stack.Serialize.Insert(&ResolveEndpoint{
    135 		Resolver: o.EndpointResolver,
    136 		Options:  o.EndpointOptions,
    137 	}, "OperationSerializer", middleware.Before)
    138 }
    139 
    140 func removeResolveEndpointMiddleware(stack *middleware.Stack) error {
    141 	_, err := stack.Serialize.Remove((&ResolveEndpoint{}).ID())
    142 	return err
    143 }
    144 
    145 type wrappedEndpointResolver struct {
    146 	awsResolver aws.EndpointResolverWithOptions
    147 }
    148 
    149 func (w *wrappedEndpointResolver) ResolveEndpoint(region string, options EndpointResolverOptions) (endpoint aws.Endpoint, err error) {
    150 	return w.awsResolver.ResolveEndpoint(ServiceID, region, options)
    151 }
    152 
    153 type awsEndpointResolverAdaptor func(service, region string) (aws.Endpoint, error)
    154 
    155 func (a awsEndpointResolverAdaptor) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) {
    156 	return a(service, region)
    157 }
    158 
    159 var _ aws.EndpointResolverWithOptions = awsEndpointResolverAdaptor(nil)
    160 
    161 // withEndpointResolver returns an aws.EndpointResolverWithOptions that first delegates endpoint resolution to the awsResolver.
    162 // If awsResolver returns aws.EndpointNotFoundError error, the v1 resolver middleware will swallow the error,
    163 // and set an appropriate context flag such that fallback will occur when EndpointResolverV2 is invoked
    164 // via its middleware.
    165 //
    166 // If another error (besides aws.EndpointNotFoundError) is returned, then that error will be propagated.
    167 func withEndpointResolver(awsResolver aws.EndpointResolver, awsResolverWithOptions aws.EndpointResolverWithOptions) EndpointResolver {
    168 	var resolver aws.EndpointResolverWithOptions
    169 
    170 	if awsResolverWithOptions != nil {
    171 		resolver = awsResolverWithOptions
    172 	} else if awsResolver != nil {
    173 		resolver = awsEndpointResolverAdaptor(awsResolver.ResolveEndpoint)
    174 	}
    175 
    176 	return &wrappedEndpointResolver{
    177 		awsResolver: resolver,
    178 	}
    179 }
    180 
    181 func finalizeClientEndpointResolverOptions(options *Options) {
    182 	options.EndpointOptions.LogDeprecated = options.ClientLogMode.IsDeprecatedUsage()
    183 
    184 	if len(options.EndpointOptions.ResolvedRegion) == 0 {
    185 		const fipsInfix = "-fips-"
    186 		const fipsPrefix = "fips-"
    187 		const fipsSuffix = "-fips"
    188 
    189 		if strings.Contains(options.Region, fipsInfix) ||
    190 			strings.Contains(options.Region, fipsPrefix) ||
    191 			strings.Contains(options.Region, fipsSuffix) {
    192 			options.EndpointOptions.ResolvedRegion = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(
    193 				options.Region, fipsInfix, "-"), fipsPrefix, ""), fipsSuffix, "")
    194 			options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled
    195 		}
    196 	}
    197 
    198 }
    199 
    200 func resolveEndpointResolverV2(options *Options) {
    201 	if options.EndpointResolverV2 == nil {
    202 		options.EndpointResolverV2 = NewDefaultEndpointResolverV2()
    203 	}
    204 }
    205 
    206 func resolveBaseEndpoint(cfg aws.Config, o *Options) {
    207 	if cfg.BaseEndpoint != nil {
    208 		o.BaseEndpoint = cfg.BaseEndpoint
    209 	}
    210 
    211 	_, g := os.LookupEnv("AWS_ENDPOINT_URL")
    212 	_, s := os.LookupEnv("AWS_ENDPOINT_URL_SIGNIN")
    213 
    214 	if g && !s {
    215 		return
    216 	}
    217 
    218 	value, found, err := internalConfig.ResolveServiceBaseEndpoint(context.Background(), "Signin", cfg.ConfigSources)
    219 	if found && err == nil {
    220 		o.BaseEndpoint = &value
    221 	}
    222 }
    223 
    224 func bindRegion(region string) (*string, error) {
    225 	if region == "" {
    226 		return nil, nil
    227 	}
    228 	if !rulesfn.IsValidHostLabel(region, true) {
    229 		return nil, fmt.Errorf("invalid input region %s", region)
    230 	}
    231 
    232 	return aws.String(endpoints.MapFIPSRegion(region)), nil
    233 }
    234 
    235 var _ = rulesfn.StringSlice(nil)
    236 
    237 // EndpointParameters provides the parameters that influence how endpoints are
    238 // resolved.
    239 type EndpointParameters struct {
    240 	// When true, use the dual-stack endpoint. If the configured endpoint does not
    241 	// support dual-stack, dispatching the request MAY return an error.
    242 	//
    243 	// Defaults to
    244 	// false if no value is provided.
    245 	//
    246 	// AWS::UseDualStack
    247 	UseDualStack *bool
    248 
    249 	// When true, send this request to the FIPS-compliant regional endpoint. If the
    250 	// configured endpoint does not have a FIPS compliant endpoint, dispatching the
    251 	// request will return an error.
    252 	//
    253 	// Defaults to false if no value is
    254 	// provided.
    255 	//
    256 	// AWS::UseFIPS
    257 	UseFIPS *bool
    258 
    259 	// Override the endpoint used to send this request
    260 	//
    261 	// Parameter is
    262 	// required.
    263 	//
    264 	// SDK::Endpoint
    265 	Endpoint *string
    266 
    267 	// The AWS region used to dispatch the request.
    268 	//
    269 	// Parameter is
    270 	// required.
    271 	//
    272 	// AWS::Region
    273 	Region *string
    274 
    275 	// Indicates if the operation targets the control plane endpoint
    276 	//
    277 	// Parameter is
    278 	// required.
    279 	IsControlPlane *bool
    280 
    281 	// Indicates if the operation targets the OAuth token endpoint
    282 	//
    283 	// Parameter is
    284 	// required.
    285 	IsOAuthEndpoint *bool
    286 }
    287 
    288 // ValidateRequired validates required parameters are set.
    289 func (p EndpointParameters) ValidateRequired() error {
    290 	if p.UseDualStack == nil {
    291 		return fmt.Errorf("parameter UseDualStack is required")
    292 	}
    293 
    294 	if p.UseFIPS == nil {
    295 		return fmt.Errorf("parameter UseFIPS is required")
    296 	}
    297 
    298 	return nil
    299 }
    300 
    301 // WithDefaults returns a shallow copy of EndpointParameterswith default values
    302 // applied to members where applicable.
    303 func (p EndpointParameters) WithDefaults() EndpointParameters {
    304 	if p.UseDualStack == nil {
    305 		p.UseDualStack = ptr.Bool(false)
    306 	}
    307 
    308 	if p.UseFIPS == nil {
    309 		p.UseFIPS = ptr.Bool(false)
    310 	}
    311 	return p
    312 }
    313 
    314 const bddRoot int32 = 2
    315 
    316 var bddNodes = [120]int32{
    317 	-1, 1, -1, 0, 6, 3, 2, 36, 4, 4, 5, 100000027, 6, 100000004, 100000027, 1, 29, 7, 2, 36, 8, 3, 9, 31, 4, 22, 10, 5, 19, 11, 7, 21, 12, 8, 100000007, 13, 10, 100000008, 14, 12, 100000009, 15, 13, 100000010, 16, 14, 100000011, 17, 15, 100000012, 18, 16, 100000013, 100000016, 6, 100000005, 20, 7, 21, 100000006, 17, 100000024, 100000025, 6, 100000004, 23, 7, 27, 24, 9, 100000014, 25, 10, 100000015, 26, 11, 100000022, 100000023, 11, 28, 100000021, 17, 100000020, 100000021, 2, 35, 30, 3, 39, 31, 4, 32, 100000027, 6, 100000004, 33, 7, 100000027, 34, 9, 100000014, 100000027, 3, 39, 36, 4, 38, 37, 7, 100000018, 100000019, 6, 100000004, 100000017, 5, 100000001, 40, 8, 100000002, 100000003}
    318 
    319 type conditionContext struct {
    320 	PartitionResult *awsrulesfn.PartitionConfig
    321 }
    322 
    323 func evalCondition(idx int, params *EndpointParameters, c *conditionContext) bool {
    324 	switch idx {
    325 	case 0:
    326 		return params.Region != nil
    327 	case 1:
    328 		return func() bool {
    329 			if v := params.IsControlPlane; v != nil {
    330 				return *v
    331 			}
    332 			return false
    333 		}() == true
    334 	case 2:
    335 		return params.Endpoint != nil
    336 	case 3:
    337 		if v := awsrulesfn.GetPartition(*params.Region); v != nil {
    338 			c.PartitionResult = v
    339 			return true
    340 		}
    341 		return false
    342 	case 4:
    343 		return *params.UseFIPS == true
    344 	case 5:
    345 		return c.PartitionResult.Name == "aws"
    346 	case 6:
    347 		return func() bool {
    348 			if v := params.IsOAuthEndpoint; v != nil {
    349 				return *v
    350 			}
    351 			return false
    352 		}() == true
    353 	case 7:
    354 		return *params.UseDualStack == true
    355 	case 8:
    356 		return c.PartitionResult.Name == "aws-cn"
    357 	case 9:
    358 		return *params.Region == "us-gov-west-1"
    359 	case 10:
    360 		return c.PartitionResult.Name == "aws-us-gov"
    361 	case 11:
    362 		return c.PartitionResult.SupportsFIPS == true
    363 	case 12:
    364 		return c.PartitionResult.Name == "aws-iso"
    365 	case 13:
    366 		return c.PartitionResult.Name == "aws-iso-b"
    367 	case 14:
    368 		return c.PartitionResult.Name == "aws-iso-f"
    369 	case 15:
    370 		return c.PartitionResult.Name == "aws-iso-e"
    371 	case 16:
    372 		return c.PartitionResult.Name == "aws-eusc"
    373 	case 17:
    374 		return c.PartitionResult.SupportsDualStack == true
    375 	}
    376 	return false
    377 }
    378 
    379 func resolveResult(idx int32, params *EndpointParameters, c *conditionContext) (smithyendpoints.Endpoint, error) {
    380 	switch idx {
    381 	case 0:
    382 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint resolution failed: no matching rule")
    383 	case 1:
    384 		uriString := func() string {
    385 			var out strings.Builder
    386 			out.WriteString("https://signin.")
    387 			out.WriteString(*params.Region)
    388 			out.WriteString(".api.aws")
    389 			return out.String()
    390 		}()
    391 		uri, err := url.Parse(uriString)
    392 		if err != nil {
    393 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    394 		}
    395 		return smithyendpoints.Endpoint{
    396 			URI:     *uri,
    397 			Headers: http.Header{},
    398 			Properties: func() smithy.Properties {
    399 				var out smithy.Properties
    400 				smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
    401 					{
    402 						SchemeID: "sigv4",
    403 						SignerProperties: func() smithy.Properties {
    404 							var sp smithy.Properties
    405 							smithyhttp.SetSigV4SigningName(&sp, "signin")
    406 							smithyhttp.SetSigV4ASigningName(&sp, "signin")
    407 
    408 							smithyhttp.SetSigV4SigningRegion(&sp, *params.Region)
    409 							return sp
    410 						}(),
    411 					},
    412 				})
    413 				return out
    414 			}(),
    415 		}, nil
    416 	case 2:
    417 		uriString := func() string {
    418 			var out strings.Builder
    419 			out.WriteString("https://signin.")
    420 			out.WriteString(*params.Region)
    421 			out.WriteString(".api.amazonwebservices.com.cn")
    422 			return out.String()
    423 		}()
    424 		uri, err := url.Parse(uriString)
    425 		if err != nil {
    426 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    427 		}
    428 		return smithyendpoints.Endpoint{
    429 			URI:     *uri,
    430 			Headers: http.Header{},
    431 			Properties: func() smithy.Properties {
    432 				var out smithy.Properties
    433 				smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
    434 					{
    435 						SchemeID: "sigv4",
    436 						SignerProperties: func() smithy.Properties {
    437 							var sp smithy.Properties
    438 							smithyhttp.SetSigV4SigningName(&sp, "signin")
    439 							smithyhttp.SetSigV4ASigningName(&sp, "signin")
    440 
    441 							smithyhttp.SetSigV4SigningRegion(&sp, *params.Region)
    442 							return sp
    443 						}(),
    444 					},
    445 				})
    446 				return out
    447 			}(),
    448 		}, nil
    449 	case 3:
    450 		uriString := func() string {
    451 			var out strings.Builder
    452 			out.WriteString("https://signin.")
    453 			out.WriteString(*params.Region)
    454 			out.WriteString(".")
    455 			out.WriteString(c.PartitionResult.DualStackDnsSuffix)
    456 			return out.String()
    457 		}()
    458 		uri, err := url.Parse(uriString)
    459 		if err != nil {
    460 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    461 		}
    462 		return smithyendpoints.Endpoint{
    463 			URI:     *uri,
    464 			Headers: http.Header{},
    465 			Properties: func() smithy.Properties {
    466 				var out smithy.Properties
    467 				smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
    468 					{
    469 						SchemeID: "sigv4",
    470 						SignerProperties: func() smithy.Properties {
    471 							var sp smithy.Properties
    472 							smithyhttp.SetSigV4SigningName(&sp, "signin")
    473 							smithyhttp.SetSigV4ASigningName(&sp, "signin")
    474 
    475 							smithyhttp.SetSigV4SigningRegion(&sp, *params.Region)
    476 							return sp
    477 						}(),
    478 					},
    479 				})
    480 				return out
    481 			}(),
    482 		}, nil
    483 	case 4:
    484 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "FIPS endpoints are not supported for OAuth operations. Disable FIPS or use a non-OAuth operation.")
    485 	case 5:
    486 		uriString := func() string {
    487 			var out strings.Builder
    488 			out.WriteString("https://")
    489 			out.WriteString(*params.Region)
    490 			out.WriteString(".oauth.signin.aws")
    491 			return out.String()
    492 		}()
    493 		uri, err := url.Parse(uriString)
    494 		if err != nil {
    495 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    496 		}
    497 		return smithyendpoints.Endpoint{
    498 			URI:     *uri,
    499 			Headers: http.Header{},
    500 			Properties: func() smithy.Properties {
    501 				var out smithy.Properties
    502 				smithyauth.SetAuthOptions(&out, []*smithyauth.Option{
    503 					{
    504 						SchemeID: "sigv4",
    505 						SignerProperties: func() smithy.Properties {
    506 							var sp smithy.Properties
    507 							smithyhttp.SetSigV4SigningName(&sp, "signin")
    508 							smithyhttp.SetSigV4ASigningName(&sp, "signin")
    509 
    510 							smithyhttp.SetSigV4SigningRegion(&sp, *params.Region)
    511 							return sp
    512 						}(),
    513 					},
    514 				})
    515 				return out
    516 			}(),
    517 		}, nil
    518 	case 6:
    519 		uriString := func() string {
    520 			var out strings.Builder
    521 			out.WriteString("https://")
    522 			out.WriteString(*params.Region)
    523 			out.WriteString(".signin.aws.amazon.com")
    524 			return out.String()
    525 		}()
    526 		uri, err := url.Parse(uriString)
    527 		if err != nil {
    528 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    529 		}
    530 		return smithyendpoints.Endpoint{
    531 			URI:     *uri,
    532 			Headers: http.Header{},
    533 		}, nil
    534 	case 7:
    535 		uriString := func() string {
    536 			var out strings.Builder
    537 			out.WriteString("https://")
    538 			out.WriteString(*params.Region)
    539 			out.WriteString(".signin.amazonaws.cn")
    540 			return out.String()
    541 		}()
    542 		uri, err := url.Parse(uriString)
    543 		if err != nil {
    544 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    545 		}
    546 		return smithyendpoints.Endpoint{
    547 			URI:     *uri,
    548 			Headers: http.Header{},
    549 		}, nil
    550 	case 8:
    551 		uriString := func() string {
    552 			var out strings.Builder
    553 			out.WriteString("https://")
    554 			out.WriteString(*params.Region)
    555 			out.WriteString(".signin.amazonaws-us-gov.com")
    556 			return out.String()
    557 		}()
    558 		uri, err := url.Parse(uriString)
    559 		if err != nil {
    560 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    561 		}
    562 		return smithyendpoints.Endpoint{
    563 			URI:     *uri,
    564 			Headers: http.Header{},
    565 		}, nil
    566 	case 9:
    567 		uriString := func() string {
    568 			var out strings.Builder
    569 			out.WriteString("https://")
    570 			out.WriteString(*params.Region)
    571 			out.WriteString(".signin.c2shome.ic.gov")
    572 			return out.String()
    573 		}()
    574 		uri, err := url.Parse(uriString)
    575 		if err != nil {
    576 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    577 		}
    578 		return smithyendpoints.Endpoint{
    579 			URI:     *uri,
    580 			Headers: http.Header{},
    581 		}, nil
    582 	case 10:
    583 		uriString := func() string {
    584 			var out strings.Builder
    585 			out.WriteString("https://")
    586 			out.WriteString(*params.Region)
    587 			out.WriteString(".signin.sc2shome.sgov.gov")
    588 			return out.String()
    589 		}()
    590 		uri, err := url.Parse(uriString)
    591 		if err != nil {
    592 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    593 		}
    594 		return smithyendpoints.Endpoint{
    595 			URI:     *uri,
    596 			Headers: http.Header{},
    597 		}, nil
    598 	case 11:
    599 		uriString := func() string {
    600 			var out strings.Builder
    601 			out.WriteString("https://")
    602 			out.WriteString(*params.Region)
    603 			out.WriteString(".signin.csphome.hci.ic.gov")
    604 			return out.String()
    605 		}()
    606 		uri, err := url.Parse(uriString)
    607 		if err != nil {
    608 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    609 		}
    610 		return smithyendpoints.Endpoint{
    611 			URI:     *uri,
    612 			Headers: http.Header{},
    613 		}, nil
    614 	case 12:
    615 		uriString := func() string {
    616 			var out strings.Builder
    617 			out.WriteString("https://")
    618 			out.WriteString(*params.Region)
    619 			out.WriteString(".signin.csphome.adc-e.uk")
    620 			return out.String()
    621 		}()
    622 		uri, err := url.Parse(uriString)
    623 		if err != nil {
    624 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    625 		}
    626 		return smithyendpoints.Endpoint{
    627 			URI:     *uri,
    628 			Headers: http.Header{},
    629 		}, nil
    630 	case 13:
    631 		uriString := func() string {
    632 			var out strings.Builder
    633 			out.WriteString("https://")
    634 			out.WriteString(*params.Region)
    635 			out.WriteString(".signin.amazonaws-eusc.eu")
    636 			return out.String()
    637 		}()
    638 		uri, err := url.Parse(uriString)
    639 		if err != nil {
    640 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    641 		}
    642 		return smithyendpoints.Endpoint{
    643 			URI:     *uri,
    644 			Headers: http.Header{},
    645 		}, nil
    646 	case 14:
    647 		uriString := "https://signin-fips.amazonaws-us-gov.com"
    648 		uri, err := url.Parse(uriString)
    649 		if err != nil {
    650 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    651 		}
    652 		return smithyendpoints.Endpoint{
    653 			URI:     *uri,
    654 			Headers: http.Header{},
    655 		}, nil
    656 	case 15:
    657 		uriString := func() string {
    658 			var out strings.Builder
    659 			out.WriteString("https://")
    660 			out.WriteString(*params.Region)
    661 			out.WriteString(".signin-fips.amazonaws-us-gov.com")
    662 			return out.String()
    663 		}()
    664 		uri, err := url.Parse(uriString)
    665 		if err != nil {
    666 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    667 		}
    668 		return smithyendpoints.Endpoint{
    669 			URI:     *uri,
    670 			Headers: http.Header{},
    671 		}, nil
    672 	case 16:
    673 		uriString := func() string {
    674 			var out strings.Builder
    675 			out.WriteString("https://")
    676 			out.WriteString(*params.Region)
    677 			out.WriteString(".signin.")
    678 			out.WriteString(c.PartitionResult.DnsSuffix)
    679 			return out.String()
    680 		}()
    681 		uri, err := url.Parse(uriString)
    682 		if err != nil {
    683 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    684 		}
    685 		return smithyendpoints.Endpoint{
    686 			URI:     *uri,
    687 			Headers: http.Header{},
    688 		}, nil
    689 	case 17:
    690 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: FIPS and custom endpoint are not supported")
    691 	case 18:
    692 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Dualstack and custom endpoint are not supported")
    693 	case 19:
    694 		uriString := *params.Endpoint
    695 		uri, err := url.Parse(uriString)
    696 		if err != nil {
    697 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    698 		}
    699 		return smithyendpoints.Endpoint{
    700 			URI:     *uri,
    701 			Headers: http.Header{},
    702 		}, nil
    703 	case 20:
    704 		uriString := func() string {
    705 			var out strings.Builder
    706 			out.WriteString("https://signin-fips.")
    707 			out.WriteString(*params.Region)
    708 			out.WriteString(".")
    709 			out.WriteString(c.PartitionResult.DualStackDnsSuffix)
    710 			return out.String()
    711 		}()
    712 		uri, err := url.Parse(uriString)
    713 		if err != nil {
    714 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    715 		}
    716 		return smithyendpoints.Endpoint{
    717 			URI:     *uri,
    718 			Headers: http.Header{},
    719 		}, nil
    720 	case 21:
    721 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "FIPS and DualStack are enabled, but this partition does not support one or both")
    722 	case 22:
    723 		uriString := func() string {
    724 			var out strings.Builder
    725 			out.WriteString("https://signin-fips.")
    726 			out.WriteString(*params.Region)
    727 			out.WriteString(".")
    728 			out.WriteString(c.PartitionResult.DnsSuffix)
    729 			return out.String()
    730 		}()
    731 		uri, err := url.Parse(uriString)
    732 		if err != nil {
    733 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    734 		}
    735 		return smithyendpoints.Endpoint{
    736 			URI:     *uri,
    737 			Headers: http.Header{},
    738 		}, nil
    739 	case 23:
    740 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "FIPS is enabled but this partition does not support FIPS")
    741 	case 24:
    742 		uriString := func() string {
    743 			var out strings.Builder
    744 			out.WriteString("https://signin.")
    745 			out.WriteString(*params.Region)
    746 			out.WriteString(".")
    747 			out.WriteString(c.PartitionResult.DualStackDnsSuffix)
    748 			return out.String()
    749 		}()
    750 		uri, err := url.Parse(uriString)
    751 		if err != nil {
    752 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    753 		}
    754 		return smithyendpoints.Endpoint{
    755 			URI:     *uri,
    756 			Headers: http.Header{},
    757 		}, nil
    758 	case 25:
    759 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "DualStack is enabled but this partition does not support DualStack")
    760 	case 26:
    761 		uriString := func() string {
    762 			var out strings.Builder
    763 			out.WriteString("https://signin.")
    764 			out.WriteString(*params.Region)
    765 			out.WriteString(".")
    766 			out.WriteString(c.PartitionResult.DnsSuffix)
    767 			return out.String()
    768 		}()
    769 		uri, err := url.Parse(uriString)
    770 		if err != nil {
    771 			return smithyendpoints.Endpoint{}, fmt.Errorf("Failed to parse uri: %s", uriString)
    772 		}
    773 		return smithyendpoints.Endpoint{
    774 			URI:     *uri,
    775 			Headers: http.Header{},
    776 		}, nil
    777 	case 27:
    778 		return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, %s", "Invalid Configuration: Missing Region")
    779 	}
    780 	return smithyendpoints.Endpoint{}, fmt.Errorf("endpoint rule error, invalid result index: %d", idx)
    781 }
    782 
    783 // EndpointResolverV2 provides the interface for resolving service endpoints.
    784 type EndpointResolverV2 interface {
    785 	ResolveEndpoint(ctx context.Context, params EndpointParameters) (
    786 		smithyendpoints.Endpoint, error,
    787 	)
    788 }
    789 
    790 // resolver provides the implementation for resolving endpoints.
    791 type resolver struct{}
    792 
    793 func NewDefaultEndpointResolverV2() EndpointResolverV2 {
    794 	return &resolver{}
    795 }
    796 
    797 // ResolveEndpoint attempts to resolve the endpoint with the provided options,
    798 // returning the endpoint if found. Otherwise an error is returned.
    799 func (r *resolver) ResolveEndpoint(
    800 	ctx context.Context, params EndpointParameters,
    801 ) (
    802 	endpoint smithyendpoints.Endpoint, err error,
    803 ) {
    804 	params = params.WithDefaults()
    805 	if err = params.ValidateRequired(); err != nil {
    806 		return endpoint, fmt.Errorf("endpoint parameters are not valid, %w", err)
    807 	}
    808 
    809 	c := &conditionContext{}
    810 	ref := bdd.Evaluate(bddNodes[:], bddRoot, func(idx int) bool {
    811 		return evalCondition(idx, &params, c)
    812 	})
    813 	return resolveResult(ref, &params, c)
    814 }
    815 
    816 type endpointParamsBinder interface {
    817 	bindEndpointParams(*EndpointParameters)
    818 }
    819 
    820 func bindEndpointParams(ctx context.Context, input interface{}, options Options) (*EndpointParameters, error) {
    821 	params := &EndpointParameters{}
    822 
    823 	params.UseDualStack = aws.Bool(options.EndpointOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled)
    824 	params.UseFIPS = aws.Bool(options.EndpointOptions.UseFIPSEndpoint == aws.FIPSEndpointStateEnabled)
    825 	params.Endpoint = options.BaseEndpoint
    826 	region, err := bindRegion(options.Region)
    827 	if err != nil {
    828 		return nil, err
    829 	}
    830 	params.Region = region
    831 
    832 	if b, ok := input.(endpointParamsBinder); ok {
    833 		b.bindEndpointParams(params)
    834 	}
    835 
    836 	return params, nil
    837 }
    838 
    839 type resolveEndpointV2Middleware struct {
    840 	options Options
    841 }
    842 
    843 func (*resolveEndpointV2Middleware) ID() string {
    844 	return "ResolveEndpointV2"
    845 }
    846 
    847 func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
    848 	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
    849 ) {
    850 	_, span := tracing.StartSpan(ctx, "ResolveEndpoint")
    851 	defer span.End()
    852 
    853 	if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
    854 		return next.HandleFinalize(ctx, in)
    855 	}
    856 
    857 	req, ok := in.Request.(*smithyhttp.Request)
    858 	if !ok {
    859 		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
    860 	}
    861 
    862 	if m.options.EndpointResolverV2 == nil {
    863 		return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
    864 	}
    865 
    866 	params, err := bindEndpointParams(ctx, getOperationInput(ctx), m.options)
    867 	if err != nil {
    868 		return out, metadata, fmt.Errorf("failed to bind endpoint params, %w", err)
    869 	}
    870 	endpt, err := timeOperationMetric(ctx, "client.call.resolve_endpoint_duration",
    871 		func() (smithyendpoints.Endpoint, error) {
    872 			return m.options.EndpointResolverV2.ResolveEndpoint(ctx, *params)
    873 		})
    874 	if err != nil {
    875 		return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
    876 	}
    877 
    878 	span.SetProperty("client.call.resolved_endpoint", endpt.URI.String())
    879 
    880 	if endpt.URI.RawPath == "" && req.URL.RawPath != "" {
    881 		endpt.URI.RawPath = endpt.URI.Path
    882 	}
    883 	req.URL.Scheme = endpt.URI.Scheme
    884 	req.URL.Host = endpt.URI.Host
    885 	req.URL.Path = smithyhttp.JoinPath(endpt.URI.Path, req.URL.Path)
    886 	req.URL.RawPath = smithyhttp.JoinPath(endpt.URI.RawPath, req.URL.RawPath)
    887 	for k := range endpt.Headers {
    888 		req.Header.Set(k, endpt.Headers.Get(k))
    889 	}
    890 
    891 	rscheme := getResolvedAuthScheme(ctx)
    892 	if rscheme == nil {
    893 		return out, metadata, fmt.Errorf("no resolved auth scheme")
    894 	}
    895 
    896 	opts, _ := smithyauth.GetAuthOptions(&endpt.Properties)
    897 	for _, o := range opts {
    898 		rscheme.SignerProperties.SetAll(&o.SignerProperties)
    899 	}
    900 
    901 	span.End()
    902 	return next.HandleFinalize(ctx, in)
    903 }