-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
customizations.rb
303 lines (260 loc) · 10.3 KB
/
customizations.rb
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
module Aws
module Api
module Customizations
@apis = {}
@docs = {}
@plugins = {}
class << self
def api(prefix, &block)
@apis[prefix] = block
end
def doc(prefix, &block)
@docs[prefix] = block
end
def plugins(prefix, options)
@plugins[prefix] = {
add: options[:add] || [],
remove: options[:remove] || [],
}
end
def apply_api_customizations(api)
metadata = api['metadata'] || {}
prefix = metadata['serviceFullName']
# event stream is not supported at V2
api = exclude_eventstream(api) if api['operations']
@apis[prefix].call(api) if @apis[prefix]
end
def apply_doc_customizations(api, docs)
prefix = api.metadata['serviceFullName']
@docs[prefix].call(docs) if @docs[prefix]
end
def apply_plugins(client_class)
prefix = client_class.api.metadata['serviceFullName']
if @plugins[prefix]
@plugins[prefix][:add].each { |p| client_class.add_plugin(p) }
@plugins[prefix][:remove].each { |p| client_class.remove_plugin(p) }
end
end
private
def exclude_eventstream(api)
api['operations'].each do |name, ref|
inbound = ref['input'] && is_eventstream?(api, ref['input']['shape'])
outbound = ref['output'] && is_eventstream?(api, ref['output']['shape'])
api['operations'].delete(name) if !!inbound || !!outbound
end
api
end
def is_eventstream?(api, shape_name)
shape = api['shapes'][shape_name]
if shape['type'] == 'structure'
eventstream = false
shape['members'].each do |_, m_ref|
eventstream ||= api['shapes'][m_ref['shape']]['eventstream']
end
eventstream
else
# non structure request/response shape
# check if it's eventstream itself
shape['eventstream']
end
end
end
plugins('Amazon API Gateway',
add: %w(Aws::Plugins::APIGatewayHeader),
)
api('Amazon CloudFront') do |api|
api['shapes'].each do |_, shape|
if shape['members'] && shape['members']['MaxItems']
shape['members']['MaxItems']['shape'] = 'integer'
end
end
api['operations'].keys.each do |name|
symbolized = name.sub(/\d{4}_\d{2}_\d{2}$/, '')
api['operations'][symbolized] = api['operations'].delete(name)
end
end
plugins('Amazon CloudSearch Domain',
add: %w(Aws::Plugins::CSDConditionalSigning
Aws::Plugins::CSDSwitchToPost),
remove: %w(Aws::Plugins::RegionalEndpoint
Aws::Plugins::EndpointPattern
Aws::Plugins::EndpointDiscovery),
)
plugins('Amazon DynamoDB', add: %w(
Aws::Plugins::DynamoDBExtendedRetries
Aws::Plugins::DynamoDBSimpleAttributes
Aws::Plugins::DynamoDBCRC32Validation
))
api('Amazon Elastic Compute Cloud') do |api|
if ENV['DOCSTRINGS']
members = api['shapes']['CopySnapshotRequest']['members']
members.delete('DestinationRegion')
members.delete('PresignedUrl')
end
end
plugins('Amazon Elastic Compute Cloud', add: %w(
Aws::Plugins::EC2CopyEncryptedSnapshot
Aws::Plugins::EC2RegionValidation
))
api('Amazon Glacier') do |api|
api['shapes']['Timestamp'] = {
'type' => 'timestamp',
'timestampFormat' => 'iso8601',
}
api['shapes'].each do |_, shape|
if shape['members']
shape['members'].each do |name, ref|
case name
when /date/i then ref['shape'] = 'Timestamp'
when 'limit' then ref['shape'] = 'Size'
when 'partSize' then ref['shape'] = 'Size'
when 'archiveSize' then ref['shape'] = 'Size'
end
end
end
end
end
plugins('Amazon Glacier', add: %w(
Aws::Plugins::GlacierAccountId
Aws::Plugins::GlacierApiVersion
Aws::Plugins::GlacierChecksums
))
api('AWS Import/Export') do |api|
api['operations'].each do |_, operation|
operation['http']['requestUri'] = '/'
end
end
api('AWS IoT Data Plane') do |api|
api['metadata'].delete('endpointPrefix')
end
api('AWS Lambda') do |api|
api['shapes']['Timestamp']['type'] = 'timestamp'
end
doc('AWS Lambda') do |docs|
docs['shapes']['Blob']['refs']['UpdateFunctionCodeRequest$ZipFile'] =
"<p>.zip file containing your packaged source code.</p>"
end
plugins('Amazon Machine Learning', add: %w(
Aws::Plugins::MachineLearningPredictEndpoint
))
api('Amazon Route 53') do |api|
api['shapes']['PageMaxItems']['type'] = 'integer'
end
plugins('Amazon Route 53', add: %w(
Aws::Plugins::Route53IdFix
))
plugins('Amazon Relational Database Service', add: %w(
Aws::Plugins::RDSCrossRegionCopying
))
api('Amazon Relational Database Service') do |api|
api['shapes']['CopyDBSnapshotMessage']['members']['DestinationRegion'] =
{"shape" => "String"}
api['shapes']['CreateDBInstanceReadReplicaMessage']['members']['DestinationRegion'] =
{"shape" => "String"}
api['shapes']['CopyDBClusterSnapshotMessage']['members']['DestinationRegion'] =
{"shape" => "String"}
api['shapes']['CreateDBClusterMessage']['members']['DestinationRegion'] =
{"shape" => "String"}
api['shapes']['CopyDBSnapshotMessage']['members']['SourceRegion'] =
{"shape" => "String"}
api['shapes']['CreateDBInstanceReadReplicaMessage']['members']['SourceRegion'] =
{"shape" => "String"}
api['shapes']['CopyDBClusterSnapshotMessage']['members']['SourceRegion'] =
{"shape" => "String"}
api['shapes']['CreateDBClusterMessage']['members']['SourceRegion'] =
{"shape" => "String"}
end
doc('Amazon Relational Database Service') do |docs|
docs['shapes']['String']['refs']['CopyDBSnapshotMessage$SourceRegion'] =
"<p>The region which you are copying an encrypted snapshot from.</p>" +
"<p>This is a required paramter that allows SDK to compute a pre-signed Url and" +
" populate <code>PreSignedURL</code> parameter on your behalf.</p>"
docs['shapes']['String']['refs']['CreateDBInstanceReadReplicaMessage$SourceRegion'] =
"<p>The region which you are copying an encrypted snapshot from.</p>" +
"<p>This is a required paramter that allows SDK to compute a pre-signed Url and" +
" populate <code>PreSignedURL</code> parameter on your behalf.</p>"
docs['shapes']['String']['refs']['CopyDBClusterSnapshotMessage$SourceRegion'] =
"<p>The region which you are copying an encrypted snapshot from.</p>" +
"<p>This is a required paramter that allows SDK to compute a pre-signed Url and" +
" populate <code>PreSignedURL</code> parameter on your behalf.</p>"
docs['shapes']['String']['refs']['CreateDBClusterMessage$SourceRegion'] =
"<p>The region which you are copying an encrypted snapshot from.</p>" +
"<p>This is a required paramter that allows SDK to compute a pre-signed Url and" +
" populate <code>PreSignedURL</code> parameter on your behalf.</p>"
end
api('Amazon Simple Storage Service') do |api|
api['metadata'].delete('signatureVersion')
if ENV['DOCSTRINGS']
api['shapes']['AccelerateBoolean'] = { 'type' => 'boolean' }
api['operations'].each do |operation_name, operation|
next if %w(CreateBucket ListBuckets DeleteBucket).include?(operation_name)
if input_ref = operation['input']
input_shape = api['shapes'][input_ref['shape']]
input_shape['members']['UseAccelerateEndpoint'] = {
'shape' => 'AccelerateBoolean'
}
end
end
end
api['shapes']['ExpiresString'] = { 'type' => 'string' }
%w(HeadObjectOutput GetObjectOutput).each do |shape|
members = api['shapes'][shape]['members']
# inject ExpiresString directly after Expires
api['shapes'][shape]['members'] = members.inject({}) do |h, (k,v)|
h[k] = v
if k == 'Expires'
h['ExpiresString'] = {
'shape' => 'ExpiresString',
'location' => 'header',
'locationName' => 'Expires',
}
end
h
end
end
end
doc('Amazon Simple Storage Service') do |docs|
if ENV['DOCSTRINGS']
docs['shapes']['AccelerateBoolean'] = {}
docs['shapes']['AccelerateBoolean']['refs'] = {}
docs['shapes']['AccelerateBoolean']['base'] = 'When <tt>true</tt>, the "https://BUCKETNAME.s3-accelerate.amazonaws.com" endpoint will be used.'
end
end
plugins('Amazon Simple Storage Service', add: %w(
Aws::Plugins::S3Accelerate
Aws::Plugins::S3Dualstack
Aws::Plugins::S3BucketDns
Aws::Plugins::S3BucketNameRestrictions
Aws::Plugins::S3Expect100Continue
Aws::Plugins::S3HostId
Aws::Plugins::S3Http200Errors
Aws::Plugins::S3GetBucketLocationFix
Aws::Plugins::S3LocationConstraint
Aws::Plugins::S3Md5s
Aws::Plugins::S3Redirects
Aws::Plugins::S3SseCpk
Aws::Plugins::S3UrlEncodedKeys
Aws::Plugins::S3RequestSigner
))
plugins('AWS Security Token Service', add: %w(
Aws::Plugins::STSRegionalEndpoints
))
plugins('AWS S3 Control', add: %w(
Aws::Plugins::S3HostId
Aws::Plugins::S3ControlDns
Aws::Plugins::S3ControlDualstack
Aws::Plugins::S3ControlSigner
))
api('Amazon Simple Queue Service') do |api|
api['metadata']['errorPrefix'] = 'AWS.SimpleQueueService.'
end
plugins('Amazon Simple Queue Service', add: %w(
Aws::Plugins::SQSQueueUrls
Aws::Plugins::SQSMd5s
))
plugins('Amazon Simple Workflow Service', add: %w(
Aws::Plugins::SWFReadTimeouts
))
end
end
end