/
api_client.go
183 lines (145 loc) · 4.94 KB
/
api_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Code generated by smithy-go-codegen DO NOT EDIT.
package ses
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
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"
"github.com/awslabs/smithy-go/middleware"
"net/http"
"time"
)
const ServiceID = "SES"
const ServiceAPIVersion = "2010-12-01"
// Amazon Simple Email Service This document contains reference information for the
// Amazon Simple Email Service (https://aws.amazon.com/ses/) (Amazon SES) API,
// version 2010-12-01. This document is best used in conjunction with the Amazon
// SES Developer Guide
// (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html). For a list
// of Amazon SES endpoints to use in service requests, see Regions and Amazon SES
// (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html) in the
// Amazon SES Developer Guide
// (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html).
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()
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
// The credentials object to use when signing requests.
Credentials aws.CredentialsProvider
// The endpoint options to be used when attempting to resolve an endpoint.
EndpointOptions ResolverOptions
// The service endpoint resolver.
EndpointResolver EndpointResolver
// Signature Version 4 (SigV4) Signer
HTTPSignerV4 HTTPSignerV4
// The region to send requests to. (Required)
Region string
// Retryer guides how HTTP requests should be retried in case of recoverable
// failures. When nil the API client will use a default retryer.
Retryer retry.Retryer
// The HTTP client to invoke API calls with. Defaults to client's default HTTP
// implementation if nil.
HTTPClient HTTPClient
}
func (o Options) GetCredentials() aws.CredentialsProvider {
return o.Credentials
}
func (o Options) GetEndpointOptions() ResolverOptions {
return o.EndpointOptions
}
func (o Options) GetEndpointResolver() EndpointResolver {
return o.EndpointResolver
}
func (o Options) GetHTTPSignerV4() HTTPSignerV4 {
return o.HTTPSignerV4
}
func (o Options) GetRegion() string {
return o.Region
}
func (o Options) GetRetryer() retry.Retryer {
return o.Retryer
}
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
}
// NewFromConfig returns a new client from the provided config.
func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client {
opts := Options{
Region: cfg.Region,
Retryer: cfg.Retryer,
HTTPClient: cfg.HTTPClient,
Credentials: cfg.Credentials,
APIOptions: cfg.APIOptions,
}
resolveAWSEndpointResolver(cfg, &opts)
return New(opts, optFns...)
}
func resolveHTTPClient(o *Options) {
if o.HTTPClient != nil {
return
}
o.HTTPClient = aws.NewBuildableHTTPClient()
}
func resolveRetryer(o *Options) {
if o.Retryer != nil {
return
}
o.Retryer = retry.NewStandard()
}
func resolveAWSEndpointResolver(cfg aws.Config, o *Options) {
if cfg.EndpointResolver == nil {
return
}
o.EndpointResolver = WithEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver())
}
func addClientUserAgent(stack *middleware.Stack) {
awsmiddleware.AddUserAgentKey("ses")(stack)
}
func addHTTPSignerV4Middleware(stack *middleware.Stack, o Options) {
stack.Finalize.Add(v4.NewSignHTTPRequestMiddleware(o.Credentials, o.HTTPSignerV4), middleware.After)
}
type HTTPSignerV4 interface {
SignHTTP(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time) error
}
func resolveHTTPSignerV4(o *Options) {
if o.HTTPSignerV4 != nil {
return
}
o.HTTPSignerV4 = v4.NewSigner()
}
func addRequestIDRetrieverMiddleware(stack *middleware.Stack) {
awsmiddleware.AddRequestIDRetrieverMiddleware(stack)
}
func addResponseErrorMiddleware(stack *middleware.Stack) {
awshttp.AddResponseErrorMiddleware(stack)
}