src

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

api_client.go (29535B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package sso
      4 
      5 import (
      6 	"context"
      7 	"errors"
      8 	"fmt"
      9 	"net"
     10 	"net/http"
     11 	"sync/atomic"
     12 	"time"
     13 
     14 	"github.com/aws/aws-sdk-go-v2/aws"
     15 	"github.com/aws/aws-sdk-go-v2/aws/defaults"
     16 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
     17 	"github.com/aws/aws-sdk-go-v2/aws/retry"
     18 	v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
     19 	awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
     20 	internalauth "github.com/aws/aws-sdk-go-v2/internal/auth"
     21 	internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
     22 	internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources"
     23 	smithy "github.com/aws/smithy-go"
     24 	smithydocument "github.com/aws/smithy-go/document"
     25 	"github.com/aws/smithy-go/logging"
     26 	"github.com/aws/smithy-go/metrics"
     27 	"github.com/aws/smithy-go/middleware"
     28 	"github.com/aws/smithy-go/tracing"
     29 	smithyhttp "github.com/aws/smithy-go/transport/http"
     30 )
     31 
     32 const ServiceID = "SSO"
     33 const ServiceAPIVersion = "2019-06-10"
     34 
     35 type operationMetrics struct {
     36 	Duration                metrics.Float64Histogram
     37 	SerializeDuration       metrics.Float64Histogram
     38 	ResolveIdentityDuration metrics.Float64Histogram
     39 	ResolveEndpointDuration metrics.Float64Histogram
     40 	SignRequestDuration     metrics.Float64Histogram
     41 	DeserializeDuration     metrics.Float64Histogram
     42 }
     43 
     44 func (m *operationMetrics) histogramFor(name string) metrics.Float64Histogram {
     45 	switch name {
     46 	case "client.call.duration":
     47 		return m.Duration
     48 	case "client.call.serialization_duration":
     49 		return m.SerializeDuration
     50 	case "client.call.resolve_identity_duration":
     51 		return m.ResolveIdentityDuration
     52 	case "client.call.resolve_endpoint_duration":
     53 		return m.ResolveEndpointDuration
     54 	case "client.call.signing_duration":
     55 		return m.SignRequestDuration
     56 	case "client.call.deserialization_duration":
     57 		return m.DeserializeDuration
     58 	default:
     59 		panic("unrecognized operation metric")
     60 	}
     61 }
     62 
     63 func timeOperationMetric[T any](
     64 	ctx context.Context, metric string, fn func() (T, error),
     65 	opts ...metrics.RecordMetricOption,
     66 ) (T, error) {
     67 	mm := getOperationMetrics(ctx)
     68 	if mm == nil { // not using the metrics system
     69 		return fn()
     70 	}
     71 
     72 	instr := mm.histogramFor(metric)
     73 	opts = append([]metrics.RecordMetricOption{withOperationMetadata(ctx)}, opts...)
     74 
     75 	start := time.Now()
     76 	v, err := fn()
     77 	end := time.Now()
     78 
     79 	elapsed := end.Sub(start)
     80 	instr.Record(ctx, float64(elapsed)/1e9, opts...)
     81 	return v, err
     82 }
     83 
     84 func startMetricTimer(ctx context.Context, metric string, opts ...metrics.RecordMetricOption) func() {
     85 	mm := getOperationMetrics(ctx)
     86 	if mm == nil { // not using the metrics system
     87 		return func() {}
     88 	}
     89 
     90 	instr := mm.histogramFor(metric)
     91 	opts = append([]metrics.RecordMetricOption{withOperationMetadata(ctx)}, opts...)
     92 
     93 	var ended bool
     94 	start := time.Now()
     95 	return func() {
     96 		if ended {
     97 			return
     98 		}
     99 		ended = true
    100 
    101 		end := time.Now()
    102 
    103 		elapsed := end.Sub(start)
    104 		instr.Record(ctx, float64(elapsed)/1e9, opts...)
    105 	}
    106 }
    107 
    108 func withOperationMetadata(ctx context.Context) metrics.RecordMetricOption {
    109 	return func(o *metrics.RecordMetricOptions) {
    110 		o.Properties.Set("rpc.service", middleware.GetServiceID(ctx))
    111 		o.Properties.Set("rpc.method", middleware.GetOperationName(ctx))
    112 	}
    113 }
    114 
    115 type operationMetricsKey struct{}
    116 
    117 func withOperationMetrics(parent context.Context, mp metrics.MeterProvider) (context.Context, error) {
    118 	if _, ok := mp.(metrics.NopMeterProvider); ok {
    119 		// not using the metrics system - setting up the metrics context is a memory-intensive operation
    120 		// so we should skip it in this case
    121 		return parent, nil
    122 	}
    123 
    124 	meter := mp.Meter("github.com/aws/aws-sdk-go-v2/service/sso")
    125 	om := &operationMetrics{}
    126 
    127 	var err error
    128 
    129 	om.Duration, err = operationMetricTimer(meter, "client.call.duration",
    130 		"Overall call duration (including retries and time to send or receive request and response body)")
    131 	if err != nil {
    132 		return nil, err
    133 	}
    134 	om.SerializeDuration, err = operationMetricTimer(meter, "client.call.serialization_duration",
    135 		"The time it takes to serialize a message body")
    136 	if err != nil {
    137 		return nil, err
    138 	}
    139 	om.ResolveIdentityDuration, err = operationMetricTimer(meter, "client.call.auth.resolve_identity_duration",
    140 		"The time taken to acquire an identity (AWS credentials, bearer token, etc) from an Identity Provider")
    141 	if err != nil {
    142 		return nil, err
    143 	}
    144 	om.ResolveEndpointDuration, err = operationMetricTimer(meter, "client.call.resolve_endpoint_duration",
    145 		"The time it takes to resolve an endpoint (endpoint resolver, not DNS) for the request")
    146 	if err != nil {
    147 		return nil, err
    148 	}
    149 	om.SignRequestDuration, err = operationMetricTimer(meter, "client.call.auth.signing_duration",
    150 		"The time it takes to sign a request")
    151 	if err != nil {
    152 		return nil, err
    153 	}
    154 	om.DeserializeDuration, err = operationMetricTimer(meter, "client.call.deserialization_duration",
    155 		"The time it takes to deserialize a message body")
    156 	if err != nil {
    157 		return nil, err
    158 	}
    159 
    160 	return context.WithValue(parent, operationMetricsKey{}, om), nil
    161 }
    162 
    163 func operationMetricTimer(m metrics.Meter, name, desc string) (metrics.Float64Histogram, error) {
    164 	return m.Float64Histogram(name, func(o *metrics.InstrumentOptions) {
    165 		o.UnitLabel = "s"
    166 		o.Description = desc
    167 	})
    168 }
    169 
    170 func getOperationMetrics(ctx context.Context) *operationMetrics {
    171 	if v := ctx.Value(operationMetricsKey{}); v != nil {
    172 		return v.(*operationMetrics)
    173 	}
    174 	return nil
    175 }
    176 
    177 func operationTracer(p tracing.TracerProvider) tracing.Tracer {
    178 	return p.Tracer("github.com/aws/aws-sdk-go-v2/service/sso")
    179 }
    180 
    181 // Client provides the API client to make operations call for AWS Single Sign-On.
    182 type Client struct {
    183 	options Options
    184 
    185 	// Difference between the time reported by the server and the client
    186 	timeOffset *atomic.Int64
    187 }
    188 
    189 // New returns an initialized Client based on the functional options. Provide
    190 // additional functional options to further configure the behavior of the client,
    191 // such as changing the client's endpoint or adding custom middleware behavior.
    192 func New(options Options, optFns ...func(*Options)) *Client {
    193 	options = options.Copy()
    194 
    195 	resolveDefaultLogger(&options)
    196 
    197 	setResolvedDefaultsMode(&options)
    198 
    199 	resolveRetryer(&options)
    200 
    201 	resolveHTTPClient(&options)
    202 
    203 	resolveHTTPSignerV4(&options)
    204 
    205 	resolveEndpointResolverV2(&options)
    206 
    207 	resolveTracerProvider(&options)
    208 
    209 	resolveMeterProvider(&options)
    210 
    211 	resolveAuthSchemeResolver(&options)
    212 
    213 	for _, fn := range optFns {
    214 		fn(&options)
    215 	}
    216 
    217 	finalizeRetryMaxAttempts(&options)
    218 
    219 	ignoreAnonymousAuth(&options)
    220 
    221 	wrapWithAnonymousAuth(&options)
    222 
    223 	resolveAuthSchemes(&options)
    224 
    225 	client := &Client{
    226 		options: options,
    227 	}
    228 
    229 	initializeTimeOffsetResolver(client)
    230 
    231 	return client
    232 }
    233 
    234 // Options returns a copy of the client configuration.
    235 //
    236 // Callers SHOULD NOT perform mutations on any inner structures within client
    237 // config. Config overrides should instead be made on a per-operation basis through
    238 // functional options.
    239 func (c *Client) Options() Options {
    240 	return c.options.Copy()
    241 }
    242 
    243 func (c *Client) invokeOperation(
    244 	ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error,
    245 ) (
    246 	result interface{}, metadata middleware.Metadata, err error,
    247 ) {
    248 	ctx = middleware.ClearStackValues(ctx)
    249 	ctx = middleware.WithServiceID(ctx, ServiceID)
    250 	ctx = middleware.WithOperationName(ctx, opID)
    251 
    252 	stack := middleware.NewStack(opID, smithyhttp.NewStackRequest)
    253 	options := c.options.Copy()
    254 
    255 	for _, fn := range optFns {
    256 		fn(&options)
    257 	}
    258 
    259 	finalizeOperationRetryMaxAttempts(&options, *c)
    260 
    261 	finalizeClientEndpointResolverOptions(&options)
    262 
    263 	ctx = setLoggerContext(ctx, options, opID)
    264 
    265 	ctx = resolveServiceMetadata(ctx, options, opID)
    266 
    267 	if err := c.addCommonMiddlewares(stack, options, opID); err != nil {
    268 		return nil, metadata, err
    269 	}
    270 
    271 	for _, fn := range stackFns {
    272 		if err := fn(stack, options); err != nil {
    273 			return nil, metadata, err
    274 		}
    275 	}
    276 
    277 	for _, fn := range options.APIOptions {
    278 		if err := fn(stack); err != nil {
    279 			return nil, metadata, err
    280 		}
    281 	}
    282 
    283 	ctx, err = withOperationMetrics(ctx, options.MeterProvider)
    284 	if err != nil {
    285 		return nil, metadata, err
    286 	}
    287 
    288 	tracer := operationTracer(options.TracerProvider)
    289 	spanName := fmt.Sprintf("%s.%s", ServiceID, opID)
    290 
    291 	ctx = tracing.WithOperationTracer(ctx, tracer)
    292 
    293 	ctx, span := tracer.StartSpan(ctx, spanName, func(o *tracing.SpanOptions) {
    294 		o.Kind = tracing.SpanKindClient
    295 		o.Properties.Set("rpc.system", "aws-api")
    296 		o.Properties.Set("rpc.method", opID)
    297 		o.Properties.Set("rpc.service", ServiceID)
    298 	})
    299 	endTimer := startMetricTimer(ctx, "client.call.duration")
    300 	defer endTimer()
    301 	defer span.End()
    302 
    303 	handler := smithyhttp.NewClientHandlerWithOptions(options.HTTPClient, func(o *smithyhttp.ClientHandler) {
    304 		o.Meter = options.MeterProvider.Meter("github.com/aws/aws-sdk-go-v2/service/sso")
    305 	})
    306 	decorated := middleware.DecorateHandler(handler, stack)
    307 	result, metadata, err = decorated.Handle(ctx, params)
    308 	if err != nil {
    309 		span.SetProperty("exception.type", fmt.Sprintf("%T", err))
    310 		span.SetProperty("exception.message", err.Error())
    311 
    312 		var aerr smithy.APIError
    313 		if errors.As(err, &aerr) {
    314 			span.SetProperty("api.error_code", aerr.ErrorCode())
    315 			span.SetProperty("api.error_message", aerr.ErrorMessage())
    316 			span.SetProperty("api.error_fault", aerr.ErrorFault().String())
    317 		}
    318 
    319 		err = &smithy.OperationError{
    320 			ServiceID:     ServiceID,
    321 			OperationName: opID,
    322 			Err:           err,
    323 		}
    324 	}
    325 
    326 	span.SetProperty("error", err != nil)
    327 	if err == nil {
    328 		span.SetStatus(tracing.SpanStatusOK)
    329 	} else {
    330 		span.SetStatus(tracing.SpanStatusError)
    331 	}
    332 
    333 	return result, metadata, err
    334 }
    335 
    336 type operationInputKey struct{}
    337 
    338 func setOperationInput(ctx context.Context, input interface{}) context.Context {
    339 	return middleware.WithStackValue(ctx, operationInputKey{}, input)
    340 }
    341 
    342 func getOperationInput(ctx context.Context) interface{} {
    343 	return middleware.GetStackValue(ctx, operationInputKey{})
    344 }
    345 
    346 type setOperationInputMiddleware struct {
    347 }
    348 
    349 func (*setOperationInputMiddleware) ID() string {
    350 	return "setOperationInput"
    351 }
    352 
    353 func (m *setOperationInputMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
    354 	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
    355 ) {
    356 	ctx = setOperationInput(ctx, in.Parameters)
    357 	return next.HandleSerialize(ctx, in)
    358 }
    359 
    360 func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, operation string) error {
    361 	if err := stack.Finalize.Add(&resolveAuthSchemeMiddleware{operation: operation, options: options}, middleware.Before); err != nil {
    362 		return fmt.Errorf("add ResolveAuthScheme: %w", err)
    363 	}
    364 	if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", middleware.After); err != nil {
    365 		return fmt.Errorf("add GetIdentity: %v", err)
    366 	}
    367 	if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", middleware.After); err != nil {
    368 		return fmt.Errorf("add ResolveEndpointV2: %v", err)
    369 	}
    370 	if err := stack.Finalize.Insert(&signRequestMiddleware{options: options}, "ResolveEndpointV2", middleware.After); err != nil {
    371 		return fmt.Errorf("add Signing: %w", err)
    372 	}
    373 	return nil
    374 }
    375 
    376 func (c *Client) addCommonMiddlewares(stack *middleware.Stack, options Options, operation string) error {
    377 	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
    378 		return err
    379 	}
    380 	if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil {
    381 		return fmt.Errorf("add protocol finalizers: %v", err)
    382 	}
    383 	if err := addClientRequestID(stack); err != nil {
    384 		return err
    385 	}
    386 	if err := addRetry(stack, options, c); err != nil {
    387 		return err
    388 	}
    389 	if err := addRawResponseToMetadata(stack); err != nil {
    390 		return err
    391 	}
    392 	if err := addSpanRetryLoop(stack, options); err != nil {
    393 		return err
    394 	}
    395 	if err := addClientUserAgent(stack, options); err != nil {
    396 		return err
    397 	}
    398 	if err := addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
    399 		return err
    400 	}
    401 	if err := addUserAgentRetryMode(stack, options); err != nil {
    402 		return err
    403 	}
    404 	if err := addRecursionDetection(stack); err != nil {
    405 		return err
    406 	}
    407 	if err := addInterceptBeforeRetryLoop(stack, options); err != nil {
    408 		return err
    409 	}
    410 	if err := addInterceptAttempt(stack, options); err != nil {
    411 		return err
    412 	}
    413 	return nil
    414 }
    415 func resolveAuthSchemeResolver(options *Options) {
    416 	if options.AuthSchemeResolver == nil {
    417 		options.AuthSchemeResolver = &defaultAuthSchemeResolver{}
    418 	}
    419 }
    420 
    421 func resolveAuthSchemes(options *Options) {
    422 	if options.AuthSchemes == nil {
    423 		options.AuthSchemes = []smithyhttp.AuthScheme{
    424 			internalauth.NewHTTPAuthScheme("aws.auth#sigv4", &internalauthsmithy.V4SignerAdapter{
    425 				Signer:     options.HTTPSignerV4,
    426 				Logger:     options.Logger,
    427 				LogSigning: options.ClientLogMode.IsSigning(),
    428 			}),
    429 		}
    430 	}
    431 }
    432 
    433 type noSmithyDocumentSerde = smithydocument.NoSerde
    434 
    435 func resolveDefaultLogger(o *Options) {
    436 	if o.Logger != nil {
    437 		return
    438 	}
    439 	o.Logger = logging.Nop{}
    440 }
    441 
    442 func setLoggerContext(ctx context.Context, options Options, operation string) context.Context {
    443 	_ = operation
    444 	return middleware.SetLogger(ctx, options.Logger)
    445 }
    446 
    447 func setResolvedDefaultsMode(o *Options) {
    448 	if len(o.resolvedDefaultsMode) > 0 {
    449 		return
    450 	}
    451 
    452 	var mode aws.DefaultsMode
    453 	mode.SetFromString(string(o.DefaultsMode))
    454 
    455 	if mode == aws.DefaultsModeAuto {
    456 		mode = defaults.ResolveDefaultsModeAuto(o.Region, o.RuntimeEnvironment)
    457 	}
    458 
    459 	o.resolvedDefaultsMode = mode
    460 }
    461 
    462 // NewFromConfig returns a new client from the provided config.
    463 func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client {
    464 	opts := Options{
    465 		Region:                     cfg.Region,
    466 		DefaultsMode:               cfg.DefaultsMode,
    467 		RuntimeEnvironment:         cfg.RuntimeEnvironment,
    468 		HTTPClient:                 cfg.HTTPClient,
    469 		Credentials:                cfg.Credentials,
    470 		APIOptions:                 cfg.APIOptions,
    471 		Logger:                     cfg.Logger,
    472 		ClientLogMode:              cfg.ClientLogMode,
    473 		AppID:                      cfg.AppID,
    474 		DisableClockSkewCorrection: cfg.DisableClockSkewCorrection,
    475 		AuthSchemePreference:       cfg.AuthSchemePreference,
    476 	}
    477 	resolveAWSRetryerProvider(cfg, &opts)
    478 	resolveAWSRetryMaxAttempts(cfg, &opts)
    479 	resolveAWSRetryMode(cfg, &opts)
    480 	resolveAWSEndpointResolver(cfg, &opts)
    481 	resolveInterceptors(cfg, &opts)
    482 	resolveUseDualStackEndpoint(cfg, &opts)
    483 	resolveUseFIPSEndpoint(cfg, &opts)
    484 	resolveBaseEndpoint(cfg, &opts)
    485 	return New(opts, func(o *Options) {
    486 		for _, opt := range cfg.ServiceOptions {
    487 			opt(ServiceID, o)
    488 		}
    489 		for _, opt := range optFns {
    490 			opt(o)
    491 		}
    492 	})
    493 }
    494 
    495 func resolveHTTPClient(o *Options) {
    496 	var buildable *awshttp.BuildableClient
    497 
    498 	if o.HTTPClient != nil {
    499 		var ok bool
    500 		buildable, ok = o.HTTPClient.(*awshttp.BuildableClient)
    501 		if !ok {
    502 			return
    503 		}
    504 	} else {
    505 		buildable = awshttp.NewBuildableClient()
    506 	}
    507 
    508 	modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode)
    509 	if err == nil {
    510 		buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) {
    511 			if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok {
    512 				dialer.Timeout = dialerTimeout
    513 			}
    514 		})
    515 
    516 		buildable = buildable.WithTransportOptions(func(transport *http.Transport) {
    517 			if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok {
    518 				transport.TLSHandshakeTimeout = tlsHandshakeTimeout
    519 			}
    520 		})
    521 	}
    522 
    523 	o.HTTPClient = buildable
    524 }
    525 
    526 func resolveRetryer(o *Options) {
    527 	if o.Retryer != nil {
    528 		return
    529 	}
    530 
    531 	if len(o.RetryMode) == 0 {
    532 		modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode)
    533 		if err == nil {
    534 			o.RetryMode = modeConfig.RetryMode
    535 		}
    536 	}
    537 	if len(o.RetryMode) == 0 {
    538 		o.RetryMode = aws.RetryModeStandard
    539 	}
    540 
    541 	var standardOptions []func(*retry.StandardOptions)
    542 	if v := o.RetryMaxAttempts; v != 0 {
    543 		standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
    544 			so.MaxAttempts = v
    545 		})
    546 	}
    547 
    548 	switch o.RetryMode {
    549 	case aws.RetryModeAdaptive:
    550 		var adaptiveOptions []func(*retry.AdaptiveModeOptions)
    551 		if len(standardOptions) != 0 {
    552 			adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) {
    553 				ao.StandardOptions = append(ao.StandardOptions, standardOptions...)
    554 			})
    555 		}
    556 		o.Retryer = retry.NewAdaptiveMode(adaptiveOptions...)
    557 
    558 	default:
    559 		o.Retryer = retry.NewStandard(standardOptions...)
    560 	}
    561 }
    562 
    563 func resolveAWSRetryerProvider(cfg aws.Config, o *Options) {
    564 	if cfg.Retryer == nil {
    565 		return
    566 	}
    567 	o.Retryer = cfg.Retryer()
    568 }
    569 
    570 func resolveAWSRetryMode(cfg aws.Config, o *Options) {
    571 	if len(cfg.RetryMode) == 0 {
    572 		return
    573 	}
    574 	o.RetryMode = cfg.RetryMode
    575 }
    576 func resolveAWSRetryMaxAttempts(cfg aws.Config, o *Options) {
    577 	if cfg.RetryMaxAttempts == 0 {
    578 		return
    579 	}
    580 	o.RetryMaxAttempts = cfg.RetryMaxAttempts
    581 }
    582 
    583 func finalizeRetryMaxAttempts(o *Options) {
    584 	if o.RetryMaxAttempts == 0 {
    585 		return
    586 	}
    587 
    588 	o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts)
    589 }
    590 
    591 func finalizeOperationRetryMaxAttempts(o *Options, client Client) {
    592 	if v := o.RetryMaxAttempts; v == 0 || v == client.options.RetryMaxAttempts {
    593 		return
    594 	}
    595 
    596 	o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts)
    597 }
    598 
    599 func resolveAWSEndpointResolver(cfg aws.Config, o *Options) {
    600 	if cfg.EndpointResolver == nil && cfg.EndpointResolverWithOptions == nil {
    601 		return
    602 	}
    603 	o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions)
    604 }
    605 
    606 func resolveInterceptors(cfg aws.Config, o *Options) {
    607 	o.Interceptors = cfg.Interceptors.Copy()
    608 }
    609 
    610 func addClientUserAgent(stack *middleware.Stack, options Options) error {
    611 	ua, err := getOrAddRequestUserAgent(stack)
    612 	if err != nil {
    613 		return err
    614 	}
    615 
    616 	ua.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "sso", goModuleVersion)
    617 	if len(options.AppID) > 0 {
    618 		ua.AddSDKAgentKey(awsmiddleware.ApplicationIdentifier, options.AppID)
    619 	}
    620 
    621 	return nil
    622 }
    623 
    624 func getOrAddRequestUserAgent(stack *middleware.Stack) (*awsmiddleware.RequestUserAgent, error) {
    625 	id := (*awsmiddleware.RequestUserAgent)(nil).ID()
    626 	mw, ok := stack.Build.Get(id)
    627 	if !ok {
    628 		mw = awsmiddleware.NewRequestUserAgent()
    629 		if err := stack.Build.Add(mw, middleware.After); err != nil {
    630 			return nil, err
    631 		}
    632 	}
    633 
    634 	ua, ok := mw.(*awsmiddleware.RequestUserAgent)
    635 	if !ok {
    636 		return nil, fmt.Errorf("%T for %s middleware did not match expected type", mw, id)
    637 	}
    638 
    639 	return ua, nil
    640 }
    641 
    642 type HTTPSignerV4 interface {
    643 	SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4.SignerOptions)) error
    644 }
    645 
    646 func resolveHTTPSignerV4(o *Options) {
    647 	if o.HTTPSignerV4 != nil {
    648 		return
    649 	}
    650 	o.HTTPSignerV4 = newDefaultV4Signer(*o)
    651 }
    652 
    653 func newDefaultV4Signer(o Options) *v4.Signer {
    654 	return v4.NewSigner(func(so *v4.SignerOptions) {
    655 		so.Logger = o.Logger
    656 		so.LogSigning = o.ClientLogMode.IsSigning()
    657 	})
    658 }
    659 
    660 func addClientRequestID(stack *middleware.Stack) error {
    661 	return stack.Build.Add(&awsmiddleware.ClientRequestID{}, middleware.After)
    662 }
    663 
    664 func addComputeContentLength(stack *middleware.Stack) error {
    665 	return stack.Build.Insert(&smithyhttp.ComputeContentLength{}, "ClientRequestID", middleware.After)
    666 }
    667 
    668 func addRawResponseToMetadata(stack *middleware.Stack) error {
    669 	return stack.Deserialize.Add(&awsmiddleware.AddRawResponse{}, middleware.Before)
    670 }
    671 
    672 func addRecordResponseTiming(stack *middleware.Stack, options Options) error {
    673 	return stack.Deserialize.Add(&awsmiddleware.RecordResponseTiming{
    674 		DisableClockSkewCorrection: options.DisableClockSkewCorrection,
    675 	}, middleware.After)
    676 }
    677 
    678 func addSpanRetryLoop(stack *middleware.Stack, options Options) error {
    679 	return stack.Finalize.Insert(&spanRetryLoop{options: options}, "Retry", middleware.Before)
    680 }
    681 
    682 type spanRetryLoop struct {
    683 	options Options
    684 }
    685 
    686 func (*spanRetryLoop) ID() string {
    687 	return "spanRetryLoop"
    688 }
    689 
    690 func (m *spanRetryLoop) HandleFinalize(
    691 	ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
    692 ) (
    693 	middleware.FinalizeOutput, middleware.Metadata, error,
    694 ) {
    695 	tracer := operationTracer(m.options.TracerProvider)
    696 	ctx, span := tracer.StartSpan(ctx, "RetryLoop")
    697 	defer span.End()
    698 
    699 	return next.HandleFinalize(ctx, in)
    700 }
    701 func addStreamingEventsPayload(stack *middleware.Stack) error {
    702 	return stack.Finalize.Add(&v4.StreamingEventsPayload{}, middleware.Before)
    703 }
    704 
    705 func addUnsignedPayload(stack *middleware.Stack) error {
    706 	return stack.Finalize.Insert(&v4.UnsignedPayload{}, "ResolveEndpointV2", middleware.After)
    707 }
    708 
    709 func addComputePayloadSHA256(stack *middleware.Stack) error {
    710 	return stack.Finalize.Insert(&v4.ComputePayloadSHA256{}, "ResolveEndpointV2", middleware.After)
    711 }
    712 
    713 func addContentSHA256Header(stack *middleware.Stack) error {
    714 	return stack.Finalize.Insert(&v4.ContentSHA256Header{}, (*v4.ComputePayloadSHA256)(nil).ID(), middleware.After)
    715 }
    716 
    717 func addIsWaiterUserAgent(o *Options) {
    718 	o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
    719 		ua, err := getOrAddRequestUserAgent(stack)
    720 		if err != nil {
    721 			return err
    722 		}
    723 
    724 		ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureWaiter)
    725 		return nil
    726 	})
    727 }
    728 
    729 func addIsPaginatorUserAgent(o *Options) {
    730 	o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
    731 		ua, err := getOrAddRequestUserAgent(stack)
    732 		if err != nil {
    733 			return err
    734 		}
    735 
    736 		ua.AddUserAgentFeature(awsmiddleware.UserAgentFeaturePaginator)
    737 		return nil
    738 	})
    739 }
    740 
    741 func addRetry(stack *middleware.Stack, o Options, c *Client) error {
    742 	attempt := retry.NewAttemptMiddleware(o.Retryer, smithyhttp.RequestCloner, func(m *retry.Attempt) {
    743 		m.LogAttempts = o.ClientLogMode.IsRetries()
    744 		m.OperationMeter = o.MeterProvider.Meter("github.com/aws/aws-sdk-go-v2/service/sso")
    745 		m.ClientSkew = c.timeOffset
    746 		m.DisableClockSkewCorrection = o.DisableClockSkewCorrection
    747 	})
    748 	if err := stack.Finalize.Insert(attempt, "ResolveAuthScheme", middleware.Before); err != nil {
    749 		return err
    750 	}
    751 	if err := stack.Finalize.Insert(&retry.MetricsHeader{}, attempt.ID(), middleware.After); err != nil {
    752 		return err
    753 	}
    754 	return nil
    755 }
    756 
    757 // resolves dual-stack endpoint configuration
    758 func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error {
    759 	if len(cfg.ConfigSources) == 0 {
    760 		return nil
    761 	}
    762 	value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources)
    763 	if err != nil {
    764 		return err
    765 	}
    766 	if found {
    767 		o.EndpointOptions.UseDualStackEndpoint = value
    768 	}
    769 	return nil
    770 }
    771 
    772 // resolves FIPS endpoint configuration
    773 func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error {
    774 	if len(cfg.ConfigSources) == 0 {
    775 		return nil
    776 	}
    777 	value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources)
    778 	if err != nil {
    779 		return err
    780 	}
    781 	if found {
    782 		o.EndpointOptions.UseFIPSEndpoint = value
    783 	}
    784 	return nil
    785 }
    786 
    787 func initializeTimeOffsetResolver(c *Client) {
    788 	c.timeOffset = new(atomic.Int64)
    789 }
    790 
    791 func addUserAgentRetryMode(stack *middleware.Stack, options Options) error {
    792 	ua, err := getOrAddRequestUserAgent(stack)
    793 	if err != nil {
    794 		return err
    795 	}
    796 
    797 	switch options.Retryer.(type) {
    798 	case *retry.Standard:
    799 		ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureRetryModeStandard)
    800 	case *retry.AdaptiveMode:
    801 		ua.AddUserAgentFeature(awsmiddleware.UserAgentFeatureRetryModeAdaptive)
    802 	}
    803 	return nil
    804 }
    805 
    806 type setCredentialSourceMiddleware struct {
    807 	ua      *awsmiddleware.RequestUserAgent
    808 	options Options
    809 }
    810 
    811 func (m setCredentialSourceMiddleware) ID() string { return "SetCredentialSourceMiddleware" }
    812 
    813 func (m setCredentialSourceMiddleware) HandleBuild(ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler) (
    814 	out middleware.BuildOutput, metadata middleware.Metadata, err error,
    815 ) {
    816 	asProviderSource, ok := m.options.Credentials.(aws.CredentialProviderSource)
    817 	if !ok {
    818 		return next.HandleBuild(ctx, in)
    819 	}
    820 	providerSources := asProviderSource.ProviderSources()
    821 	for _, source := range providerSources {
    822 		m.ua.AddCredentialsSource(source)
    823 	}
    824 	return next.HandleBuild(ctx, in)
    825 }
    826 
    827 func addCredentialSource(stack *middleware.Stack, options Options) error {
    828 	ua, err := getOrAddRequestUserAgent(stack)
    829 	if err != nil {
    830 		return err
    831 	}
    832 
    833 	mw := setCredentialSourceMiddleware{ua: ua, options: options}
    834 	return stack.Build.Insert(&mw, "UserAgent", middleware.Before)
    835 }
    836 
    837 func resolveTracerProvider(options *Options) {
    838 	if options.TracerProvider == nil {
    839 		options.TracerProvider = &tracing.NopTracerProvider{}
    840 	}
    841 }
    842 
    843 func resolveMeterProvider(options *Options) {
    844 	if options.MeterProvider == nil {
    845 		options.MeterProvider = metrics.NopMeterProvider{}
    846 	}
    847 }
    848 
    849 func resolveServiceMetadata(ctx context.Context, options Options, operation string) context.Context {
    850 	ctx = awsmiddleware.SetServiceID(ctx, ServiceID)
    851 	if options.Region != "" {
    852 		ctx = awsmiddleware.SetRegion(ctx, options.Region)
    853 	}
    854 	ctx = awsmiddleware.SetOperationName(ctx, operation)
    855 	if options.EndpointResolver != nil {
    856 		ctx = awsmiddleware.SetRequiresLegacyEndpoints(ctx, true)
    857 	}
    858 	return ctx
    859 }
    860 
    861 func addRecursionDetection(stack *middleware.Stack) error {
    862 	return stack.Build.Add(&awsmiddleware.RecursionDetection{}, middleware.After)
    863 }
    864 
    865 func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error {
    866 	return stack.Deserialize.Insert(&awsmiddleware.RequestIDRetriever{}, "OperationDeserializer", middleware.Before)
    867 
    868 }
    869 
    870 func addResponseErrorMiddleware(stack *middleware.Stack) error {
    871 	return stack.Deserialize.Insert(&awshttp.ResponseErrorWrapper{}, "RequestIDRetriever", middleware.Before)
    872 
    873 }
    874 
    875 func addRequestResponseLogging(stack *middleware.Stack, o Options) error {
    876 	return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{
    877 		LogRequest:          o.ClientLogMode.IsRequest(),
    878 		LogRequestWithBody:  o.ClientLogMode.IsRequestWithBody(),
    879 		LogResponse:         o.ClientLogMode.IsResponse(),
    880 		LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(),
    881 	}, middleware.After)
    882 }
    883 
    884 type disableHTTPSMiddleware struct {
    885 	DisableHTTPS bool
    886 }
    887 
    888 func (*disableHTTPSMiddleware) ID() string {
    889 	return "disableHTTPS"
    890 }
    891 
    892 func (m *disableHTTPSMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
    893 	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
    894 ) {
    895 	req, ok := in.Request.(*smithyhttp.Request)
    896 	if !ok {
    897 		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
    898 	}
    899 
    900 	if m.DisableHTTPS && !smithyhttp.GetHostnameImmutable(ctx) {
    901 		req.URL.Scheme = "http"
    902 	}
    903 
    904 	return next.HandleFinalize(ctx, in)
    905 }
    906 
    907 func addDisableHTTPSMiddleware(stack *middleware.Stack, o Options) error {
    908 	return stack.Finalize.Insert(&disableHTTPSMiddleware{
    909 		DisableHTTPS: o.EndpointOptions.DisableHTTPS,
    910 	}, "ResolveEndpointV2", middleware.After)
    911 }
    912 
    913 func addInterceptBeforeRetryLoop(stack *middleware.Stack, opts Options) error {
    914 	return stack.Finalize.Insert(&smithyhttp.InterceptBeforeRetryLoop{
    915 		Interceptors: opts.Interceptors.BeforeRetryLoop,
    916 	}, "Retry", middleware.Before)
    917 }
    918 
    919 func addInterceptAttempt(stack *middleware.Stack, opts Options) error {
    920 	return stack.Finalize.Insert(&smithyhttp.InterceptAttempt{
    921 		BeforeAttempt: opts.Interceptors.BeforeAttempt,
    922 		AfterAttempt:  opts.Interceptors.AfterAttempt,
    923 	}, "Retry", middleware.After)
    924 }
    925 
    926 func addInterceptors(stack *middleware.Stack, opts Options) error {
    927 	// middlewares are expensive, don't add all of these interceptor ones unless the caller
    928 	// actually has at least one interceptor configured
    929 	//
    930 	// at the moment it's all-or-nothing because some of the middlewares here are responsible for
    931 	// setting fields in the interceptor context for future ones
    932 	if len(opts.Interceptors.BeforeExecution) == 0 &&
    933 		len(opts.Interceptors.BeforeSerialization) == 0 && len(opts.Interceptors.AfterSerialization) == 0 &&
    934 		len(opts.Interceptors.BeforeRetryLoop) == 0 &&
    935 		len(opts.Interceptors.BeforeAttempt) == 0 &&
    936 		len(opts.Interceptors.BeforeSigning) == 0 && len(opts.Interceptors.AfterSigning) == 0 &&
    937 		len(opts.Interceptors.BeforeTransmit) == 0 && len(opts.Interceptors.AfterTransmit) == 0 &&
    938 		len(opts.Interceptors.BeforeDeserialization) == 0 && len(opts.Interceptors.AfterDeserialization) == 0 &&
    939 		len(opts.Interceptors.AfterAttempt) == 0 && len(opts.Interceptors.AfterExecution) == 0 {
    940 		return nil
    941 	}
    942 
    943 	return errors.Join(
    944 		stack.Initialize.Add(&smithyhttp.InterceptExecution{
    945 			BeforeExecution: opts.Interceptors.BeforeExecution,
    946 			AfterExecution:  opts.Interceptors.AfterExecution,
    947 		}, middleware.Before),
    948 		stack.Serialize.Insert(&smithyhttp.InterceptBeforeSerialization{
    949 			Interceptors: opts.Interceptors.BeforeSerialization,
    950 		}, "OperationSerializer", middleware.Before),
    951 		stack.Serialize.Insert(&smithyhttp.InterceptAfterSerialization{
    952 			Interceptors: opts.Interceptors.AfterSerialization,
    953 		}, "OperationSerializer", middleware.After),
    954 		stack.Finalize.Insert(&smithyhttp.InterceptBeforeSigning{
    955 			Interceptors: opts.Interceptors.BeforeSigning,
    956 		}, "Signing", middleware.Before),
    957 		stack.Finalize.Insert(&smithyhttp.InterceptAfterSigning{
    958 			Interceptors: opts.Interceptors.AfterSigning,
    959 		}, "Signing", middleware.After),
    960 		stack.Deserialize.Add(&smithyhttp.InterceptTransmit{
    961 			BeforeTransmit: opts.Interceptors.BeforeTransmit,
    962 			AfterTransmit:  opts.Interceptors.AfterTransmit,
    963 		}, middleware.After),
    964 		stack.Deserialize.Insert(&smithyhttp.InterceptBeforeDeserialization{
    965 			Interceptors: opts.Interceptors.BeforeDeserialization,
    966 		}, "OperationDeserializer", middleware.After), // (deserialize stack is called in reverse)
    967 		stack.Deserialize.Insert(&smithyhttp.InterceptAfterDeserialization{
    968 			Interceptors: opts.Interceptors.AfterDeserialization,
    969 		}, "OperationDeserializer", middleware.Before),
    970 	)
    971 }