123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- // Code generated by smithy-go-codegen DO NOT EDIT.
- package ssooidc
- import (
- "context"
- "github.com/aws/aws-sdk-go-v2/aws"
- "github.com/aws/aws-sdk-go-v2/aws/defaults"
- awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
- "github.com/aws/aws-sdk-go-v2/aws/retry"
- "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
- awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
- internalConfig "github.com/aws/aws-sdk-go-v2/internal/configsources"
- smithy "github.com/aws/smithy-go"
- smithydocument "github.com/aws/smithy-go/document"
- "github.com/aws/smithy-go/logging"
- "github.com/aws/smithy-go/middleware"
- smithyhttp "github.com/aws/smithy-go/transport/http"
- "net"
- "net/http"
- "time"
- )
- const ServiceID = "SSO OIDC"
- const ServiceAPIVersion = "2019-06-10"
- // Client provides the API client to make operations call for AWS SSO OIDC.
- type Client struct {
- options Options
- }
- // New returns an initialized Client based on the functional options. Provide
- // additional functional options to further configure the behavior of the client,
- // such as changing the client's endpoint or adding custom middleware behavior.
- func New(options Options, optFns ...func(*Options)) *Client {
- options = options.Copy()
- resolveDefaultLogger(&options)
- setResolvedDefaultsMode(&options)
- resolveRetryer(&options)
- resolveHTTPClient(&options)
- resolveHTTPSignerV4(&options)
- resolveDefaultEndpointConfiguration(&options)
- for _, fn := range optFns {
- fn(&options)
- }
- client := &Client{
- options: options,
- }
- return client
- }
- type Options struct {
- // Set of options to modify how an operation is invoked. These apply to all
- // operations invoked for this client. Use functional options on operation call to
- // modify this list for per operation behavior.
- APIOptions []func(*middleware.Stack) error
- // Configures the events that will be sent to the configured logger.
- ClientLogMode aws.ClientLogMode
- // The credentials object to use when signing requests.
- Credentials aws.CredentialsProvider
- // The configuration DefaultsMode that the SDK should use when constructing the
- // clients initial default settings.
- DefaultsMode aws.DefaultsMode
- // The endpoint options to be used when attempting to resolve an endpoint.
- EndpointOptions EndpointResolverOptions
- // The service endpoint resolver.
- EndpointResolver EndpointResolver
- // Signature Version 4 (SigV4) Signer
- HTTPSignerV4 HTTPSignerV4
- // The logger writer interface to write logging messages to.
- Logger logging.Logger
- // The region to send requests to. (Required)
- Region string
- // RetryMaxAttempts specifies the maximum number attempts an API client will call
- // an operation that fails with a retryable error. A value of 0 is ignored, and
- // will not be used to configure the API client created default retryer, or modify
- // per operation call's retry max attempts. When creating a new API Clients this
- // member will only be used if the Retryer Options member is nil. This value will
- // be ignored if Retryer is not nil. If specified in an operation call's functional
- // options with a value that is different than the constructed client's Options,
- // the Client's Retryer will be wrapped to use the operation's specific
- // RetryMaxAttempts value.
- RetryMaxAttempts int
- // RetryMode specifies the retry mode the API client will be created with, if
- // Retryer option is not also specified. When creating a new API Clients this
- // member will only be used if the Retryer Options member is nil. This value will
- // be ignored if Retryer is not nil. Currently does not support per operation call
- // overrides, may in the future.
- RetryMode aws.RetryMode
- // Retryer guides how HTTP requests should be retried in case of recoverable
- // failures. When nil the API client will use a default retryer. The kind of
- // default retry created by the API client can be changed with the RetryMode
- // option.
- Retryer aws.Retryer
- // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set
- // to DefaultsModeAuto and is initialized using config.LoadDefaultConfig. You
- // should not populate this structure programmatically, or rely on the values here
- // within your applications.
- RuntimeEnvironment aws.RuntimeEnvironment
- // The initial DefaultsMode used when the client options were constructed. If the
- // DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
- // value was at that point in time. Currently does not support per operation call
- // overrides, may in the future.
- resolvedDefaultsMode aws.DefaultsMode
- // The HTTP client to invoke API calls with. Defaults to client's default HTTP
- // implementation if nil.
- HTTPClient HTTPClient
- }
- // WithAPIOptions returns a functional option for setting the Client's APIOptions
- // option.
- func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) {
- return func(o *Options) {
- o.APIOptions = append(o.APIOptions, optFns...)
- }
- }
- // WithEndpointResolver returns a functional option for setting the Client's
- // EndpointResolver option.
- func WithEndpointResolver(v EndpointResolver) func(*Options) {
- return func(o *Options) {
- o.EndpointResolver = v
- }
- }
- type HTTPClient interface {
- Do(*http.Request) (*http.Response, error)
- }
- // Copy creates a clone where the APIOptions list is deep copied.
- func (o Options) Copy() Options {
- to := o
- to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions))
- copy(to.APIOptions, o.APIOptions)
- return to
- }
- 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) {
- ctx = middleware.ClearStackValues(ctx)
- stack := middleware.NewStack(opID, smithyhttp.NewStackRequest)
- options := c.options.Copy()
- for _, fn := range optFns {
- fn(&options)
- }
- finalizeRetryMaxAttemptOptions(&options, *c)
- finalizeClientEndpointResolverOptions(&options)
- for _, fn := range stackFns {
- if err := fn(stack, options); err != nil {
- return nil, metadata, err
- }
- }
- for _, fn := range options.APIOptions {
- if err := fn(stack); err != nil {
- return nil, metadata, err
- }
- }
- handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack)
- result, metadata, err = handler.Handle(ctx, params)
- if err != nil {
- err = &smithy.OperationError{
- ServiceID: ServiceID,
- OperationName: opID,
- Err: err,
- }
- }
- return result, metadata, err
- }
- type noSmithyDocumentSerde = smithydocument.NoSerde
- func resolveDefaultLogger(o *Options) {
- if o.Logger != nil {
- return
- }
- o.Logger = logging.Nop{}
- }
- func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error {
- return middleware.AddSetLoggerMiddleware(stack, o.Logger)
- }
- func setResolvedDefaultsMode(o *Options) {
- if len(o.resolvedDefaultsMode) > 0 {
- return
- }
- var mode aws.DefaultsMode
- mode.SetFromString(string(o.DefaultsMode))
- if mode == aws.DefaultsModeAuto {
- mode = defaults.ResolveDefaultsModeAuto(o.Region, o.RuntimeEnvironment)
- }
- o.resolvedDefaultsMode = mode
- }
- // NewFromConfig returns a new client from the provided config.
- func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client {
- opts := Options{
- Region: cfg.Region,
- DefaultsMode: cfg.DefaultsMode,
- RuntimeEnvironment: cfg.RuntimeEnvironment,
- HTTPClient: cfg.HTTPClient,
- Credentials: cfg.Credentials,
- APIOptions: cfg.APIOptions,
- Logger: cfg.Logger,
- ClientLogMode: cfg.ClientLogMode,
- }
- resolveAWSRetryerProvider(cfg, &opts)
- resolveAWSRetryMaxAttempts(cfg, &opts)
- resolveAWSRetryMode(cfg, &opts)
- resolveAWSEndpointResolver(cfg, &opts)
- resolveUseDualStackEndpoint(cfg, &opts)
- resolveUseFIPSEndpoint(cfg, &opts)
- return New(opts, optFns...)
- }
- func resolveHTTPClient(o *Options) {
- var buildable *awshttp.BuildableClient
- if o.HTTPClient != nil {
- var ok bool
- buildable, ok = o.HTTPClient.(*awshttp.BuildableClient)
- if !ok {
- return
- }
- } else {
- buildable = awshttp.NewBuildableClient()
- }
- modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode)
- if err == nil {
- buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) {
- if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok {
- dialer.Timeout = dialerTimeout
- }
- })
- buildable = buildable.WithTransportOptions(func(transport *http.Transport) {
- if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok {
- transport.TLSHandshakeTimeout = tlsHandshakeTimeout
- }
- })
- }
- o.HTTPClient = buildable
- }
- func resolveRetryer(o *Options) {
- if o.Retryer != nil {
- return
- }
- if len(o.RetryMode) == 0 {
- modeConfig, err := defaults.GetModeConfiguration(o.resolvedDefaultsMode)
- if err == nil {
- o.RetryMode = modeConfig.RetryMode
- }
- }
- if len(o.RetryMode) == 0 {
- o.RetryMode = aws.RetryModeStandard
- }
- var standardOptions []func(*retry.StandardOptions)
- if v := o.RetryMaxAttempts; v != 0 {
- standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
- so.MaxAttempts = v
- })
- }
- switch o.RetryMode {
- case aws.RetryModeAdaptive:
- var adaptiveOptions []func(*retry.AdaptiveModeOptions)
- if len(standardOptions) != 0 {
- adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) {
- ao.StandardOptions = append(ao.StandardOptions, standardOptions...)
- })
- }
- o.Retryer = retry.NewAdaptiveMode(adaptiveOptions...)
- default:
- o.Retryer = retry.NewStandard(standardOptions...)
- }
- }
- func resolveAWSRetryerProvider(cfg aws.Config, o *Options) {
- if cfg.Retryer == nil {
- return
- }
- o.Retryer = cfg.Retryer()
- }
- func resolveAWSRetryMode(cfg aws.Config, o *Options) {
- if len(cfg.RetryMode) == 0 {
- return
- }
- o.RetryMode = cfg.RetryMode
- }
- func resolveAWSRetryMaxAttempts(cfg aws.Config, o *Options) {
- if cfg.RetryMaxAttempts == 0 {
- return
- }
- o.RetryMaxAttempts = cfg.RetryMaxAttempts
- }
- func finalizeRetryMaxAttemptOptions(o *Options, client Client) {
- if v := o.RetryMaxAttempts; v == 0 || v == client.options.RetryMaxAttempts {
- return
- }
- o.Retryer = retry.AddWithMaxAttempts(o.Retryer, o.RetryMaxAttempts)
- }
- func resolveAWSEndpointResolver(cfg aws.Config, o *Options) {
- if cfg.EndpointResolver == nil && cfg.EndpointResolverWithOptions == nil {
- return
- }
- o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, cfg.EndpointResolverWithOptions, NewDefaultEndpointResolver())
- }
- func addClientUserAgent(stack *middleware.Stack) error {
- return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "ssooidc", goModuleVersion)(stack)
- }
- func addHTTPSignerV4Middleware(stack *middleware.Stack, o Options) error {
- mw := v4.NewSignHTTPRequestMiddleware(v4.SignHTTPRequestMiddlewareOptions{
- CredentialsProvider: o.Credentials,
- Signer: o.HTTPSignerV4,
- LogSigning: o.ClientLogMode.IsSigning(),
- })
- return stack.Finalize.Add(mw, middleware.After)
- }
- type HTTPSignerV4 interface {
- SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4.SignerOptions)) error
- }
- func resolveHTTPSignerV4(o *Options) {
- if o.HTTPSignerV4 != nil {
- return
- }
- o.HTTPSignerV4 = newDefaultV4Signer(*o)
- }
- func newDefaultV4Signer(o Options) *v4.Signer {
- return v4.NewSigner(func(so *v4.SignerOptions) {
- so.Logger = o.Logger
- so.LogSigning = o.ClientLogMode.IsSigning()
- })
- }
- func addRetryMiddlewares(stack *middleware.Stack, o Options) error {
- mo := retry.AddRetryMiddlewaresOptions{
- Retryer: o.Retryer,
- LogRetryAttempts: o.ClientLogMode.IsRetries(),
- }
- return retry.AddRetryMiddlewares(stack, mo)
- }
- // resolves dual-stack endpoint configuration
- func resolveUseDualStackEndpoint(cfg aws.Config, o *Options) error {
- if len(cfg.ConfigSources) == 0 {
- return nil
- }
- value, found, err := internalConfig.ResolveUseDualStackEndpoint(context.Background(), cfg.ConfigSources)
- if err != nil {
- return err
- }
- if found {
- o.EndpointOptions.UseDualStackEndpoint = value
- }
- return nil
- }
- // resolves FIPS endpoint configuration
- func resolveUseFIPSEndpoint(cfg aws.Config, o *Options) error {
- if len(cfg.ConfigSources) == 0 {
- return nil
- }
- value, found, err := internalConfig.ResolveUseFIPSEndpoint(context.Background(), cfg.ConfigSources)
- if err != nil {
- return err
- }
- if found {
- o.EndpointOptions.UseFIPSEndpoint = value
- }
- return nil
- }
- func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error {
- return awsmiddleware.AddRequestIDRetrieverMiddleware(stack)
- }
- func addResponseErrorMiddleware(stack *middleware.Stack) error {
- return awshttp.AddResponseErrorMiddleware(stack)
- }
- func addRequestResponseLogging(stack *middleware.Stack, o Options) error {
- return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{
- LogRequest: o.ClientLogMode.IsRequest(),
- LogRequestWithBody: o.ClientLogMode.IsRequestWithBody(),
- LogResponse: o.ClientLogMode.IsResponse(),
- LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(),
- }, middleware.After)
- }
|