aws-sdk-core 3.46.2 → 3.126.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1258 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -1
  5. data/lib/aws-defaults/default_configuration.rb +153 -0
  6. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  7. data/lib/aws-defaults.rb +3 -0
  8. data/lib/aws-sdk-core/arn.rb +92 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +40 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +20 -0
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +109 -0
  12. data/lib/aws-sdk-core/async_client_stubs.rb +82 -0
  13. data/lib/aws-sdk-core/binary/decode_handler.rb +11 -1
  14. data/lib/aws-sdk-core/binary/encode_handler.rb +34 -0
  15. data/lib/aws-sdk-core/binary/event_builder.rb +124 -0
  16. data/lib/aws-sdk-core/binary/event_parser.rb +50 -18
  17. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +7 -2
  18. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +55 -0
  19. data/lib/aws-sdk-core/binary.rb +5 -0
  20. data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +11 -1
  21. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
  22. data/lib/aws-sdk-core/client_stubs.rb +16 -13
  23. data/lib/aws-sdk-core/credential_provider.rb +1 -30
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +102 -40
  25. data/lib/aws-sdk-core/credentials.rb +2 -0
  26. data/lib/aws-sdk-core/deprecations.rb +17 -11
  27. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  28. data/lib/aws-sdk-core/ec2_metadata.rb +238 -0
  29. data/lib/aws-sdk-core/ecs_credentials.rb +18 -9
  30. data/lib/aws-sdk-core/endpoint_cache.rb +16 -11
  31. data/lib/aws-sdk-core/errors.rb +138 -15
  32. data/lib/aws-sdk-core/event_emitter.rb +44 -0
  33. data/lib/aws-sdk-core/ini_parser.rb +2 -0
  34. data/lib/aws-sdk-core/instance_profile_credentials.rb +179 -42
  35. data/lib/aws-sdk-core/json/builder.rb +2 -0
  36. data/lib/aws-sdk-core/json/error_handler.rb +21 -2
  37. data/lib/aws-sdk-core/json/handler.rb +21 -1
  38. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  39. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  40. data/lib/aws-sdk-core/json/parser.rb +10 -0
  41. data/lib/aws-sdk-core/json.rb +11 -28
  42. data/lib/aws-sdk-core/log/formatter.rb +16 -4
  43. data/lib/aws-sdk-core/log/handler.rb +2 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +38 -13
  45. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +48 -24
  47. data/lib/aws-sdk-core/pager.rb +5 -0
  48. data/lib/aws-sdk-core/param_converter.rb +2 -0
  49. data/lib/aws-sdk-core/param_validator.rb +63 -7
  50. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  51. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  52. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  53. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  54. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +28 -1
  55. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  56. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  57. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  58. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +12 -4
  59. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  60. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +16 -0
  61. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  62. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  63. data/lib/aws-sdk-core/plugins/http_checksum.rb +57 -0
  64. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  65. data/lib/aws-sdk-core/plugins/invocation_id.rb +35 -0
  66. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  71. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  73. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  75. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  76. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  77. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -16
  78. data/lib/aws-sdk-core/plugins/response_paging.rb +2 -0
  79. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
  80. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
  81. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
  82. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
  83. data/lib/aws-sdk-core/plugins/retry_errors.rb +295 -107
  84. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  85. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -25
  86. data/lib/aws-sdk-core/plugins/stub_responses.rb +24 -7
  87. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +53 -0
  88. data/lib/aws-sdk-core/plugins/user_agent.rb +6 -8
  89. data/lib/aws-sdk-core/process_credentials.rb +12 -5
  90. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  91. data/lib/aws-sdk-core/query/handler.rb +2 -0
  92. data/lib/aws-sdk-core/query/param.rb +2 -0
  93. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  94. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  95. data/lib/aws-sdk-core/query.rb +2 -0
  96. data/lib/aws-sdk-core/refreshing_credentials.rb +15 -2
  97. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  98. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  99. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  100. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  101. data/lib/aws-sdk-core/rest/request/endpoint.rb +10 -3
  102. data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
  103. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +4 -2
  104. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  105. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  106. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  107. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  108. data/lib/aws-sdk-core/rest.rb +2 -0
  109. data/lib/aws-sdk-core/shared_config.rb +153 -127
  110. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  111. data/lib/aws-sdk-core/sso_credentials.rb +136 -0
  112. data/lib/aws-sdk-core/structure.rb +14 -4
  113. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  114. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  115. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  117. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  118. data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
  119. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +52 -7
  120. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  121. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  122. data/lib/aws-sdk-core/stubbing/stub_data.rb +15 -4
  123. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  124. data/lib/aws-sdk-core/type_builder.rb +2 -0
  125. data/lib/aws-sdk-core/util.rb +6 -0
  126. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  127. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  128. data/lib/aws-sdk-core/waiters/waiter.rb +4 -2
  129. data/lib/aws-sdk-core/waiters.rb +2 -0
  130. data/lib/aws-sdk-core/xml/builder.rb +5 -3
  131. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  132. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  133. data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
  134. data/lib/aws-sdk-core/xml/error_handler.rb +29 -4
  135. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  136. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  137. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  139. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
  140. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  141. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  142. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  143. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  144. data/lib/aws-sdk-core/xml.rb +2 -0
  145. data/lib/aws-sdk-core.rb +23 -4
  146. data/lib/aws-sdk-sso/client.rb +568 -0
  147. data/lib/aws-sdk-sso/client_api.rb +190 -0
  148. data/lib/aws-sdk-sso/customizations.rb +1 -0
  149. data/lib/aws-sdk-sso/errors.rb +102 -0
  150. data/lib/aws-sdk-sso/resource.rb +26 -0
  151. data/lib/aws-sdk-sso/types.rb +352 -0
  152. data/lib/aws-sdk-sso.rb +55 -0
  153. data/lib/aws-sdk-sts/client.rb +1282 -531
  154. data/lib/aws-sdk-sts/client_api.rb +76 -1
  155. data/lib/aws-sdk-sts/customizations.rb +4 -0
  156. data/lib/aws-sdk-sts/errors.rb +153 -1
  157. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
  158. data/lib/aws-sdk-sts/presigner.rb +75 -0
  159. data/lib/aws-sdk-sts/resource.rb +4 -1
  160. data/lib/aws-sdk-sts/types.rb +958 -229
  161. data/lib/aws-sdk-sts.rb +16 -6
  162. data/lib/seahorse/client/async_base.rb +52 -0
  163. data/lib/seahorse/client/async_response.rb +64 -0
  164. data/lib/seahorse/client/base.rb +7 -2
  165. data/lib/seahorse/client/block_io.rb +6 -2
  166. data/lib/seahorse/client/configuration.rb +7 -1
  167. data/lib/seahorse/client/events.rb +3 -1
  168. data/lib/seahorse/client/h2/connection.rb +250 -0
  169. data/lib/seahorse/client/h2/handler.rb +152 -0
  170. data/lib/seahorse/client/handler.rb +2 -0
  171. data/lib/seahorse/client/handler_builder.rb +2 -0
  172. data/lib/seahorse/client/handler_list.rb +2 -0
  173. data/lib/seahorse/client/handler_list_entry.rb +6 -4
  174. data/lib/seahorse/client/http/async_response.rb +44 -0
  175. data/lib/seahorse/client/http/headers.rb +2 -0
  176. data/lib/seahorse/client/http/request.rb +5 -3
  177. data/lib/seahorse/client/http/response.rb +18 -11
  178. data/lib/seahorse/client/logging/formatter.rb +6 -2
  179. data/lib/seahorse/client/logging/handler.rb +2 -0
  180. data/lib/seahorse/client/managed_file.rb +2 -0
  181. data/lib/seahorse/client/net_http/connection_pool.rb +30 -23
  182. data/lib/seahorse/client/net_http/handler.rb +24 -7
  183. data/lib/seahorse/client/net_http/patches.rb +15 -84
  184. data/lib/seahorse/client/networking_error.rb +30 -0
  185. data/lib/seahorse/client/plugin.rb +10 -7
  186. data/lib/seahorse/client/plugin_list.rb +2 -0
  187. data/lib/seahorse/client/plugins/content_length.rb +14 -3
  188. data/lib/seahorse/client/plugins/endpoint.rb +4 -2
  189. data/lib/seahorse/client/plugins/h2.rb +69 -0
  190. data/lib/seahorse/client/plugins/logging.rb +2 -0
  191. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  192. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  193. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  194. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  195. data/lib/seahorse/client/plugins/response_target.rb +23 -14
  196. data/lib/seahorse/client/request.rb +2 -0
  197. data/lib/seahorse/client/request_context.rb +2 -0
  198. data/lib/seahorse/client/response.rb +5 -5
  199. data/lib/seahorse/model/api.rb +10 -0
  200. data/lib/seahorse/model/authorizer.rb +2 -0
  201. data/lib/seahorse/model/operation.rb +9 -0
  202. data/lib/seahorse/model/shapes.rb +29 -2
  203. data/lib/seahorse/util.rb +8 -1
  204. data/lib/seahorse/version.rb +2 -0
  205. data/lib/seahorse.rb +12 -0
  206. metadata +64 -14
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+ require 'securerandom'
5
+ require 'base64'
6
+
7
+ module Aws
8
+
9
+ # An auto-refreshing credential provider that works by assuming
10
+ # a role via {Aws::STS::Client#assume_role_with_web_identity}.
11
+ #
12
+ # role_credentials = Aws::AssumeRoleWebIdentityCredentials.new(
13
+ # client: Aws::STS::Client.new(...),
14
+ # role_arn: "linked::account::arn",
15
+ # web_identity_token_file: "/path/to/token/file",
16
+ # role_session_name: "session-name"
17
+ # ...
18
+ # )
19
+ # For full list of parameters accepted
20
+ # @see Aws::STS::Client#assume_role_with_web_identity
21
+ #
22
+ #
23
+ # If you omit `:client` option, a new {STS::Client} object will be
24
+ # constructed.
25
+ class AssumeRoleWebIdentityCredentials
26
+
27
+ include CredentialProvider
28
+ include RefreshingCredentials
29
+
30
+ # @param [Hash] options
31
+ # @option options [required, String] :role_arn the IAM role
32
+ # to be assumed
33
+ #
34
+ # @option options [required, String] :web_identity_token_file
35
+ # absolute path to the file on disk containing OIDC token
36
+ #
37
+ # @option options [String] :role_session_name the IAM session
38
+ # name used to distinguish session, when not provided, base64
39
+ # encoded UUID is generated as the session name
40
+ #
41
+ # @option options [STS::Client] :client
42
+ #
43
+ # @option options [Callable] before_refresh Proc called before
44
+ # credentials are refreshed. `before_refresh` is called
45
+ # with an instance of this object when
46
+ # AWS credentials are required and need to be refreshed.
47
+ def initialize(options = {})
48
+ client_opts = {}
49
+ @assume_role_web_identity_params = {}
50
+ @token_file = options.delete(:web_identity_token_file)
51
+ options.each_pair do |key, value|
52
+ if self.class.assume_role_web_identity_options.include?(key)
53
+ @assume_role_web_identity_params[key] = value
54
+ else
55
+ client_opts[key] = value
56
+ end
57
+ end
58
+
59
+ unless @assume_role_web_identity_params[:role_session_name]
60
+ # not provided, generate encoded UUID as session name
61
+ @assume_role_web_identity_params[:role_session_name] = _session_name
62
+ end
63
+ @client = client_opts[:client] || STS::Client.new(client_opts.merge(credentials: false))
64
+ super
65
+ end
66
+
67
+ # @return [STS::Client]
68
+ attr_reader :client
69
+
70
+ private
71
+
72
+ def refresh
73
+ # read from token file everytime it refreshes
74
+ @assume_role_web_identity_params[:web_identity_token] = _token_from_file(@token_file)
75
+
76
+ c = @client.assume_role_with_web_identity(
77
+ @assume_role_web_identity_params).credentials
78
+ @credentials = Credentials.new(
79
+ c.access_key_id,
80
+ c.secret_access_key,
81
+ c.session_token
82
+ )
83
+ @expiration = c.expiration
84
+ end
85
+
86
+ def _token_from_file(path)
87
+ unless path && File.exist?(path)
88
+ raise Aws::Errors::MissingWebIdentityTokenFile.new
89
+ end
90
+ File.read(path)
91
+ end
92
+
93
+ def _session_name
94
+ Base64.strict_encode64(SecureRandom.uuid)
95
+ end
96
+
97
+ class << self
98
+
99
+ # @api private
100
+ def assume_role_web_identity_options
101
+ @arwio ||= begin
102
+ input = STS::Client.api.operation(:assume_role_with_web_identity).input
103
+ Set.new(input.shape.member_names)
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module AsyncClientStubs
5
+
6
+ include Aws::ClientStubs
7
+
8
+ # @api private
9
+ def setup_stubbing
10
+ @stubs = {}
11
+ @stub_mutex = Mutex.new
12
+ if Hash === @config.stub_responses
13
+ @config.stub_responses.each do |operation_name, stubs|
14
+ apply_stubs(operation_name, Array === stubs ? stubs : [stubs])
15
+ end
16
+ end
17
+
18
+ # When a client is stubbed allow the user to access the requests made
19
+ @api_requests = []
20
+
21
+ # allow to access signaled events when client is stubbed
22
+ @send_events = []
23
+
24
+ requests = @api_requests
25
+ send_events = @send_events
26
+
27
+ self.handle do |context|
28
+ if input_stream = context[:input_event_stream_handler]
29
+ stub_stream = StubStream.new
30
+ stub_stream.send_events = send_events
31
+ input_stream.event_emitter.stream = stub_stream
32
+ input_stream.event_emitter.validate_event = context.config.validate_params
33
+ end
34
+ requests << {
35
+ operation_name: context.operation_name,
36
+ params: context.params,
37
+ context: context
38
+ }
39
+ @handler.call(context)
40
+ end
41
+ end
42
+
43
+ def send_events
44
+ if config.stub_responses
45
+ @send_events
46
+ else
47
+ msg = 'This method is only implemented for stubbed clients, and is '\
48
+ 'available when you enable stubbing in the constructor with `stub_responses: true`'
49
+ raise NotImplementedError.new(msg)
50
+ end
51
+ end
52
+
53
+ class StubStream
54
+
55
+ def initialize
56
+ @state = :open
57
+ end
58
+
59
+ attr_accessor :send_events
60
+
61
+ attr_reader :state
62
+
63
+ def data(bytes, options = {})
64
+ if options[:end_stream]
65
+ @state = :closed
66
+ else
67
+ decoder = Aws::EventStream::Decoder.new
68
+ event = decoder.decode_chunk(bytes).first
69
+ @send_events << decoder.decode_chunk(event.payload.read).first
70
+ end
71
+ end
72
+
73
+ def closed?
74
+ @state == :closed
75
+ end
76
+
77
+ def close
78
+ @state = :closed
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Binary
3
5
 
@@ -23,11 +25,19 @@ module Aws
23
25
 
24
26
  context.http_response.on_headers(200) do
25
27
  protocol = context.config.api.metadata['protocol']
28
+ output_handler = context[:output_event_stream_handler] || context[:event_stream_handler]
26
29
  context.http_response.body = EventStreamDecoder.new(
27
30
  protocol,
28
31
  rules,
32
+ context.operation.output,
33
+ context.operation.errors,
29
34
  context.http_response.body,
30
- context[:event_stream_handler])
35
+ output_handler)
36
+ if input_emitter = context[:input_event_emitter]
37
+ # #emit will be blocked until 200 success
38
+ # see Aws::EventEmitter#emit
39
+ input_emitter.signal_queue << "ready"
40
+ end
31
41
  end
32
42
 
33
43
  context.http_response.on_success(200) do
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Binary
5
+
6
+ # @api private
7
+ class EncodeHandler < Seahorse::Client::Handler
8
+
9
+ def call(context)
10
+ if eventstream_member = eventstream_input?(context)
11
+ input_es_handler = context[:input_event_stream_handler]
12
+ input_es_handler.event_emitter.encoder = EventStreamEncoder.new(
13
+ context.config.api.metadata['protocol'],
14
+ eventstream_member,
15
+ context.operation.input,
16
+ context.config.sigv4_signer
17
+ )
18
+ context[:input_event_emitter] = input_es_handler.event_emitter
19
+ end
20
+ @handler.call(context)
21
+ end
22
+
23
+ private
24
+
25
+ def eventstream_input?(ctx)
26
+ ctx.operation.input.shape.members.each do |_, ref|
27
+ return ref if ref.eventstream
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Binary
5
+ # @api private
6
+ class EventBuilder
7
+
8
+ include Seahorse::Model::Shapes
9
+
10
+ # @param [Class] serializer_class
11
+ # @param [Seahorse::Model::ShapeRef] rules (of eventstream member)
12
+ def initialize(serializer_class, rules)
13
+ @serializer_class = serializer_class
14
+ @rules = rules
15
+ end
16
+
17
+ def apply(event_type, params)
18
+ event_ref = @rules.shape.member(event_type)
19
+ _event_stream_message(event_ref, params)
20
+ end
21
+
22
+ private
23
+
24
+ def _event_stream_message(event_ref, params)
25
+ es_headers = {}
26
+ payload = ""
27
+
28
+ es_headers[":message-type"] = Aws::EventStream::HeaderValue.new(
29
+ type: "string", value: "event")
30
+ es_headers[":event-type"] = Aws::EventStream::HeaderValue.new(
31
+ type: "string", value: event_ref.location_name)
32
+
33
+ explicit_payload = false
34
+ implicit_payload_members = {}
35
+ event_ref.shape.members.each do |member_name, member_ref|
36
+ unless member_ref.eventheader
37
+ if member_ref.eventpayload
38
+ explicit_payload = true
39
+ else
40
+ implicit_payload_members[member_name] = member_ref
41
+ end
42
+ end
43
+ end
44
+
45
+ # implict payload
46
+ if !explicit_payload && !implicit_payload_members.empty?
47
+ if implicit_payload_members.size > 1
48
+ payload_shape = Shapes::StructureShape.new
49
+ implicit_payload_members.each do |m_name, m_ref|
50
+ payload_shape.add_member(m_name, m_ref)
51
+ end
52
+ payload_ref = Shapes::ShapeRef.new(shape: payload_shape)
53
+
54
+ payload = build_payload_members(payload_ref, params)
55
+ else
56
+ m_name, m_ref = implicit_payload_members.first
57
+ streaming, content_type = _content_type(m_ref.shape)
58
+
59
+ es_headers[":content-type"] = Aws::EventStream::HeaderValue.new(
60
+ type: "string", value: content_type)
61
+ payload = _build_payload(streaming, m_ref, params[m_name])
62
+ end
63
+ end
64
+
65
+
66
+ event_ref.shape.members.each do |member_name, member_ref|
67
+ if member_ref.eventheader && params[member_name]
68
+ header_value = params[member_name]
69
+ es_headers[member_ref.shape.name] = Aws::EventStream::HeaderValue.new(
70
+ type: _header_value_type(member_ref.shape, header_value),
71
+ value: header_value
72
+ )
73
+ elsif member_ref.eventpayload && params[member_name]
74
+ # explicit payload
75
+ streaming, content_type = _content_type(member_ref.shape)
76
+
77
+ es_headers[":content-type"] = Aws::EventStream::HeaderValue.new(
78
+ type: "string", value: content_type)
79
+ payload = _build_payload(streaming, member_ref, params[member_name])
80
+ end
81
+ end
82
+
83
+ Aws::EventStream::Message.new(
84
+ headers: es_headers,
85
+ payload: StringIO.new(payload)
86
+ )
87
+ end
88
+
89
+ def _content_type(shape)
90
+ case shape
91
+ when BlobShape then [true, "application/octet-stream"]
92
+ when StringShape then [true, "text/plain"]
93
+ when StructureShape then
94
+ if @serializer_class.name.include?('Xml')
95
+ [false, "text/xml"]
96
+ elsif @serializer_class.name.include?('Json')
97
+ [false, "application/json"]
98
+ end
99
+ else
100
+ raise Aws::Errors::EventStreamBuilderError.new(
101
+ "Unsupport eventpayload shape: #{shape.name}")
102
+ end
103
+ end
104
+
105
+ def _header_value_type(shape, value)
106
+ case shape
107
+ when StringShape then "string"
108
+ when IntegerShape then "integer"
109
+ when TimestampShape then "timestamp"
110
+ when BlobShape then "bytes"
111
+ when BooleanShape then !!value ? "bool_true" : "bool_false"
112
+ else
113
+ raise Aws::Errors::EventStreamBuilderError.new(
114
+ "Unsupported eventheader shape: #{shape.name}")
115
+ end
116
+ end
117
+
118
+ def _build_payload(streaming, ref, value)
119
+ streaming ? value : @serializer_class.new(ref).serialize(value)
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Binary
3
5
  # @api private
@@ -6,10 +8,14 @@ module Aws
6
8
  include Seahorse::Model::Shapes
7
9
 
8
10
  # @param [Class] parser_class
9
- # @param [Seahorse::Model::ShapeRef] rules
10
- def initialize(parser_class, rules)
11
+ # @param [Seahorse::Model::ShapeRef] rules (of eventstream member)
12
+ # @param [Array] error_refs array of errors ShapeRef
13
+ # @param [Seahorse::Model::ShapeRef] output_ref
14
+ def initialize(parser_class, rules, error_refs, output_ref)
11
15
  @parser_class = parser_class
12
16
  @rules = rules
17
+ @error_refs = error_refs
18
+ @output_ref = output_ref
13
19
  end
14
20
 
15
21
  # Parse raw event message into event struct
@@ -31,9 +37,7 @@ module Aws
31
37
  when 'event'
32
38
  parse_event(raw_event)
33
39
  when 'exception'
34
- # Pending
35
- raise Aws::Errors::EventStreamParserError.new(
36
- ':exception event parsing is not supported')
40
+ parse_exception(raw_event)
37
41
  else
38
42
  raise Aws::Errors::EventStreamParserError.new(
39
43
  'Unrecognized :message-type value for the event')
@@ -44,6 +48,15 @@ module Aws
44
48
  end
45
49
  end
46
50
 
51
+ def parse_exception(raw_event)
52
+ exception_type = raw_event.headers.delete(":exception-type").value
53
+ name, ref = @rules.shape.member_by_location_name(exception_type)
54
+ # exception lives in payload implictly
55
+ exception = parse_payload(raw_event.payload.read, ref)
56
+ exception.event_type = name
57
+ exception
58
+ end
59
+
47
60
  def parse_error_event(raw_event)
48
61
  error_code = raw_event.headers.delete(":error-code")
49
62
  error_message = raw_event.headers.delete(":error-message")
@@ -58,35 +71,54 @@ module Aws
58
71
  event_type = raw_event.headers.delete(":event-type").value
59
72
  # content_type = raw_event.headers.delete(":content-type").value
60
73
 
61
- # Pending
62
74
  if event_type == 'initial-response'
63
- raise Aws::Errors::EventStreamParserError.new(
64
- 'non eventstream member at response is not supported yet'
65
- )
75
+ event = Struct.new(:event_type, :response).new
76
+ event.event_type = :initial_response
77
+ event.response = parse_payload(raw_event.payload.read, @output_ref)
78
+ return event
66
79
  end
67
80
 
68
81
  # locate event from eventstream
69
82
  name, ref = @rules.shape.member_by_location_name(event_type)
70
- raise "Non event member found at eventstream" unless ref.event
83
+ unless ref && ref.event
84
+ return Struct.new(:event_type, :raw_event_type, :raw_event)
85
+ .new(:unknown_event, event_type, raw_event)
86
+ end
71
87
 
72
88
  event = ref.shape.struct_class.new
89
+
90
+ explicit_payload = false
91
+ implicit_payload_members = {}
92
+ ref.shape.members.each do |member_name, member_ref|
93
+ unless member_ref.eventheader
94
+ if member_ref.eventpayload
95
+ explicit_payload = true
96
+ else
97
+ implicit_payload_members[member_name] = member_ref
98
+ end
99
+ end
100
+ end
101
+
102
+ # implicit payload
103
+ if !explicit_payload && !implicit_payload_members.empty?
104
+ event = parse_payload(raw_event.payload.read, ref)
105
+ end
73
106
  event.event_type = name
107
+
74
108
  # locate payload and headers in the event
75
109
  ref.shape.members.each do |member_name, member_ref|
76
- if member_ref.eventpayload
77
- eventpayload_streaming?(member_ref) ?
78
- event.send("#{member_name}=", raw_event.payload) :
79
- event.send("#{member_name}=", parse_payload(raw_event.payload.read, member_ref))
80
- elsif member_ref.eventheader
110
+ if member_ref.eventheader
81
111
  # allow incomplete event members in response
82
112
  if raw_event.headers.key?(member_ref.location_name)
83
113
  event.send("#{member_name}=", raw_event.headers[member_ref.location_name].value)
84
114
  end
85
- else
86
- raise "Non eventpayload or eventheader member found at event"
115
+ elsif member_ref.eventpayload
116
+ # explicit payload
117
+ eventpayload_streaming?(member_ref) ?
118
+ event.send("#{member_name}=", raw_event.payload) :
119
+ event.send("#{member_name}=", parse_payload(raw_event.payload.read, member_ref))
87
120
  end
88
121
  end
89
-
90
122
  event
91
123
  end
92
124
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-eventstream'
2
4
 
3
5
  module Aws
@@ -7,11 +9,13 @@ module Aws
7
9
 
8
10
  # @param [String] protocol
9
11
  # @param [ShapeRef] rules ShapeRef of the eventstream member
12
+ # @param [ShapeRef] output_ref ShapeRef of output shape
13
+ # @param [Array] error_refs array of ShapeRefs for errors
10
14
  # @param [EventStream|nil] event_stream_handler A Service EventStream object
11
15
  # that registered with callbacks for processing events when they arrive
12
- def initialize(protocol, rules, io, event_stream_handler = nil)
16
+ def initialize(protocol, rules, output_ref, error_refs, io, event_stream_handler = nil)
13
17
  @decoder = Aws::EventStream::Decoder.new
14
- @event_parser = EventParser.new(parser_class(protocol), rules)
18
+ @event_parser = EventParser.new(parser_class(protocol), rules, error_refs, output_ref)
15
19
  @stream_class = extract_stream_class(rules.shape.struct_class)
16
20
  @emitter = event_stream_handler.event_emitter
17
21
  @events = []
@@ -42,6 +46,7 @@ module Aws
42
46
  case protocol
43
47
  when 'rest-xml' then Aws::Xml::Parser
44
48
  when 'rest-json' then Aws::Json::Parser
49
+ when 'json' then Aws::Json::Parser
45
50
  else raise "unsupported protocol #{protocol} for event stream"
46
51
  end
47
52
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-eventstream'
4
+
5
+ module Aws
6
+ module Binary
7
+ # @api private
8
+ class EventStreamEncoder
9
+
10
+ # @param [String] protocol
11
+ # @param [ShapeRef] rules ShapeRef of the eventstream member
12
+ # @param [ShapeRef] input_ref ShapeRef of the input shape
13
+ # @param [Aws::Sigv4::Signer] signer
14
+ def initialize(protocol, rules, input_ref, signer)
15
+ @encoder = Aws::EventStream::Encoder.new
16
+ @event_builder = EventBuilder.new(serializer_class(protocol), rules)
17
+ @input_ref = input_ref
18
+ @rules = rules
19
+ @signer = signer
20
+ @prior_signature = nil
21
+ end
22
+
23
+ attr_reader :rules
24
+
25
+ attr_accessor :prior_signature
26
+
27
+ def encode(event_type, params)
28
+ if event_type == :end_stream
29
+ payload = ''
30
+ else
31
+ payload = @encoder.encode(@event_builder.apply(event_type, params))
32
+ end
33
+ headers, signature = @signer.sign_event(@prior_signature, payload, @encoder)
34
+ @prior_signature = signature
35
+ message = Aws::EventStream::Message.new(
36
+ headers: headers,
37
+ payload: StringIO.new(payload)
38
+ )
39
+ @encoder.encode(message)
40
+ end
41
+
42
+ private
43
+
44
+ def serializer_class(protocol)
45
+ case protocol
46
+ when 'rest-xml' then Xml::Builder
47
+ when 'rest-json' then Json::Builder
48
+ when 'json' then Json::Builder
49
+ else raise "unsupported protocol #{protocol} for event stream"
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'binary/decode_handler'
4
+ require_relative 'binary/encode_handler'
2
5
  require_relative 'binary/event_stream_decoder'
6
+ require_relative 'binary/event_stream_encoder'
7
+ require_relative 'binary/event_builder'
3
8
  require_relative 'binary/event_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
  require 'socket'
3
5
 
@@ -6,8 +8,10 @@ module Aws
6
8
  # @api private
7
9
  class Publisher
8
10
  attr_reader :agent_port
11
+ attr_reader :agent_host
9
12
 
10
13
  def initialize(opts = {})
14
+ @agent_host = opts[:agent_host] || "127.0.0.1"
11
15
  @agent_port = opts[:agent_port]
12
16
  @mutex = Mutex.new
13
17
  end
@@ -18,6 +22,12 @@ module Aws
18
22
  end
19
23
  end
20
24
 
25
+ def agent_host=(value)
26
+ @mutex.synchronize do
27
+ @agent_host = value
28
+ end
29
+ end
30
+
21
31
  def publish(request_metrics)
22
32
  send_datagram(request_metrics.api_call.to_json)
23
33
  request_metrics.api_call_attempts.each do |attempt|
@@ -29,7 +39,7 @@ module Aws
29
39
  if @agent_port
30
40
  socket = UDPSocket.new
31
41
  begin
32
- socket.connect("127.0.0.1", @agent_port)
42
+ socket.connect(@agent_host, @agent_port)
33
43
  socket.send(msg, 0)
34
44
  rescue Errno::ECONNREFUSED
35
45
  # Drop on the floor
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module ClientSideMonitoring
3
5
  # @api private