1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package lakeformation 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 "github.com/aws/aws-sdk-go-v2/aws/retry" 10 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 11 awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" 12 smithy "github.com/aws/smithy-go" 13 smithydocument "github.com/aws/smithy-go/document" 14 "github.com/aws/smithy-go/logging" 15 "github.com/aws/smithy-go/middleware" 16 smithyhttp "github.com/aws/smithy-go/transport/http" 17 "net/http" 18 "time" 19) 20 21const ServiceID = "LakeFormation" 22const ServiceAPIVersion = "2017-03-31" 23 24// Client provides the API client to make operations call for AWS Lake Formation. 25type Client struct { 26 options Options 27} 28 29// New returns an initialized Client based on the functional options. Provide 30// additional functional options to further configure the behavior of the client, 31// such as changing the client's endpoint or adding custom middleware behavior. 32func New(options Options, optFns ...func(*Options)) *Client { 33 options = options.Copy() 34 35 resolveDefaultLogger(&options) 36 37 resolveRetryer(&options) 38 39 resolveHTTPClient(&options) 40 41 resolveHTTPSignerV4(&options) 42 43 resolveDefaultEndpointConfiguration(&options) 44 45 for _, fn := range optFns { 46 fn(&options) 47 } 48 49 client := &Client{ 50 options: options, 51 } 52 53 return client 54} 55 56type Options struct { 57 // Set of options to modify how an operation is invoked. These apply to all 58 // operations invoked for this client. Use functional options on operation call to 59 // modify this list for per operation behavior. 60 APIOptions []func(*middleware.Stack) error 61 62 // Configures the events that will be sent to the configured logger. 63 ClientLogMode aws.ClientLogMode 64 65 // The credentials object to use when signing requests. 66 Credentials aws.CredentialsProvider 67 68 // The endpoint options to be used when attempting to resolve an endpoint. 69 EndpointOptions EndpointResolverOptions 70 71 // The service endpoint resolver. 72 EndpointResolver EndpointResolver 73 74 // Signature Version 4 (SigV4) Signer 75 HTTPSignerV4 HTTPSignerV4 76 77 // The logger writer interface to write logging messages to. 78 Logger logging.Logger 79 80 // The region to send requests to. (Required) 81 Region string 82 83 // Retryer guides how HTTP requests should be retried in case of recoverable 84 // failures. When nil the API client will use a default retryer. 85 Retryer aws.Retryer 86 87 // The HTTP client to invoke API calls with. Defaults to client's default HTTP 88 // implementation if nil. 89 HTTPClient HTTPClient 90} 91 92// WithAPIOptions returns a functional option for setting the Client's APIOptions 93// option. 94func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) { 95 return func(o *Options) { 96 o.APIOptions = append(o.APIOptions, optFns...) 97 } 98} 99 100// WithEndpointResolver returns a functional option for setting the Client's 101// EndpointResolver option. 102func WithEndpointResolver(v EndpointResolver) func(*Options) { 103 return func(o *Options) { 104 o.EndpointResolver = v 105 } 106} 107 108type HTTPClient interface { 109 Do(*http.Request) (*http.Response, error) 110} 111 112// Copy creates a clone where the APIOptions list is deep copied. 113func (o Options) Copy() Options { 114 to := o 115 to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) 116 copy(to.APIOptions, o.APIOptions) 117 return to 118} 119func (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) { 120 ctx = middleware.ClearStackValues(ctx) 121 stack := middleware.NewStack(opID, smithyhttp.NewStackRequest) 122 options := c.options.Copy() 123 for _, fn := range optFns { 124 fn(&options) 125 } 126 127 for _, fn := range stackFns { 128 if err := fn(stack, options); err != nil { 129 return nil, metadata, err 130 } 131 } 132 133 for _, fn := range options.APIOptions { 134 if err := fn(stack); err != nil { 135 return nil, metadata, err 136 } 137 } 138 139 handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack) 140 result, metadata, err = handler.Handle(ctx, params) 141 if err != nil { 142 err = &smithy.OperationError{ 143 ServiceID: ServiceID, 144 OperationName: opID, 145 Err: err, 146 } 147 } 148 return result, metadata, err 149} 150 151type noSmithyDocumentSerde = smithydocument.NoSerde 152 153func resolveDefaultLogger(o *Options) { 154 if o.Logger != nil { 155 return 156 } 157 o.Logger = logging.Nop{} 158} 159 160func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { 161 return middleware.AddSetLoggerMiddleware(stack, o.Logger) 162} 163 164// NewFromConfig returns a new client from the provided config. 165func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { 166 opts := Options{ 167 Region: cfg.Region, 168 HTTPClient: cfg.HTTPClient, 169 Credentials: cfg.Credentials, 170 APIOptions: cfg.APIOptions, 171 Logger: cfg.Logger, 172 ClientLogMode: cfg.ClientLogMode, 173 } 174 resolveAWSRetryerProvider(cfg, &opts) 175 resolveAWSEndpointResolver(cfg, &opts) 176 return New(opts, optFns...) 177} 178 179func resolveHTTPClient(o *Options) { 180 if o.HTTPClient != nil { 181 return 182 } 183 o.HTTPClient = awshttp.NewBuildableClient() 184} 185 186func resolveRetryer(o *Options) { 187 if o.Retryer != nil { 188 return 189 } 190 o.Retryer = retry.NewStandard() 191} 192 193func resolveAWSRetryerProvider(cfg aws.Config, o *Options) { 194 if cfg.Retryer == nil { 195 return 196 } 197 o.Retryer = cfg.Retryer() 198} 199 200func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { 201 if cfg.EndpointResolver == nil { 202 return 203 } 204 o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) 205} 206 207func addClientUserAgent(stack *middleware.Stack) error { 208 return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "lakeformation", goModuleVersion)(stack) 209} 210 211func addHTTPSignerV4Middleware(stack *middleware.Stack, o Options) error { 212 mw := v4.NewSignHTTPRequestMiddleware(v4.SignHTTPRequestMiddlewareOptions{ 213 CredentialsProvider: o.Credentials, 214 Signer: o.HTTPSignerV4, 215 LogSigning: o.ClientLogMode.IsSigning(), 216 }) 217 return stack.Finalize.Add(mw, middleware.After) 218} 219 220type HTTPSignerV4 interface { 221 SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4.SignerOptions)) error 222} 223 224func resolveHTTPSignerV4(o *Options) { 225 if o.HTTPSignerV4 != nil { 226 return 227 } 228 o.HTTPSignerV4 = newDefaultV4Signer(*o) 229} 230 231func newDefaultV4Signer(o Options) *v4.Signer { 232 return v4.NewSigner(func(so *v4.SignerOptions) { 233 so.Logger = o.Logger 234 so.LogSigning = o.ClientLogMode.IsSigning() 235 }) 236} 237 238func addRetryMiddlewares(stack *middleware.Stack, o Options) error { 239 mo := retry.AddRetryMiddlewaresOptions{ 240 Retryer: o.Retryer, 241 LogRetryAttempts: o.ClientLogMode.IsRetries(), 242 } 243 return retry.AddRetryMiddlewares(stack, mo) 244} 245 246func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { 247 return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) 248} 249 250func addResponseErrorMiddleware(stack *middleware.Stack) error { 251 return awshttp.AddResponseErrorMiddleware(stack) 252} 253 254func addRequestResponseLogging(stack *middleware.Stack, o Options) error { 255 return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{ 256 LogRequest: o.ClientLogMode.IsRequest(), 257 LogRequestWithBody: o.ClientLogMode.IsRequestWithBody(), 258 LogResponse: o.ClientLogMode.IsResponse(), 259 LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(), 260 }, middleware.After) 261} 262