aws-sdk-sqs 1.70.0 → 1.83.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,322 +14,253 @@ module Aws::SQS
14
14
 
15
15
  class AddPermission
16
16
  def self.build(context)
17
- unless context.config.regional_endpoint
18
- endpoint = context.config.endpoint.to_s
19
- end
20
17
  Aws::SQS::EndpointParameters.new(
21
18
  region: context.config.region,
22
19
  use_dual_stack: context.config.use_dualstack_endpoint,
23
20
  use_fips: context.config.use_fips_endpoint,
24
- endpoint: endpoint,
21
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
25
22
  )
26
23
  end
27
24
  end
28
25
 
29
26
  class CancelMessageMoveTask
30
27
  def self.build(context)
31
- unless context.config.regional_endpoint
32
- endpoint = context.config.endpoint.to_s
33
- end
34
28
  Aws::SQS::EndpointParameters.new(
35
29
  region: context.config.region,
36
30
  use_dual_stack: context.config.use_dualstack_endpoint,
37
31
  use_fips: context.config.use_fips_endpoint,
38
- endpoint: endpoint,
32
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
39
33
  )
40
34
  end
41
35
  end
42
36
 
43
37
  class ChangeMessageVisibility
44
38
  def self.build(context)
45
- unless context.config.regional_endpoint
46
- endpoint = context.config.endpoint.to_s
47
- end
48
39
  Aws::SQS::EndpointParameters.new(
49
40
  region: context.config.region,
50
41
  use_dual_stack: context.config.use_dualstack_endpoint,
51
42
  use_fips: context.config.use_fips_endpoint,
52
- endpoint: endpoint,
43
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
53
44
  )
54
45
  end
55
46
  end
56
47
 
57
48
  class ChangeMessageVisibilityBatch
58
49
  def self.build(context)
59
- unless context.config.regional_endpoint
60
- endpoint = context.config.endpoint.to_s
61
- end
62
50
  Aws::SQS::EndpointParameters.new(
63
51
  region: context.config.region,
64
52
  use_dual_stack: context.config.use_dualstack_endpoint,
65
53
  use_fips: context.config.use_fips_endpoint,
66
- endpoint: endpoint,
54
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
67
55
  )
68
56
  end
69
57
  end
70
58
 
71
59
  class CreateQueue
72
60
  def self.build(context)
73
- unless context.config.regional_endpoint
74
- endpoint = context.config.endpoint.to_s
75
- end
76
61
  Aws::SQS::EndpointParameters.new(
77
62
  region: context.config.region,
78
63
  use_dual_stack: context.config.use_dualstack_endpoint,
79
64
  use_fips: context.config.use_fips_endpoint,
80
- endpoint: endpoint,
65
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
81
66
  )
82
67
  end
83
68
  end
84
69
 
85
70
  class DeleteMessage
86
71
  def self.build(context)
87
- unless context.config.regional_endpoint
88
- endpoint = context.config.endpoint.to_s
89
- end
90
72
  Aws::SQS::EndpointParameters.new(
91
73
  region: context.config.region,
92
74
  use_dual_stack: context.config.use_dualstack_endpoint,
93
75
  use_fips: context.config.use_fips_endpoint,
94
- endpoint: endpoint,
76
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
95
77
  )
96
78
  end
97
79
  end
98
80
 
99
81
  class DeleteMessageBatch
100
82
  def self.build(context)
101
- unless context.config.regional_endpoint
102
- endpoint = context.config.endpoint.to_s
103
- end
104
83
  Aws::SQS::EndpointParameters.new(
105
84
  region: context.config.region,
106
85
  use_dual_stack: context.config.use_dualstack_endpoint,
107
86
  use_fips: context.config.use_fips_endpoint,
108
- endpoint: endpoint,
87
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
109
88
  )
110
89
  end
111
90
  end
112
91
 
113
92
  class DeleteQueue
114
93
  def self.build(context)
115
- unless context.config.regional_endpoint
116
- endpoint = context.config.endpoint.to_s
117
- end
118
94
  Aws::SQS::EndpointParameters.new(
119
95
  region: context.config.region,
120
96
  use_dual_stack: context.config.use_dualstack_endpoint,
121
97
  use_fips: context.config.use_fips_endpoint,
122
- endpoint: endpoint,
98
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
123
99
  )
124
100
  end
125
101
  end
126
102
 
127
103
  class GetQueueAttributes
128
104
  def self.build(context)
129
- unless context.config.regional_endpoint
130
- endpoint = context.config.endpoint.to_s
131
- end
132
105
  Aws::SQS::EndpointParameters.new(
133
106
  region: context.config.region,
134
107
  use_dual_stack: context.config.use_dualstack_endpoint,
135
108
  use_fips: context.config.use_fips_endpoint,
136
- endpoint: endpoint,
109
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
137
110
  )
138
111
  end
139
112
  end
140
113
 
141
114
  class GetQueueUrl
142
115
  def self.build(context)
143
- unless context.config.regional_endpoint
144
- endpoint = context.config.endpoint.to_s
145
- end
146
116
  Aws::SQS::EndpointParameters.new(
147
117
  region: context.config.region,
148
118
  use_dual_stack: context.config.use_dualstack_endpoint,
149
119
  use_fips: context.config.use_fips_endpoint,
150
- endpoint: endpoint,
120
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
151
121
  )
152
122
  end
153
123
  end
154
124
 
155
125
  class ListDeadLetterSourceQueues
156
126
  def self.build(context)
157
- unless context.config.regional_endpoint
158
- endpoint = context.config.endpoint.to_s
159
- end
160
127
  Aws::SQS::EndpointParameters.new(
161
128
  region: context.config.region,
162
129
  use_dual_stack: context.config.use_dualstack_endpoint,
163
130
  use_fips: context.config.use_fips_endpoint,
164
- endpoint: endpoint,
131
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
165
132
  )
166
133
  end
167
134
  end
168
135
 
169
136
  class ListMessageMoveTasks
170
137
  def self.build(context)
171
- unless context.config.regional_endpoint
172
- endpoint = context.config.endpoint.to_s
173
- end
174
138
  Aws::SQS::EndpointParameters.new(
175
139
  region: context.config.region,
176
140
  use_dual_stack: context.config.use_dualstack_endpoint,
177
141
  use_fips: context.config.use_fips_endpoint,
178
- endpoint: endpoint,
142
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
179
143
  )
180
144
  end
181
145
  end
182
146
 
183
147
  class ListQueueTags
184
148
  def self.build(context)
185
- unless context.config.regional_endpoint
186
- endpoint = context.config.endpoint.to_s
187
- end
188
149
  Aws::SQS::EndpointParameters.new(
189
150
  region: context.config.region,
190
151
  use_dual_stack: context.config.use_dualstack_endpoint,
191
152
  use_fips: context.config.use_fips_endpoint,
192
- endpoint: endpoint,
153
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
193
154
  )
194
155
  end
195
156
  end
196
157
 
197
158
  class ListQueues
198
159
  def self.build(context)
199
- unless context.config.regional_endpoint
200
- endpoint = context.config.endpoint.to_s
201
- end
202
160
  Aws::SQS::EndpointParameters.new(
203
161
  region: context.config.region,
204
162
  use_dual_stack: context.config.use_dualstack_endpoint,
205
163
  use_fips: context.config.use_fips_endpoint,
206
- endpoint: endpoint,
164
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
207
165
  )
208
166
  end
209
167
  end
210
168
 
211
169
  class PurgeQueue
212
170
  def self.build(context)
213
- unless context.config.regional_endpoint
214
- endpoint = context.config.endpoint.to_s
215
- end
216
171
  Aws::SQS::EndpointParameters.new(
217
172
  region: context.config.region,
218
173
  use_dual_stack: context.config.use_dualstack_endpoint,
219
174
  use_fips: context.config.use_fips_endpoint,
220
- endpoint: endpoint,
175
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
221
176
  )
222
177
  end
223
178
  end
224
179
 
225
180
  class ReceiveMessage
226
181
  def self.build(context)
227
- unless context.config.regional_endpoint
228
- endpoint = context.config.endpoint.to_s
229
- end
230
182
  Aws::SQS::EndpointParameters.new(
231
183
  region: context.config.region,
232
184
  use_dual_stack: context.config.use_dualstack_endpoint,
233
185
  use_fips: context.config.use_fips_endpoint,
234
- endpoint: endpoint,
186
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
235
187
  )
236
188
  end
237
189
  end
238
190
 
239
191
  class RemovePermission
240
192
  def self.build(context)
241
- unless context.config.regional_endpoint
242
- endpoint = context.config.endpoint.to_s
243
- end
244
193
  Aws::SQS::EndpointParameters.new(
245
194
  region: context.config.region,
246
195
  use_dual_stack: context.config.use_dualstack_endpoint,
247
196
  use_fips: context.config.use_fips_endpoint,
248
- endpoint: endpoint,
197
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
249
198
  )
250
199
  end
251
200
  end
252
201
 
253
202
  class SendMessage
254
203
  def self.build(context)
255
- unless context.config.regional_endpoint
256
- endpoint = context.config.endpoint.to_s
257
- end
258
204
  Aws::SQS::EndpointParameters.new(
259
205
  region: context.config.region,
260
206
  use_dual_stack: context.config.use_dualstack_endpoint,
261
207
  use_fips: context.config.use_fips_endpoint,
262
- endpoint: endpoint,
208
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
263
209
  )
264
210
  end
265
211
  end
266
212
 
267
213
  class SendMessageBatch
268
214
  def self.build(context)
269
- unless context.config.regional_endpoint
270
- endpoint = context.config.endpoint.to_s
271
- end
272
215
  Aws::SQS::EndpointParameters.new(
273
216
  region: context.config.region,
274
217
  use_dual_stack: context.config.use_dualstack_endpoint,
275
218
  use_fips: context.config.use_fips_endpoint,
276
- endpoint: endpoint,
219
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
277
220
  )
278
221
  end
279
222
  end
280
223
 
281
224
  class SetQueueAttributes
282
225
  def self.build(context)
283
- unless context.config.regional_endpoint
284
- endpoint = context.config.endpoint.to_s
285
- end
286
226
  Aws::SQS::EndpointParameters.new(
287
227
  region: context.config.region,
288
228
  use_dual_stack: context.config.use_dualstack_endpoint,
289
229
  use_fips: context.config.use_fips_endpoint,
290
- endpoint: endpoint,
230
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
291
231
  )
292
232
  end
293
233
  end
294
234
 
295
235
  class StartMessageMoveTask
296
236
  def self.build(context)
297
- unless context.config.regional_endpoint
298
- endpoint = context.config.endpoint.to_s
299
- end
300
237
  Aws::SQS::EndpointParameters.new(
301
238
  region: context.config.region,
302
239
  use_dual_stack: context.config.use_dualstack_endpoint,
303
240
  use_fips: context.config.use_fips_endpoint,
304
- endpoint: endpoint,
241
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
305
242
  )
306
243
  end
307
244
  end
308
245
 
309
246
  class TagQueue
310
247
  def self.build(context)
311
- unless context.config.regional_endpoint
312
- endpoint = context.config.endpoint.to_s
313
- end
314
248
  Aws::SQS::EndpointParameters.new(
315
249
  region: context.config.region,
316
250
  use_dual_stack: context.config.use_dualstack_endpoint,
317
251
  use_fips: context.config.use_fips_endpoint,
318
- endpoint: endpoint,
252
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
319
253
  )
320
254
  end
321
255
  end
322
256
 
323
257
  class UntagQueue
324
258
  def self.build(context)
325
- unless context.config.regional_endpoint
326
- endpoint = context.config.endpoint.to_s
327
- end
328
259
  Aws::SQS::EndpointParameters.new(
329
260
  region: context.config.region,
330
261
  use_dual_stack: context.config.use_dualstack_endpoint,
331
262
  use_fips: context.config.use_fips_endpoint,
332
- endpoint: endpoint,
263
+ endpoint: context.config.regional_endpoint ? nil : context.config.endpoint.to_s,
333
264
  )
334
265
  end
335
266
  end
@@ -163,7 +163,7 @@ module Aws::SQS
163
163
  queue_url: @queue_url,
164
164
  receipt_handle: @receipt_handle
165
165
  )
166
- resp = Aws::Plugins::UserAgent.feature('resource') do
166
+ resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
167
167
  @client.change_message_visibility(options)
168
168
  end
169
169
  resp.data
@@ -179,7 +179,7 @@ module Aws::SQS
179
179
  queue_url: @queue_url,
180
180
  receipt_handle: @receipt_handle
181
181
  )
182
- resp = Aws::Plugins::UserAgent.feature('resource') do
182
+ resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
183
183
  @client.delete_message(options)
184
184
  end
185
185
  resp.data
@@ -246,7 +246,7 @@ module Aws::SQS
246
246
  receipt_handle: item.receipt_handle
247
247
  }
248
248
  end
249
- Aws::Plugins::UserAgent.feature('resource') do
249
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
250
250
  batch[0].client.delete_message_batch(params)
251
251
  end
252
252
  end
@@ -40,11 +40,20 @@ module Aws::SQS
40
40
  context[:auth_scheme] =
41
41
  Aws::Endpoints.resolve_auth_scheme(context, endpoint)
42
42
 
43
- @handler.call(context)
43
+ with_metrics(context) { @handler.call(context) }
44
44
  end
45
45
 
46
46
  private
47
47
 
48
+ def with_metrics(context, &block)
49
+ metrics = []
50
+ metrics << 'ENDPOINT_OVERRIDE' unless context.config.regional_endpoint
51
+ if context[:auth_scheme] && context[:auth_scheme]['name'] == 'sigv4a'
52
+ metrics << 'SIGV4A_SIGNING'
53
+ end
54
+ Aws::Plugins::UserAgent.metric(*metrics, &block)
55
+ end
56
+
48
57
  def apply_endpoint_headers(context, headers)
49
58
  headers.each do |key, values|
50
59
  value = values
@@ -6,7 +6,6 @@ module Aws
6
6
  module SQS
7
7
  module Plugins
8
8
  class Md5s < Seahorse::Client::Plugin
9
-
10
9
  # @api private
11
10
  class Handler < Seahorse::Client::Handler
12
11
  def call(context)
@@ -26,16 +25,17 @@ module Aws
26
25
  'String' => 1,
27
26
  'Binary' => 2,
28
27
  'Number' => 1
29
- }
28
+ }.freeze
30
29
 
31
- DATA_TYPE = /\A(String|Binary|Number)(\..+)?\z/
30
+ DATA_TYPE = /\A(String|Binary|Number)(\..+)?\z/.freeze
32
31
 
33
32
  NORMALIZED_ENCODING = Encoding::UTF_8
34
33
 
35
34
  def validate_send_message(context, response)
36
35
  body = context.params[:message_body]
37
36
  attributes = context.params[:message_attributes]
38
- validate_single_message(body, attributes, response)
37
+ system_attributes = context.params[:message_system_attributes]
38
+ validate_single_message(body, attributes, system_attributes, response)
39
39
  end
40
40
 
41
41
  def validate_send_message_batch(context, response)
@@ -43,63 +43,87 @@ module Aws
43
43
  id = entry[:id]
44
44
  body = entry[:message_body]
45
45
  attributes = entry[:message_attributes]
46
+ system_attributes = entry[:message_system_attributes]
46
47
  message_response = response.successful.select { |r| r.id == id }[0]
47
48
  unless message_response.nil?
48
- validate_single_message(body, attributes, message_response)
49
+ validate_single_message(body, attributes, system_attributes, message_response)
49
50
  end
50
51
  end
51
52
  end
52
53
 
53
- def validate_single_message(body, attributes, response)
54
+ def validate_single_message(body, attributes, system_attributes, response)
54
55
  validate_body(body, response)
55
56
  unless attributes.nil? || attributes.empty?
56
57
  validate_attributes(attributes, response)
57
58
  end
59
+ unless system_attributes.nil? || system_attributes.empty?
60
+ validate_system_attributes(system_attributes, response)
61
+ end
58
62
  end
59
63
 
60
64
  def validate_body(body, response)
61
65
  calculated_md5 = md5_of_message_body(body)
62
66
  returned_md5 = response.md5_of_message_body
63
- if calculated_md5 != returned_md5
64
- error_message = mismatch_error_message(
65
- 'message body',
66
- calculated_md5,
67
- returned_md5,
68
- response)
69
- raise Aws::Errors::ChecksumError, error_message
70
- end
67
+ return unless calculated_md5 != returned_md5
68
+
69
+ error_message = mismatch_error_message(
70
+ 'message body',
71
+ calculated_md5,
72
+ returned_md5,
73
+ response
74
+ )
75
+ raise Aws::Errors::ChecksumError, error_message
71
76
  end
72
77
 
73
78
  def validate_attributes(attributes, response)
74
79
  calculated_md5 = md5_of_message_attributes(attributes)
75
80
  returned_md5 = response.md5_of_message_attributes
76
- if returned_md5 != calculated_md5
77
- error_message = mismatch_error_message(
78
- 'message attributes',
79
- calculated_md5,
80
- returned_md5,
81
- response)
82
- raise Aws::Errors::ChecksumError, error_message
83
- end
81
+ return unless returned_md5 != calculated_md5
82
+
83
+ error_message = mismatch_error_message(
84
+ 'message attributes',
85
+ calculated_md5,
86
+ returned_md5,
87
+ response
88
+ )
89
+ raise Aws::Errors::ChecksumError, error_message
90
+ end
91
+
92
+ def validate_system_attributes(system_attributes, response)
93
+ calculated_md5 = md5_of_message_system_attributes(system_attributes)
94
+ returned_md5 = response.md5_of_message_system_attributes
95
+ return unless returned_md5 != calculated_md5
96
+
97
+ error_message = mismatch_error_message(
98
+ 'message system attributes',
99
+ calculated_md5,
100
+ returned_md5,
101
+ response
102
+ )
103
+ raise Aws::Errors::ChecksumError, error_message
84
104
  end
85
105
 
86
106
  def md5_of_message_body(message_body)
87
107
  OpenSSL::Digest::MD5.hexdigest(message_body)
88
108
  end
89
109
 
110
+ # MD5 of Message Attributes and System Attributes are effectively
111
+ # the same calculation. However, keeping these as two methods because
112
+ # they are modeled as two different shapes.
113
+ ###
90
114
  def md5_of_message_attributes(message_attributes)
91
- encoded = { }
115
+ encoded = {}
92
116
  message_attributes.each do |name, attribute|
93
117
  name = name.to_s
94
118
  encoded[name] = String.new
95
119
  data_type_without_label = DATA_TYPE.match(attribute[:data_type])[1]
96
120
  encoded[name] << encode_length_and_bytes(name) <<
97
- encode_length_and_bytes(attribute[:data_type]) <<
98
- [TRANSPORT_TYPE_ENCODINGS[data_type_without_label]].pack('C'.freeze)
121
+ encode_length_and_bytes(attribute[:data_type]) <<
122
+ [TRANSPORT_TYPE_ENCODINGS[data_type_without_label]].pack('C')
99
123
 
100
- if attribute[:string_value] != nil
124
+ if !attribute[:string_value].nil?
101
125
  encoded[name] << encode_length_and_string(attribute[:string_value])
102
- elsif attribute[:binary_value] != nil
126
+ elsif !attribute[:binary_value].nil?
103
127
  encoded[name] << encode_length_and_bytes(attribute[:binary_value])
104
128
  end
105
129
  end
@@ -110,6 +134,30 @@ module Aws
110
134
  OpenSSL::Digest::MD5.hexdigest(buffer)
111
135
  end
112
136
 
137
+ def md5_of_message_system_attributes(message_system_attributes)
138
+ encoded = {}
139
+ message_system_attributes.each do |name, attribute|
140
+ name = name.to_s
141
+ encoded[name] = String.new
142
+ data_type_without_label = DATA_TYPE.match(attribute[:data_type])[1]
143
+ encoded[name] << encode_length_and_bytes(name) <<
144
+ encode_length_and_bytes(attribute[:data_type]) <<
145
+ [TRANSPORT_TYPE_ENCODINGS[data_type_without_label]].pack('C')
146
+
147
+ if !attribute[:string_value].nil?
148
+ encoded[name] << encode_length_and_string(attribute[:string_value])
149
+ elsif !attribute[:binary_value].nil?
150
+ encoded[name] << encode_length_and_bytes(attribute[:binary_value])
151
+ end
152
+ end
153
+
154
+ buffer = encoded.keys.sort.reduce(String.new) do |string, name|
155
+ string << encoded[name]
156
+ end
157
+ OpenSSL::Digest::MD5.hexdigest(buffer)
158
+ end
159
+ ###
160
+
113
161
  def encode_length_and_string(string)
114
162
  string = String.new(string)
115
163
  string.encode!(NORMALIZED_ENCODING)
@@ -117,7 +165,7 @@ module Aws
117
165
  end
118
166
 
119
167
  def encode_length_and_bytes(bytes)
120
- [bytes.bytesize, bytes].pack('L>a*'.freeze)
168
+ [bytes.bytesize, bytes].pack('L>a*')
121
169
  end
122
170
 
123
171
  def mismatch_error_message(section, local_md5, returned_md5, response)
@@ -154,13 +202,14 @@ not match.
154
202
  end
155
203
 
156
204
  def add_handlers(handlers, config)
157
- if config.verify_checksums
158
- handlers.add(Handler, {
159
- priority: 10 ,
160
- step: :validate,
161
- operations: [:send_message, :send_message_batch]
162
- })
163
- end
205
+ return unless config.verify_checksums
206
+
207
+ handlers.add(
208
+ Handler,
209
+ priority: 10,
210
+ step: :validate,
211
+ operations: %i[send_message send_message_batch]
212
+ )
164
213
  end
165
214
  end
166
215
  end