api_client.go (20563B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package sts 4 5 import ( 6 "context" 7 "fmt" 8 "github.com/aws/aws-sdk-go-v2/aws" 9 "github.com/aws/aws-sdk-go-v2/aws/defaults" 10 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 11 "github.com/aws/aws-sdk-go-v2/aws/protocol/query" 12 "github.com/aws/aws-sdk-go-v2/aws/retry" 13 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 14 awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" 15 internalauth "github.com/aws/aws-sdk-go-v2/internal/auth" 16 internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy" 17 internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" 18 acceptencodingcust "github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding" 19 presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" 20 smithy "github.com/aws/smithy-go" 21 smithydocument "github.com/aws/smithy-go/document" 22 "github.com/aws/smithy-go/logging" 23 "github.com/aws/smithy-go/middleware" 24 smithyhttp "github.com/aws/smithy-go/transport/http" 25 "net" 26 "net/http" 27 "time" 28 ) 29 30 const ServiceID = "STS" 31 const ServiceAPIVersion = "2011-06-15" 32 33 // Client provides the API client to make operations call for AWS Security Token 34 // Service. 35 type Client struct { 36 options Options 37 } 38 39 // New returns an initialized Client based on the functional options. Provide 40 // additional functional options to further configure the behavior of the client, 41 // such as changing the client's endpoint or adding custom middleware behavior. 42 func New(options Options, optFns ...func(*Options)) *Client { 43 options = options.Copy() 44 45 resolveDefaultLogger(&options) 46 47 setResolvedDefaultsMode(&options) 48 49 resolveRetryer(&options) 50 51 resolveHTTPClient(&options) 52 53 resolveHTTPSignerV4(&options) 54 55 resolveEndpointResolverV2(&options) 56 57 resolveAuthSchemeResolver(&options) 58 59 for _, fn := range optFns { 60 fn(&options) 61 } 62 63 finalizeRetryMaxAttempts(&options) 64 65 ignoreAnonymousAuth(&options) 66 67 wrapWithAnonymousAuth(&options) 68 69 resolveAuthSchemes(&options) 70 71 client := &Client{ 72 options: options, 73 } 74 75 return client 76 } 77 78 // Options returns a copy of the client configuration. 79 // 80 // Callers SHOULD NOT perform mutations on any inner structures within client 81 // config. Config overrides should instead be made on a per-operation basis through 82 // functional options. 83 func (c *Client) Options() Options { 84 return c.options.Copy() 85 } 86 87 func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { 88 ctx = middleware.ClearStackValues(ctx) 89 stack := middleware.NewStack(opID, smithyhttp.NewStackRequest) 90 options := c.options.Copy() 91 92 for _, fn := range optFns { 93 fn(&options) 94 } 95 96 finalizeOperationRetryMaxAttempts(&options, *c) 97 98 finalizeClientEndpointResolverOptions(&options) 99 100 for _, fn := range stackFns { 101 if err := fn(stack, options); err != nil { 102 return nil, metadata, err 103 } 104 } 105 106 for _, fn := range options.APIOptions { 107 if err := fn(stack); err != nil { 108 return nil, metadata, err 109 } 110 } 111 112 handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack) 113 result, metadata, err = handler.Handle(ctx, params) 114 if err != nil { 115 err = &smithy.OperationError{ 116 ServiceID: ServiceID, 117 OperationName: opID, 118 Err: err, 119 } 120 } 121 return result, metadata, err 122 } 123 124 type operationInputKey struct{} 125 126 func setOperationInput(ctx context.Context, input interface{}) context.Context { 127 return middleware.WithStackValue(ctx, operationInputKey{}, input) 128 } 129 130 func getOperationInput(ctx context.Context) interface{} { 131 return middleware.GetStackValue(ctx, operationInputKey{}) 132 } 133 134 type setOperationInputMiddleware struct { 135 } 136 137 func (*setOperationInputMiddleware) ID() string { 138 return "setOperationInput" 139 } 140 141 func (m *setOperationInputMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( 142 out middleware.SerializeOutput, metadata middleware.Metadata, err error, 143 ) { 144 ctx = setOperationInput(ctx, in.Parameters) 145 return next.HandleSerialize(ctx, in) 146 } 147 148 func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, operation string) error { 149 if err := stack.Finalize.Add(&resolveAuthSchemeMiddleware{operation: operation, options: options}, middleware.Before); err != nil { 150 return fmt.Errorf("add ResolveAuthScheme: %w", err) 151 } 152 if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", middleware.After); err != nil { 153 return fmt.Errorf("add GetIdentity: %v", err) 154 } 155 if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", middleware.After); err != nil { 156 return fmt.Errorf("add ResolveEndpointV2: %v", err) 157 } 158 if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", middleware.After); err != nil { 159 return fmt.Errorf("add Signing: %w", err) 160 } 161 return nil 162 } 163 func resolveAuthSchemeResolver(options *Options) { 164 if options.AuthSchemeResolver == nil { 165 options.AuthSchemeResolver = &defaultAuthSchemeResolver{} 166 } 167 } 168 169 func resolveAuthSchemes(options *Options) { 170 if options.AuthSchemes == nil { 171 options.AuthSchemes = []smithyhttp.AuthScheme{ 172 internalauth.NewHTTPAuthScheme("aws.auth#sigv4", &internalauthsmithy.V4SignerAdapter{ 173 Signer: options.HTTPSignerV4, 174 Logger: options.Logger, 175 LogSigning: options.ClientLogMode.IsSigning(), 176 }), 177 } 178 } 179 } 180 181 type noSmithyDocumentSerde = smithydocument.NoSerde 182 183 type legacyEndpointContextSetter struct { 184 LegacyResolver EndpointResolver 185 } 186 187 func (*legacyEndpointContextSetter) ID() string { 188 return "legacyEndpointContextSetter" 189 } 190 191 func (m *legacyEndpointContextSetter) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( 192 out middleware.InitializeOutput, metadata middleware.Metadata, err error, 193 ) { 194 if m.LegacyResolver != nil { 195 ctx = awsmiddleware.SetRequiresLegacyEndpoints(ctx, true) 196 } 197 198 return next.HandleInitialize(ctx, in) 199 200 } 201 func addlegacyEndpointContextSetter(stack *middleware.Stack, o Options) error { 202 return stack.Initialize.Add(&legacyEndpointContextSetter{ 203 LegacyResolver: o.EndpointResolver, 204 }, middleware.Before) 205 } 206 207 func resolveDefaultLogger(o *Options) { 208 if o.Logger != nil { 209 return 210 } 211 o.Logger = logging.Nop{} 212 } 213 214 func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { 215 return middleware.AddSetLoggerMiddleware(stack, o.Logger) 216 } 217 218 func setResolvedDefaultsMode(o *Options) { 219 if len(o.resolvedDefaultsMode) > 0 { 220 return 221 } 222 223 var mode aws.DefaultsMode 224 mode.SetFromString(string(o.DefaultsMode)) 225 226 if mode == aws.DefaultsModeAuto { 227 mode = defaults.ResolveDefaultsModeAuto(o.Region, o.RuntimeEnvironment) 228 } 229 230 o.resolvedDefaultsMode = mode 231 } 232 233 // NewFromConfig returns a new client from the provided config. 234 func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { 235 opts := Options{ 236 Region: cfg.Region, 237 DefaultsMode: cfg.DefaultsMode, 238 RuntimeEnvironment: cfg.RuntimeEnvironment, 239 HTTPClient: cfg.HTTPClient, 240 Credentials: cfg.Credentials, 241 APIOptions: cfg.APIOptions, 242 Logger: cfg.Logger, 243 ClientLogMode: cfg.ClientLogMode, 244 AppID: cfg.AppID, 245 } 246 resolveAWSRetryerProvider(cfg, &opts) 247 resolveAWSRetryMaxAttempts(cfg, &opts) 248 resolveAWSRetryMode(cfg, &opts) 249 resolveAWSEndpointResolver(cfg, &opts) 250 resolveUseDualStackEndpoint(cfg, &opts) 251 resolveUseFIPSEndpoint(cfg, &opts) 252 resolveBaseEndpoint(cfg, &opts) 253 return New(opts, optFns...) 254 } 255 256 func resolveHTTPClient(o *Options) { 257 var buildable *awshttp.BuildableClient 258 259 if o.HTTPClient != nil { 260 var ok bool 261 buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) 262 if !ok { 263 return 264 } 265 } else { 266 buildable = awshttp.NewBuildableClient() 267 } 268 269 modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode) 270 if err == nil { 271 buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { 272 if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { 273 dialer.Timeout = dialerTimeout 274 } 275 }) 276 277 buildable = buildable.WithTransportOptions(func(transport *http.Transport) { 278 if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { 279 transport.TLSHandshakeTimeout = tlsHandshakeTimeout 280 } 281 }) 282 } 283 284 o.HTTPClient = buildable 285 } 286 287 func resolveRetryer(o *Options) { 288 if o.Retryer != nil { 289 return 290 } 291 292 if len(o.RetryMode) == 0 { 293 modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode) 294 if err == nil { 295 o.RetryMode = modeConfig.RetryMode 296 } 297 } 298 if len(o.RetryMode) == 0 { 299 o.RetryMode = aws.RetryModeStandard 300 } 301 302 var standardOptions []func(*retry.StandardOptions) 303 if v := o.RetryMaxAttempts; v != 0 { 304 standardOptions = append(standardOptions, func(so *retry.StandardOptions) { 305 so.MaxAttempts = v 306 }) 307 } 308 309 switch o.RetryMode { 310 case aws.RetryModeAdaptive: 311 var adaptiveOptions []func(*retry.AdaptiveModeOptions) 312 if len(standardOptions) != 0 { 313 adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) { 314 ao.StandardOptions = append(ao.StandardOptions, standardOptions...) 315 }) 316 } 317 o.Retryer = retry.NewAdaptiveMode(adaptiveOptions...) 318 319 default: 320 o.Retryer = retry.NewStandard(standardOptions...) 321 } 322 } 323 324 func resolveAWSRetryerProvider(cfg aws.Config, o *Options) { 325 if cfg.Retryer == nil { 326 return 327 } 328 o.Retryer = cfg.Retryer() 329 } 330 331 func resolveAWSRetryMode(cfg aws.Config, o *Options) { 332 if len(cfg.RetryMode) == 0 { 333 return 334 } 335 o.RetryMode = cfg.RetryMode 336 } 337 func resolveAWSRetryMaxAttempts(cfg aws.Config, o *Options) { 338 if cfg.RetryMaxAttempts == 0 { 339 return 340 } 341 o.RetryMaxAttempts = cfg.RetryMaxAttempts 342 } 343 344 func finalizeRetryMaxAttempts(o *Options) { 345 if o.RetryMaxAttempts == 0 { 346 return 347 } 348 349 o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts) 350 } 351 352 func finalizeOperationRetryMaxAttempts(o *Options, client Client) { 353 if v := o.RetryMaxAttempts; v == 0 || v == client.options.RetryMaxAttempts { 354 return 355 } 356 357 o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts) 358 } 359 360 func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { 361 if cfg.EndpointResolver == nil && cfg.EndpointResolverWithOptions == nil { 362 return 363 } 364 o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions) 365 } 366 367 func addClientUserAgent(stack *middleware.Stack, options Options) error { 368 ua, err := getOrAddRequestUserAgent(stack) 369 if err != nil { 370 return err 371 } 372 373 ua.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "sts", goModuleVersion) 374 if len(options.AppID) > 0 { 375 ua.AddSDKAgentKey(awsmiddleware.ApplicationIdentifier, options.AppID) 376 } 377 378 return nil 379 } 380 381 func getOrAddRequestUserAgent(stack *middleware.Stack) (*awsmiddleware.RequestUserAgent, error) { 382 id := (*awsmiddleware.RequestUserAgent)(nil).ID() 383 mw, ok := stack.Build.Get(id) 384 if !ok { 385 mw = awsmiddleware.NewRequestUserAgent() 386 if err := stack.Build.Add(mw, middleware.After); err != nil { 387 return nil, err 388 } 389 } 390 391 ua, ok := mw.(*awsmiddleware.RequestUserAgent) 392 if !ok { 393 return nil, fmt.Errorf("%T for %s middleware did not match expected type", mw, id) 394 } 395 396 return ua, nil 397 } 398 399 type HTTPSignerV4 interface { 400 SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4.SignerOptions)) error 401 } 402 403 func resolveHTTPSignerV4(o *Options) { 404 if o.HTTPSignerV4 != nil { 405 return 406 } 407 o.HTTPSignerV4 = newDefaultV4Signer(*o) 408 } 409 410 func newDefaultV4Signer(o Options) *v4.Signer { 411 return v4.NewSigner(func(so *v4.SignerOptions) { 412 so.Logger = o.Logger 413 so.LogSigning = o.ClientLogMode.IsSigning() 414 }) 415 } 416 417 func addClientRequestID(stack *middleware.Stack) error { 418 return stack.Build.Add(&awsmiddleware.ClientRequestID{}, middleware.After) 419 } 420 421 func addComputeContentLength(stack *middleware.Stack) error { 422 return stack.Build.Add(&smithyhttp.ComputeContentLength{}, middleware.After) 423 } 424 425 func addRawResponseToMetadata(stack *middleware.Stack) error { 426 return stack.Deserialize.Add(&awsmiddleware.AddRawResponse{}, middleware.Before) 427 } 428 429 func addRecordResponseTiming(stack *middleware.Stack) error { 430 return stack.Deserialize.Add(&awsmiddleware.RecordResponseTiming{}, middleware.After) 431 } 432 func addStreamingEventsPayload(stack *middleware.Stack) error { 433 return stack.Finalize.Add(&v4.StreamingEventsPayload{}, middleware.Before) 434 } 435 436 func addUnsignedPayload(stack *middleware.Stack) error { 437 return stack.Finalize.Insert(&v4.UnsignedPayload{}, "ResolveEndpointV2", middleware.After) 438 } 439 440 func addComputePayloadSHA256(stack *middleware.Stack) error { 441 return stack.Finalize.Insert(&v4.ComputePayloadSHA256{}, "ResolveEndpointV2", middleware.After) 442 } 443 444 func addContentSHA256Header(stack *middleware.Stack) error { 445 return stack.Finalize.Insert(&v4.ContentSHA256Header{}, (*v4.ComputePayloadSHA256)(nil).ID(), middleware.After) 446 } 447 448 func addRetry(stack *middleware.Stack, o Options) error { 449 attempt := retry.NewAttemptMiddleware(o.Retryer, smithyhttp.RequestCloner, func(m *retry.Attempt) { 450 m.LogAttempts = o.ClientLogMode.IsRetries() 451 }) 452 if err := stack.Finalize.Insert(attempt, "Signing", middleware.Before); err != nil { 453 return err 454 } 455 if err := stack.Finalize.Insert(&retry.MetricsHeader{}, attempt.ID(), middleware.After); err != nil { 456 return err 457 } 458 return nil 459 } 460 461 // resolves dual-stack endpoint configuration 462 func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { 463 if len(cfg.ConfigSources) == 0 { 464 return nil 465 } 466 value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) 467 if err != nil { 468 return err 469 } 470 if found { 471 o.EndpointOptions.UseDualStackEndpoint = value 472 } 473 return nil 474 } 475 476 // resolves FIPS endpoint configuration 477 func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { 478 if len(cfg.ConfigSources) == 0 { 479 return nil 480 } 481 value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) 482 if err != nil { 483 return err 484 } 485 if found { 486 o.EndpointOptions.UseFIPSEndpoint = value 487 } 488 return nil 489 } 490 491 func addRecursionDetection(stack *middleware.Stack) error { 492 return stack.Build.Add(&awsmiddleware.RecursionDetection{}, middleware.After) 493 } 494 495 func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { 496 return stack.Deserialize.Insert(&awsmiddleware.RequestIDRetriever{}, "OperationDeserializer", middleware.Before) 497 498 } 499 500 func addResponseErrorMiddleware(stack *middleware.Stack) error { 501 return stack.Deserialize.Insert(&awshttp.ResponseErrorWrapper{}, "RequestIDRetriever", middleware.Before) 502 503 } 504 505 // HTTPPresignerV4 represents presigner interface used by presign url client 506 type HTTPPresignerV4 interface { 507 PresignHTTP( 508 ctx context.Context, credentials aws.Credentials, r *http.Request, 509 payloadHash string, service string, region string, signingTime time.Time, 510 optFns ...func(*v4.SignerOptions), 511 ) (url string, signedHeader http.Header, err error) 512 } 513 514 // PresignOptions represents the presign client options 515 type PresignOptions struct { 516 517 // ClientOptions are list of functional options to mutate client options used by 518 // the presign client. 519 ClientOptions []func(*Options) 520 521 // Presigner is the presigner used by the presign url client 522 Presigner HTTPPresignerV4 523 } 524 525 func (o PresignOptions) copy() PresignOptions { 526 clientOptions := make([]func(*Options), len(o.ClientOptions)) 527 copy(clientOptions, o.ClientOptions) 528 o.ClientOptions = clientOptions 529 return o 530 } 531 532 // WithPresignClientFromClientOptions is a helper utility to retrieve a function 533 // that takes PresignOption as input 534 func WithPresignClientFromClientOptions(optFns ...func(*Options)) func(*PresignOptions) { 535 return withPresignClientFromClientOptions(optFns).options 536 } 537 538 type withPresignClientFromClientOptions []func(*Options) 539 540 func (w withPresignClientFromClientOptions) options(o *PresignOptions) { 541 o.ClientOptions = append(o.ClientOptions, w...) 542 } 543 544 // PresignClient represents the presign url client 545 type PresignClient struct { 546 client *Client 547 options PresignOptions 548 } 549 550 // NewPresignClient generates a presign client using provided API Client and 551 // presign options 552 func NewPresignClient(c *Client, optFns ...func(*PresignOptions)) *PresignClient { 553 var options PresignOptions 554 for _, fn := range optFns { 555 fn(&options) 556 } 557 if len(options.ClientOptions) != 0 { 558 c = New(c.options, options.ClientOptions...) 559 } 560 561 if options.Presigner == nil { 562 options.Presigner = newDefaultV4Signer(c.options) 563 } 564 565 return &PresignClient{ 566 client: c, 567 options: options, 568 } 569 } 570 571 func withNopHTTPClientAPIOption(o *Options) { 572 o.HTTPClient = smithyhttp.NopClient{} 573 } 574 575 type presignContextPolyfillMiddleware struct { 576 } 577 578 func (*presignContextPolyfillMiddleware) ID() string { 579 return "presignContextPolyfill" 580 } 581 582 func (m *presignContextPolyfillMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( 583 out middleware.FinalizeOutput, metadata middleware.Metadata, err error, 584 ) { 585 rscheme := getResolvedAuthScheme(ctx) 586 if rscheme == nil { 587 return out, metadata, fmt.Errorf("no resolved auth scheme") 588 } 589 590 schemeID := rscheme.Scheme.SchemeID() 591 592 if schemeID == "aws.auth#sigv4" || schemeID == "com.amazonaws.s3#sigv4express" { 593 if sn, ok := smithyhttp.GetSigV4SigningName(&rscheme.SignerProperties); ok { 594 ctx = awsmiddleware.SetSigningName(ctx, sn) 595 } 596 if sr, ok := smithyhttp.GetSigV4SigningRegion(&rscheme.SignerProperties); ok { 597 ctx = awsmiddleware.SetSigningRegion(ctx, sr) 598 } 599 } else if schemeID == "aws.auth#sigv4a" { 600 if sn, ok := smithyhttp.GetSigV4ASigningName(&rscheme.SignerProperties); ok { 601 ctx = awsmiddleware.SetSigningName(ctx, sn) 602 } 603 if sr, ok := smithyhttp.GetSigV4ASigningRegions(&rscheme.SignerProperties); ok { 604 ctx = awsmiddleware.SetSigningRegion(ctx, sr[0]) 605 } 606 } 607 608 return next.HandleFinalize(ctx, in) 609 } 610 611 type presignConverter PresignOptions 612 613 func (c presignConverter) convertToPresignMiddleware(stack *middleware.Stack, options Options) (err error) { 614 if _, ok := stack.Finalize.Get((*acceptencodingcust.DisableGzip)(nil).ID()); ok { 615 stack.Finalize.Remove((*acceptencodingcust.DisableGzip)(nil).ID()) 616 } 617 if _, ok := stack.Finalize.Get((*retry.Attempt)(nil).ID()); ok { 618 stack.Finalize.Remove((*retry.Attempt)(nil).ID()) 619 } 620 if _, ok := stack.Finalize.Get((*retry.MetricsHeader)(nil).ID()); ok { 621 stack.Finalize.Remove((*retry.MetricsHeader)(nil).ID()) 622 } 623 stack.Deserialize.Clear() 624 stack.Build.Remove((*awsmiddleware.ClientRequestID)(nil).ID()) 625 stack.Build.Remove("UserAgent") 626 if err := stack.Finalize.Insert(&presignContextPolyfillMiddleware{}, "Signing", middleware.Before); err != nil { 627 return err 628 } 629 630 pmw := v4.NewPresignHTTPRequestMiddleware(v4.PresignHTTPRequestMiddlewareOptions{ 631 CredentialsProvider: options.Credentials, 632 Presigner: c.Presigner, 633 LogSigning: options.ClientLogMode.IsSigning(), 634 }) 635 if _, err := stack.Finalize.Swap("Signing", pmw); err != nil { 636 return err 637 } 638 if err = smithyhttp.AddNoPayloadDefaultContentTypeRemover(stack); err != nil { 639 return err 640 } 641 // convert request to a GET request 642 err = query.AddAsGetRequestMiddleware(stack) 643 if err != nil { 644 return err 645 } 646 err = presignedurlcust.AddAsIsPresigingMiddleware(stack) 647 if err != nil { 648 return err 649 } 650 return nil 651 } 652 653 func addRequestResponseLogging(stack *middleware.Stack, o Options) error { 654 return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{ 655 LogRequest: o.ClientLogMode.IsRequest(), 656 LogRequestWithBody: o.ClientLogMode.IsRequestWithBody(), 657 LogResponse: o.ClientLogMode.IsResponse(), 658 LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(), 659 }, middleware.After) 660 } 661 662 type disableHTTPSMiddleware struct { 663 DisableHTTPS bool 664 } 665 666 func (*disableHTTPSMiddleware) ID() string { 667 return "disableHTTPS" 668 } 669 670 func (m *disableHTTPSMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) ( 671 out middleware.FinalizeOutput, metadata middleware.Metadata, err error, 672 ) { 673 req, ok := in.Request.(*smithyhttp.Request) 674 if !ok { 675 return out, metadata, fmt.Errorf("unknown transport type %T", in.Request) 676 } 677 678 if m.DisableHTTPS && !smithyhttp.GetHostnameImmutable(ctx) { 679 req.URL.Scheme = "http" 680 } 681 682 return next.HandleFinalize(ctx, in) 683 } 684 685 func addDisableHTTPSMiddleware(stack *middleware.Stack, o Options) error { 686 return stack.Finalize.Insert(&disableHTTPSMiddleware{ 687 DisableHTTPS: o.EndpointOptions.DisableHTTPS, 688 }, "ResolveEndpointV2", middleware.After) 689 }