api_client.go (13139B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package ssooidc 4 5 import ( 6 "context" 7 "github.com/aws/aws-sdk-go-v2/aws" 8 "github.com/aws/aws-sdk-go-v2/aws/defaults" 9 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 10 "github.com/aws/aws-sdk-go-v2/aws/retry" 11 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 12 awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" 13 internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources" 14 smithy "github.com/aws/smithy-go" 15 smithydocument "github.com/aws/smithy-go/document" 16 "github.com/aws/smithy-go/logging" 17 "github.com/aws/smithy-go/middleware" 18 smithyhttp "github.com/aws/smithy-go/transport/http" 19 "net" 20 "net/http" 21 "time" 22 ) 23 24 const ServiceID = "SSO OIDC" 25 const ServiceAPIVersion = "2019-06-10" 26 27 // Client provides the API client to make operations call for AWS SSO OIDC. 28 type Client struct { 29 options Options 30 } 31 32 // New returns an initialized Client based on the functional options. Provide 33 // additional functional options to further configure the behavior of the client, 34 // such as changing the client's endpoint or adding custom middleware behavior. 35 func New(options Options, optFns ...func(*Options)) *Client { 36 options = options.Copy() 37 38 resolveDefaultLogger(&options) 39 40 setResolvedDefaultsMode(&options) 41 42 resolveRetryer(&options) 43 44 resolveHTTPClient(&options) 45 46 resolveHTTPSignerV4(&options) 47 48 resolveDefaultEndpointConfiguration(&options) 49 50 for _, fn := range optFns { 51 fn(&options) 52 } 53 54 client := &Client{ 55 options: options, 56 } 57 58 return client 59 } 60 61 type Options struct { 62 // Set of options to modify how an operation is invoked. These apply to all 63 // operations invoked for this client. Use functional options on operation call to 64 // modify this list for per operation behavior. 65 APIOptions []func(*middleware.Stack) error 66 67 // Configures the events that will be sent to the configured logger. 68 ClientLogMode aws.ClientLogMode 69 70 // The credentials object to use when signing requests. 71 Credentials aws.CredentialsProvider 72 73 // The configuration DefaultsMode that the SDK should use when constructing the 74 // clients initial default settings. 75 DefaultsMode aws.DefaultsMode 76 77 // The endpoint options to be used when attempting to resolve an endpoint. 78 EndpointOptions EndpointResolverOptions 79 80 // The service endpoint resolver. 81 EndpointResolver EndpointResolver 82 83 // Signature Version 4 (SigV4) Signer 84 HTTPSignerV4 HTTPSignerV4 85 86 // The logger writer interface to write logging messages to. 87 Logger logging.Logger 88 89 // The region to send requests to. (Required) 90 Region string 91 92 // RetryMaxAttempts specifies the maximum number attempts an API client will call 93 // an operation that fails with a retryable error. A value of 0 is ignored, and 94 // will not be used to configure the API client created default retryer, or modify 95 // per operation call's retry max attempts. When creating a new API Clients this 96 // member will only be used if the Retryer Options member is nil. This value will 97 // be ignored if Retryer is not nil. If specified in an operation call's functional 98 // options with a value that is different than the constructed client's Options, 99 // the Client's Retryer will be wrapped to use the operation's specific 100 // RetryMaxAttempts value. 101 RetryMaxAttempts int 102 103 // RetryMode specifies the retry mode the API client will be created with, if 104 // Retryer option is not also specified. When creating a new API Clients this 105 // member will only be used if the Retryer Options member is nil. This value will 106 // be ignored if Retryer is not nil. Currently does not support per operation call 107 // overrides, may in the future. 108 RetryMode aws.RetryMode 109 110 // Retryer guides how HTTP requests should be retried in case of recoverable 111 // failures. When nil the API client will use a default retryer. The kind of 112 // default retry created by the API client can be changed with the RetryMode 113 // option. 114 Retryer aws.Retryer 115 116 // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set 117 // to DefaultsModeAuto and is initialized using config.LoadDefaultConfig. You 118 // should not populate this structure programmatically, or rely on the values here 119 // within your applications. 120 RuntimeEnvironment aws.RuntimeEnvironment 121 122 // The initial DefaultsMode used when the client options were constructed. If the 123 // DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved 124 // value was at that point in time. Currently does not support per operation call 125 // overrides, may in the future. 126 resolvedDefaultsMode aws.DefaultsMode 127 128 // The HTTP client to invoke API calls with. Defaults to client's default HTTP 129 // implementation if nil. 130 HTTPClient HTTPClient 131 } 132 133 // WithAPIOptions returns a functional option for setting the Client's APIOptions 134 // option. 135 func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) { 136 return func(o *Options) { 137 o.APIOptions = append(o.APIOptions, optFns...) 138 } 139 } 140 141 // WithEndpointResolver returns a functional option for setting the Client's 142 // EndpointResolver option. 143 func WithEndpointResolver(v EndpointResolver) func(*Options) { 144 return func(o *Options) { 145 o.EndpointResolver = v 146 } 147 } 148 149 type HTTPClient interface { 150 Do(*http.Request) (*http.Response, error) 151 } 152 153 // Copy creates a clone where the APIOptions list is deep copied. 154 func (o Options) Copy() Options { 155 to := o 156 to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) 157 copy(to.APIOptions, o.APIOptions) 158 159 return to 160 } 161 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) { 162 ctx = middleware.ClearStackValues(ctx) 163 stack := middleware.NewStack(opID, smithyhttp.NewStackRequest) 164 options := c.options.Copy() 165 for _, fn := range optFns { 166 fn(&options) 167 } 168 169 finalizeRetryMaxAttemptOptions(&options, *c) 170 171 finalizeClientEndpointResolverOptions(&options) 172 173 for _, fn := range stackFns { 174 if err := fn(stack, options); err != nil { 175 return nil, metadata, err 176 } 177 } 178 179 for _, fn := range options.APIOptions { 180 if err := fn(stack); err != nil { 181 return nil, metadata, err 182 } 183 } 184 185 handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack) 186 result, metadata, err = handler.Handle(ctx, params) 187 if err != nil { 188 err = &smithy.OperationError{ 189 ServiceID: ServiceID, 190 OperationName: opID, 191 Err: err, 192 } 193 } 194 return result, metadata, err 195 } 196 197 type noSmithyDocumentSerde = smithydocument.NoSerde 198 199 func resolveDefaultLogger(o *Options) { 200 if o.Logger != nil { 201 return 202 } 203 o.Logger = logging.Nop{} 204 } 205 206 func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { 207 return middleware.AddSetLoggerMiddleware(stack, o.Logger) 208 } 209 210 func setResolvedDefaultsMode(o *Options) { 211 if len(o.resolvedDefaultsMode) > 0 { 212 return 213 } 214 215 var mode aws.DefaultsMode 216 mode.SetFromString(string(o.DefaultsMode)) 217 218 if mode == aws.DefaultsModeAuto { 219 mode = defaults.ResolveDefaultsModeAuto(o.Region, o.RuntimeEnvironment) 220 } 221 222 o.resolvedDefaultsMode = mode 223 } 224 225 // NewFromConfig returns a new client from the provided config. 226 func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { 227 opts := Options{ 228 Region: cfg.Region, 229 DefaultsMode: cfg.DefaultsMode, 230 RuntimeEnvironment: cfg.RuntimeEnvironment, 231 HTTPClient: cfg.HTTPClient, 232 Credentials: cfg.Credentials, 233 APIOptions: cfg.APIOptions, 234 Logger: cfg.Logger, 235 ClientLogMode: cfg.ClientLogMode, 236 } 237 resolveAWSRetryerProvider(cfg, &opts) 238 resolveAWSRetryMaxAttempts(cfg, &opts) 239 resolveAWSRetryMode(cfg, &opts) 240 resolveAWSEndpointResolver(cfg, &opts) 241 resolveUseDualStackEndpoint(cfg, &opts) 242 resolveUseFIPSEndpoint(cfg, &opts) 243 return New(opts, optFns...) 244 } 245 246 func resolveHTTPClient(o *Options) { 247 var buildable *awshttp.BuildableClient 248 249 if o.HTTPClient != nil { 250 var ok bool 251 buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) 252 if !ok { 253 return 254 } 255 } else { 256 buildable = awshttp.NewBuildableClient() 257 } 258 259 modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode) 260 if err == nil { 261 buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { 262 if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { 263 dialer.Timeout = dialerTimeout 264 } 265 }) 266 267 buildable = buildable.WithTransportOptions(func(transport *http.Transport) { 268 if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { 269 transport.TLSHandshakeTimeout = tlsHandshakeTimeout 270 } 271 }) 272 } 273 274 o.HTTPClient = buildable 275 } 276 277 func resolveRetryer(o *Options) { 278 if o.Retryer != nil { 279 return 280 } 281 282 if len(o.RetryMode) == 0 { 283 modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode) 284 if err == nil { 285 o.RetryMode = modeConfig.RetryMode 286 } 287 } 288 if len(o.RetryMode) == 0 { 289 o.RetryMode = aws.RetryModeStandard 290 } 291 292 var standardOptions []func(*retry.StandardOptions) 293 if v := o.RetryMaxAttempts; v != 0 { 294 standardOptions = append(standardOptions, func(so *retry.StandardOptions) { 295 so.MaxAttempts = v 296 }) 297 } 298 299 switch o.RetryMode { 300 case aws.RetryModeAdaptive: 301 var adaptiveOptions []func(*retry.AdaptiveModeOptions) 302 if len(standardOptions) != 0 { 303 adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) { 304 ao.StandardOptions = append(ao.StandardOptions, standardOptions...) 305 }) 306 } 307 o.Retryer = retry.NewAdaptiveMode(adaptiveOptions...) 308 309 default: 310 o.Retryer = retry.NewStandard(standardOptions...) 311 } 312 } 313 314 func resolveAWSRetryerProvider(cfg aws.Config, o *Options) { 315 if cfg.Retryer == nil { 316 return 317 } 318 o.Retryer = cfg.Retryer() 319 } 320 321 func resolveAWSRetryMode(cfg aws.Config, o *Options) { 322 if len(cfg.RetryMode) == 0 { 323 return 324 } 325 o.RetryMode = cfg.RetryMode 326 } 327 func resolveAWSRetryMaxAttempts(cfg aws.Config, o *Options) { 328 if cfg.RetryMaxAttempts == 0 { 329 return 330 } 331 o.RetryMaxAttempts = cfg.RetryMaxAttempts 332 } 333 334 func finalizeRetryMaxAttemptOptions(o *Options, client Client) { 335 if v := o.RetryMaxAttempts; v == 0 || v == client.options.RetryMaxAttempts { 336 return 337 } 338 339 o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts) 340 } 341 342 func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { 343 if cfg.EndpointResolver == nil && cfg.EndpointResolverWithOptions == nil { 344 return 345 } 346 o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver()) 347 } 348 349 func addClientUserAgent(stack *middleware.Stack) error { 350 return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "ssooidc", goModuleVersion)(stack) 351 } 352 353 func addHTTPSignerV4Middleware(stack *middleware.Stack, o Options) error { 354 mw := v4.NewSignHTTPRequestMiddleware(v4.SignHTTPRequestMiddlewareOptions{ 355 CredentialsProvider: o.Credentials, 356 Signer: o.HTTPSignerV4, 357 LogSigning: o.ClientLogMode.IsSigning(), 358 }) 359 return stack.Finalize.Add(mw, middleware.After) 360 } 361 362 type HTTPSignerV4 interface { 363 SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4.SignerOptions)) error 364 } 365 366 func resolveHTTPSignerV4(o *Options) { 367 if o.HTTPSignerV4 != nil { 368 return 369 } 370 o.HTTPSignerV4 = newDefaultV4Signer(*o) 371 } 372 373 func newDefaultV4Signer(o Options) *v4.Signer { 374 return v4.NewSigner(func(so *v4.SignerOptions) { 375 so.Logger = o.Logger 376 so.LogSigning = o.ClientLogMode.IsSigning() 377 }) 378 } 379 380 func addRetryMiddlewares(stack *middleware.Stack, o Options) error { 381 mo := retry.AddRetryMiddlewaresOptions{ 382 Retryer: o.Retryer, 383 LogRetryAttempts: o.ClientLogMode.IsRetries(), 384 } 385 return retry.AddRetryMiddlewares(stack, mo) 386 } 387 388 // resolves dual-stack endpoint configuration 389 func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error { 390 if len(cfg.ConfigSources) == 0 { 391 return nil 392 } 393 value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources) 394 if err != nil { 395 return err 396 } 397 if found { 398 o.EndpointOptions.UseDualStackEndpoint = value 399 } 400 return nil 401 } 402 403 // resolves FIPS endpoint configuration 404 func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error { 405 if len(cfg.ConfigSources) == 0 { 406 return nil 407 } 408 value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources) 409 if err != nil { 410 return err 411 } 412 if found { 413 o.EndpointOptions.UseFIPSEndpoint = value 414 } 415 return nil 416 } 417 418 func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { 419 return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) 420 } 421 422 func addResponseErrorMiddleware(stack *middleware.Stack) error { 423 return awshttp.AddResponseErrorMiddleware(stack) 424 } 425 426 func addRequestResponseLogging(stack *middleware.Stack, o Options) error { 427 return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{ 428 LogRequest: o.ClientLogMode.IsRequest(), 429 LogRequestWithBody: o.ClientLogMode.IsRequestWithBody(), 430 LogResponse: o.ClientLogMode.IsResponse(), 431 LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(), 432 }, middleware.After) 433 }