1// Code generated by smithy-go-codegen DO NOT EDIT.
  2
  3package ssooidc
  4
  5import (
  6	"context"
  7	"github.com/aws/aws-sdk-go-v2/aws"
  8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  9	internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
 10	smithyauth "github.com/aws/smithy-go/auth"
 11	"github.com/aws/smithy-go/logging"
 12	"github.com/aws/smithy-go/middleware"
 13	smithyhttp "github.com/aws/smithy-go/transport/http"
 14	"net/http"
 15)
 16
 17type HTTPClient interface {
 18	Do(*http.Request) (*http.Response, error)
 19}
 20
 21type Options struct {
 22	// Set of options to modify how an operation is invoked. These apply to all
 23	// operations invoked for this client. Use functional options on operation call to
 24	// modify this list for per operation behavior.
 25	APIOptions []func(*middleware.Stack) error
 26
 27	// Indicates how aws account ID is applied in endpoint2.0 routing
 28	AccountIDEndpointMode aws.AccountIDEndpointMode
 29
 30	// The optional application specific identifier appended to the User-Agent header.
 31	AppID string
 32
 33	// This endpoint will be given as input to an EndpointResolverV2. It is used for
 34	// providing a custom base endpoint that is subject to modifications by the
 35	// processing EndpointResolverV2.
 36	BaseEndpoint *string
 37
 38	// Configures the events that will be sent to the configured logger.
 39	ClientLogMode aws.ClientLogMode
 40
 41	// The credentials object to use when signing requests.
 42	Credentials aws.CredentialsProvider
 43
 44	// The configuration DefaultsMode that the SDK should use when constructing the
 45	// clients initial default settings.
 46	DefaultsMode aws.DefaultsMode
 47
 48	// The endpoint options to be used when attempting to resolve an endpoint.
 49	EndpointOptions EndpointResolverOptions
 50
 51	// The service endpoint resolver.
 52	//
 53	// Deprecated: Deprecated: EndpointResolver and WithEndpointResolver. Providing a
 54	// value for this field will likely prevent you from using any endpoint-related
 55	// service features released after the introduction of EndpointResolverV2 and
 56	// BaseEndpoint.
 57	//
 58	// To migrate an EndpointResolver implementation that uses a custom endpoint, set
 59	// the client option BaseEndpoint instead.
 60	EndpointResolver EndpointResolver
 61
 62	// Resolves the endpoint used for a particular service operation. This should be
 63	// used over the deprecated EndpointResolver.
 64	EndpointResolverV2 EndpointResolverV2
 65
 66	// Signature Version 4 (SigV4) Signer
 67	HTTPSignerV4 HTTPSignerV4
 68
 69	// The logger writer interface to write logging messages to.
 70	Logger logging.Logger
 71
 72	// The region to send requests to. (Required)
 73	Region string
 74
 75	// RetryMaxAttempts specifies the maximum number attempts an API client will call
 76	// an operation that fails with a retryable error. A value of 0 is ignored, and
 77	// will not be used to configure the API client created default retryer, or modify
 78	// per operation call's retry max attempts.
 79	//
 80	// If specified in an operation call's functional options with a value that is
 81	// different than the constructed client's Options, the Client's Retryer will be
 82	// wrapped to use the operation's specific RetryMaxAttempts value.
 83	RetryMaxAttempts int
 84
 85	// RetryMode specifies the retry mode the API client will be created with, if
 86	// Retryer option is not also specified.
 87	//
 88	// When creating a new API Clients this member will only be used if the Retryer
 89	// Options member is nil. This value will be ignored if Retryer is not nil.
 90	//
 91	// Currently does not support per operation call overrides, may in the future.
 92	RetryMode aws.RetryMode
 93
 94	// Retryer guides how HTTP requests should be retried in case of recoverable
 95	// failures. When nil the API client will use a default retryer. The kind of
 96	// default retry created by the API client can be changed with the RetryMode
 97	// option.
 98	Retryer aws.Retryer
 99
100	// The RuntimeEnvironment configuration, only populated if the DefaultsMode is set
101	// to DefaultsModeAuto and is initialized using config.LoadDefaultConfig . You
102	// should not populate this structure programmatically, or rely on the values here
103	// within your applications.
104	RuntimeEnvironment aws.RuntimeEnvironment
105
106	// The initial DefaultsMode used when the client options were constructed. If the
107	// DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
108	// value was at that point in time.
109	//
110	// Currently does not support per operation call overrides, may in the future.
111	resolvedDefaultsMode aws.DefaultsMode
112
113	// The HTTP client to invoke API calls with. Defaults to client's default HTTP
114	// implementation if nil.
115	HTTPClient HTTPClient
116
117	// The auth scheme resolver which determines how to authenticate for each
118	// operation.
119	AuthSchemeResolver AuthSchemeResolver
120
121	// The list of auth schemes supported by the client.
122	AuthSchemes []smithyhttp.AuthScheme
123}
124
125// Copy creates a clone where the APIOptions list is deep copied.
126func (o Options) Copy() Options {
127	to := o
128	to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions))
129	copy(to.APIOptions, o.APIOptions)
130
131	return to
132}
133
134func (o Options) GetIdentityResolver(schemeID string) smithyauth.IdentityResolver {
135	if schemeID == "aws.auth#sigv4" {
136		return getSigV4IdentityResolver(o)
137	}
138	if schemeID == "smithy.api#noAuth" {
139		return &smithyauth.AnonymousIdentityResolver{}
140	}
141	return nil
142}
143
144// WithAPIOptions returns a functional option for setting the Client's APIOptions
145// option.
146func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) {
147	return func(o *Options) {
148		o.APIOptions = append(o.APIOptions, optFns...)
149	}
150}
151
152// Deprecated: EndpointResolver and WithEndpointResolver. Providing a value for
153// this field will likely prevent you from using any endpoint-related service
154// features released after the introduction of EndpointResolverV2 and BaseEndpoint.
155//
156// To migrate an EndpointResolver implementation that uses a custom endpoint, set
157// the client option BaseEndpoint instead.
158func WithEndpointResolver(v EndpointResolver) func(*Options) {
159	return func(o *Options) {
160		o.EndpointResolver = v
161	}
162}
163
164// WithEndpointResolverV2 returns a functional option for setting the Client's
165// EndpointResolverV2 option.
166func WithEndpointResolverV2(v EndpointResolverV2) func(*Options) {
167	return func(o *Options) {
168		o.EndpointResolverV2 = v
169	}
170}
171
172func getSigV4IdentityResolver(o Options) smithyauth.IdentityResolver {
173	if o.Credentials != nil {
174		return &internalauthsmithy.CredentialsProviderAdapter{Provider: o.Credentials}
175	}
176	return nil
177}
178
179// WithSigV4SigningName applies an override to the authentication workflow to
180// use the given signing name for SigV4-authenticated operations.
181//
182// This is an advanced setting. The value here is FINAL, taking precedence over
183// the resolved signing name from both auth scheme resolution and endpoint
184// resolution.
185func WithSigV4SigningName(name string) func(*Options) {
186	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
187		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
188	) {
189		return next.HandleInitialize(awsmiddleware.SetSigningName(ctx, name), in)
190	}
191	return func(o *Options) {
192		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
193			return s.Initialize.Add(
194				middleware.InitializeMiddlewareFunc("withSigV4SigningName", fn),
195				middleware.Before,
196			)
197		})
198	}
199}
200
201// WithSigV4SigningRegion applies an override to the authentication workflow to
202// use the given signing region for SigV4-authenticated operations.
203//
204// This is an advanced setting. The value here is FINAL, taking precedence over
205// the resolved signing region from both auth scheme resolution and endpoint
206// resolution.
207func WithSigV4SigningRegion(region string) func(*Options) {
208	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
209		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
210	) {
211		return next.HandleInitialize(awsmiddleware.SetSigningRegion(ctx, region), in)
212	}
213	return func(o *Options) {
214		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
215			return s.Initialize.Add(
216				middleware.InitializeMiddlewareFunc("withSigV4SigningRegion", fn),
217				middleware.Before,
218			)
219		})
220	}
221}
222
223func ignoreAnonymousAuth(options *Options) {
224	if aws.IsCredentialsProvider(options.Credentials, (*aws.AnonymousCredentials)(nil)) {
225		options.Credentials = nil
226	}
227}