aws-sdk-core 3.46.0 → 3.94.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/VERSION +1 -1
- data/lib/aws-sdk-core.rb +7 -0
- data/lib/aws-sdk-core/arn.rb +77 -0
- data/lib/aws-sdk-core/arn_parser.rb +38 -0
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +102 -0
- data/lib/aws-sdk-core/async_client_stubs.rb +80 -0
- data/lib/aws-sdk-core/binary.rb +3 -0
- data/lib/aws-sdk-core/binary/decode_handler.rb +9 -1
- data/lib/aws-sdk-core/binary/encode_handler.rb +32 -0
- data/lib/aws-sdk-core/binary/event_builder.rb +122 -0
- data/lib/aws-sdk-core/binary/event_parser.rb +48 -18
- data/lib/aws-sdk-core/binary/event_stream_decoder.rb +5 -2
- data/lib/aws-sdk-core/binary/event_stream_encoder.rb +53 -0
- data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +9 -1
- data/lib/aws-sdk-core/client_stubs.rb +10 -9
- data/lib/aws-sdk-core/credential_provider.rb +0 -31
- data/lib/aws-sdk-core/credential_provider_chain.rb +79 -39
- data/lib/aws-sdk-core/deprecations.rb +16 -10
- data/lib/aws-sdk-core/ecs_credentials.rb +12 -8
- data/lib/aws-sdk-core/endpoint_cache.rb +14 -11
- data/lib/aws-sdk-core/errors.rb +94 -6
- data/lib/aws-sdk-core/event_emitter.rb +42 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +120 -38
- data/lib/aws-sdk-core/json.rb +13 -14
- data/lib/aws-sdk-core/json/error_handler.rb +19 -2
- data/lib/aws-sdk-core/json/handler.rb +19 -1
- data/lib/aws-sdk-core/log/formatter.rb +7 -1
- data/lib/aws-sdk-core/log/param_filter.rb +3 -3
- data/lib/aws-sdk-core/pageable_response.rb +34 -20
- data/lib/aws-sdk-core/param_validator.rb +11 -5
- data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +26 -1
- data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +1 -1
- data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +14 -0
- data/lib/aws-sdk-core/plugins/invocation_id.rb +33 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +8 -1
- data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +137 -0
- data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +98 -0
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +142 -0
- data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +57 -0
- data/lib/aws-sdk-core/plugins/retry_errors.rb +290 -106
- data/lib/aws-sdk-core/plugins/signature_v4.rb +13 -2
- data/lib/aws-sdk-core/plugins/stub_responses.rb +20 -7
- data/lib/aws-sdk-core/plugins/transfer_encoding.rb +51 -0
- data/lib/aws-sdk-core/plugins/user_agent.rb +4 -8
- data/lib/aws-sdk-core/process_credentials.rb +9 -3
- data/lib/aws-sdk-core/shared_config.rb +95 -125
- data/lib/aws-sdk-core/structure.rb +1 -2
- data/lib/aws-sdk-core/stubbing/protocols/rest.rb +19 -0
- data/lib/aws-sdk-core/stubbing/stub_data.rb +13 -4
- data/lib/aws-sdk-core/util.rb +4 -0
- data/lib/aws-sdk-core/waiters/waiter.rb +2 -2
- data/lib/aws-sdk-core/xml/error_handler.rb +26 -3
- data/lib/aws-sdk-sts.rb +7 -4
- data/lib/aws-sdk-sts/client.rb +1109 -459
- data/lib/aws-sdk-sts/client_api.rb +67 -0
- data/lib/aws-sdk-sts/customizations.rb +2 -0
- data/lib/aws-sdk-sts/errors.rb +150 -0
- data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +32 -0
- data/lib/aws-sdk-sts/presigner.rb +67 -0
- data/lib/aws-sdk-sts/resource.rb +1 -0
- data/lib/aws-sdk-sts/types.rb +736 -176
- data/lib/seahorse.rb +9 -0
- data/lib/seahorse/client/async_base.rb +50 -0
- data/lib/seahorse/client/async_response.rb +62 -0
- data/lib/seahorse/client/base.rb +4 -2
- data/lib/seahorse/client/configuration.rb +4 -2
- data/lib/seahorse/client/events.rb +1 -1
- data/lib/seahorse/client/h2/connection.rb +246 -0
- data/lib/seahorse/client/h2/handler.rb +151 -0
- data/lib/seahorse/client/handler_list_entry.rb +2 -2
- data/lib/seahorse/client/http/async_response.rb +42 -0
- data/lib/seahorse/client/http/response.rb +13 -8
- data/lib/seahorse/client/logging/formatter.rb +4 -2
- data/lib/seahorse/client/net_http/connection_pool.rb +19 -20
- data/lib/seahorse/client/net_http/handler.rb +7 -1
- data/lib/seahorse/client/net_http/patches.rb +7 -1
- data/lib/seahorse/client/networking_error.rb +28 -0
- data/lib/seahorse/client/plugin.rb +5 -4
- data/lib/seahorse/client/plugins/content_length.rb +5 -2
- data/lib/seahorse/client/plugins/h2.rb +64 -0
- data/lib/seahorse/client/response.rb +3 -5
- data/lib/seahorse/model/api.rb +4 -0
- data/lib/seahorse/model/operation.rb +4 -0
- data/lib/seahorse/model/shapes.rb +2 -2
- metadata +43 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 013be14c50cd2f84bc8db92fbcc838368de7424782da617a63e5ded5ad9b132c
|
4
|
+
data.tar.gz: 6f64cca7a945df5caf0f074e93860de149ac1f4ecb4d3d5c4d37ab785828165f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f587d229ac78de946e51d724026979c92daf3252f1e6fe0931f9e52e469ee75618ba25d87186757358c0826df6c891974760ec6cab2a03df8a089955b7856a3f
|
7
|
+
data.tar.gz: 55ce6c601c093dccd8487b9e28834300c2851c8b31a0149385aa15052b6acdec0d79ed155f868cd1e13bfbaeaa5d4316a13c0fde928625fd089ee2d3ab493edf
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.94.0
|
data/lib/aws-sdk-core.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative 'aws-sdk-core/deprecations'
|
|
9
9
|
require_relative 'aws-sdk-core/credential_provider'
|
10
10
|
require_relative 'aws-sdk-core/refreshing_credentials'
|
11
11
|
require_relative 'aws-sdk-core/assume_role_credentials'
|
12
|
+
require_relative 'aws-sdk-core/assume_role_web_identity_credentials'
|
12
13
|
require_relative 'aws-sdk-core/credentials'
|
13
14
|
require_relative 'aws-sdk-core/credential_provider_chain'
|
14
15
|
require_relative 'aws-sdk-core/ecs_credentials'
|
@@ -19,6 +20,7 @@ require_relative 'aws-sdk-core/process_credentials'
|
|
19
20
|
# client modules
|
20
21
|
|
21
22
|
require_relative 'aws-sdk-core/client_stubs'
|
23
|
+
require_relative 'aws-sdk-core/async_client_stubs'
|
22
24
|
require_relative 'aws-sdk-core/eager_loader'
|
23
25
|
require_relative 'aws-sdk-core/errors'
|
24
26
|
require_relative 'aws-sdk-core/pageable_response'
|
@@ -77,6 +79,11 @@ require_relative 'aws-sdk-core/endpoint_cache'
|
|
77
79
|
require_relative 'aws-sdk-core/client_side_monitoring/request_metrics'
|
78
80
|
require_relative 'aws-sdk-core/client_side_monitoring/publisher'
|
79
81
|
|
82
|
+
# arn
|
83
|
+
|
84
|
+
require_relative 'aws-sdk-core/arn'
|
85
|
+
require_relative 'aws-sdk-core/arn_parser'
|
86
|
+
|
80
87
|
# aws-sdk-sts is vendored to support Aws::AssumeRoleCredentials
|
81
88
|
|
82
89
|
require 'aws-sdk-sts'
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Aws
|
2
|
+
# Create and provide access to components of Amazon Resource Names (ARN).
|
3
|
+
#
|
4
|
+
# You can create an ARN and access it's components like the following:
|
5
|
+
#
|
6
|
+
# arn = Aws::ARN.new(
|
7
|
+
# partition: 'aws',
|
8
|
+
# service: 's3',
|
9
|
+
# region: 'us-west-2',
|
10
|
+
# account_id: '12345678910',
|
11
|
+
# resource: 'foo/bar'
|
12
|
+
# )
|
13
|
+
# # => #<Aws::ARN ...>
|
14
|
+
#
|
15
|
+
# arn.to_s
|
16
|
+
# # => "arn:aws:s3:us-west-2:12345678910:foo/bar"
|
17
|
+
#
|
18
|
+
# arn.partition
|
19
|
+
# # => 'aws'
|
20
|
+
# arn.service
|
21
|
+
# # => 's3'
|
22
|
+
# arn.resource
|
23
|
+
# # => foo/bar
|
24
|
+
#
|
25
|
+
# # Note: parser available for parsing resource details
|
26
|
+
# @see Aws::ARNParser#parse_resource
|
27
|
+
#
|
28
|
+
# @see https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns
|
29
|
+
class ARN
|
30
|
+
|
31
|
+
# @param [Hash] options
|
32
|
+
# @option options [String] :partition
|
33
|
+
# @option options [String] :service
|
34
|
+
# @option options [String] :region
|
35
|
+
# @option options [String] :account_id
|
36
|
+
# @option options [String] :resource
|
37
|
+
def initialize(options = {})
|
38
|
+
@partition = options[:partition]
|
39
|
+
@service = options[:service]
|
40
|
+
@region = options[:region]
|
41
|
+
@account_id = options[:account_id]
|
42
|
+
@resource = options[:resource]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String]
|
46
|
+
attr_reader :partition
|
47
|
+
|
48
|
+
# @return [String]
|
49
|
+
attr_reader :service
|
50
|
+
|
51
|
+
# @return [String]
|
52
|
+
attr_reader :region
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
attr_reader :account_id
|
56
|
+
|
57
|
+
# @return [String]
|
58
|
+
attr_reader :resource
|
59
|
+
|
60
|
+
# Validates ARN contains non-empty required components.
|
61
|
+
# Region and account_id can be optional.
|
62
|
+
#
|
63
|
+
# @return [Boolean]
|
64
|
+
def valid?
|
65
|
+
!partition.nil? && !partition.empty? &&
|
66
|
+
!service.nil? && !service.empty? &&
|
67
|
+
!resource.nil? && !resource.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
# Return the ARN format in string
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
def to_s
|
74
|
+
"arn:#{partition}:#{service}:#{region}:#{account_id}:#{resource}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Aws
|
2
|
+
module ARNParser
|
3
|
+
# Parse a string with an ARN format into an {Aws::ARN} object.
|
4
|
+
# `InvalidARNError` would be raised when encountering a parsing error or the
|
5
|
+
# ARN object contains invalid components (nil/empty).
|
6
|
+
#
|
7
|
+
# @param [String] arn_str
|
8
|
+
#
|
9
|
+
# @return [Aws::ARN]
|
10
|
+
# @see https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns
|
11
|
+
def self.parse(arn_str)
|
12
|
+
parts = arn_str.nil? ? [] : arn_str.split(':', 6)
|
13
|
+
raise Aws::Errors::InvalidARNError if parts.size < 6
|
14
|
+
|
15
|
+
# part[0] is "arn"
|
16
|
+
arn = ARN.new(
|
17
|
+
partition: parts[1],
|
18
|
+
service: parts[2],
|
19
|
+
region: parts[3],
|
20
|
+
account_id: parts[4],
|
21
|
+
resource: parts[5]
|
22
|
+
)
|
23
|
+
raise Aws::Errors::InvalidARNError unless arn.valid?
|
24
|
+
|
25
|
+
arn
|
26
|
+
end
|
27
|
+
|
28
|
+
# Checks whether a String could be a ARN or not. An ARN starts with 'arn:'
|
29
|
+
# and has at least 6 segments separated by a colon (:).
|
30
|
+
#
|
31
|
+
# @param [String] str
|
32
|
+
#
|
33
|
+
# @return [Boolean]
|
34
|
+
def self.arn?(str)
|
35
|
+
!str.nil? && str.start_with?('arn:') && str.scan(/:/).length >= 5
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
|
7
|
+
# An auto-refreshing credential provider that works by assuming
|
8
|
+
# a role via {Aws::STS::Client#assume_role_with_web_identity}.
|
9
|
+
#
|
10
|
+
# role_credentials = Aws::AssumeRoleWebIdentityCredentials.new(
|
11
|
+
# client: Aws::STS::Client.new(...),
|
12
|
+
# role_arn: "linked::account::arn",
|
13
|
+
# web_identity_token_file: "/path/to/token/file",
|
14
|
+
# role_session_name: "session-name"
|
15
|
+
# ...
|
16
|
+
# )
|
17
|
+
# For full list of parameters accepted
|
18
|
+
# @see Aws::STS::Client#assume_role_with_web_identity
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# If you omit `:client` option, a new {STS::Client} object will be
|
22
|
+
# constructed.
|
23
|
+
class AssumeRoleWebIdentityCredentials
|
24
|
+
|
25
|
+
include CredentialProvider
|
26
|
+
include RefreshingCredentials
|
27
|
+
|
28
|
+
# @param [Hash] options
|
29
|
+
# @option options [required, String] :role_arn the IAM role
|
30
|
+
# to be assumed
|
31
|
+
#
|
32
|
+
# @option options [required, String] :web_identity_token_file
|
33
|
+
# absolute path to the file on disk containing OIDC token
|
34
|
+
#
|
35
|
+
# @option options [String] :role_session_name the IAM session
|
36
|
+
# name used to distinguish session, when not provided, base64
|
37
|
+
# encoded UUID is generated as the session name
|
38
|
+
#
|
39
|
+
# @option options [STS::Client] :client
|
40
|
+
def initialize(options = {})
|
41
|
+
client_opts = {}
|
42
|
+
@assume_role_web_identity_params = {}
|
43
|
+
@token_file = options.delete(:web_identity_token_file)
|
44
|
+
options.each_pair do |key, value|
|
45
|
+
if self.class.assume_role_web_identity_options.include?(key)
|
46
|
+
@assume_role_web_identity_params[key] = value
|
47
|
+
else
|
48
|
+
client_opts[key] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
unless @assume_role_web_identity_params[:role_session_name]
|
53
|
+
# not provided, generate encoded UUID as session name
|
54
|
+
@assume_role_web_identity_params[:role_session_name] = _session_name
|
55
|
+
end
|
56
|
+
@client = client_opts[:client] || STS::Client.new(client_opts.merge(credentials: false))
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [STS::Client]
|
61
|
+
attr_reader :client
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def refresh
|
66
|
+
# read from token file everytime it refreshes
|
67
|
+
@assume_role_web_identity_params[:web_identity_token] = _token_from_file(@token_file)
|
68
|
+
|
69
|
+
c = @client.assume_role_with_web_identity(
|
70
|
+
@assume_role_web_identity_params).credentials
|
71
|
+
@credentials = Credentials.new(
|
72
|
+
c.access_key_id,
|
73
|
+
c.secret_access_key,
|
74
|
+
c.session_token
|
75
|
+
)
|
76
|
+
@expiration = c.expiration
|
77
|
+
end
|
78
|
+
|
79
|
+
def _token_from_file(path)
|
80
|
+
unless path && File.exist?(path)
|
81
|
+
raise Aws::Errors::MissingWebIdentityTokenFile.new
|
82
|
+
end
|
83
|
+
File.read(path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def _session_name
|
87
|
+
Base64.strict_encode64(SecureRandom.uuid)
|
88
|
+
end
|
89
|
+
|
90
|
+
class << self
|
91
|
+
|
92
|
+
# @api private
|
93
|
+
def assume_role_web_identity_options
|
94
|
+
@arwio ||= begin
|
95
|
+
input = STS::Client.api.operation(:assume_role_with_web_identity).input
|
96
|
+
Set.new(input.shape.member_names)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Aws
|
2
|
+
module AsyncClientStubs
|
3
|
+
|
4
|
+
include Aws::ClientStubs
|
5
|
+
|
6
|
+
# @api private
|
7
|
+
def setup_stubbing
|
8
|
+
@stubs = {}
|
9
|
+
@stub_mutex = Mutex.new
|
10
|
+
if Hash === @config.stub_responses
|
11
|
+
@config.stub_responses.each do |operation_name, stubs|
|
12
|
+
apply_stubs(operation_name, Array === stubs ? stubs : [stubs])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# When a client is stubbed allow the user to access the requests made
|
17
|
+
@api_requests = []
|
18
|
+
|
19
|
+
# allow to access signaled events when client is stubbed
|
20
|
+
@send_events = []
|
21
|
+
|
22
|
+
requests = @api_requests
|
23
|
+
send_events = @send_events
|
24
|
+
|
25
|
+
self.handle do |context|
|
26
|
+
if input_stream = context[:input_event_stream_handler]
|
27
|
+
stub_stream = StubStream.new
|
28
|
+
stub_stream.send_events = send_events
|
29
|
+
input_stream.event_emitter.stream = stub_stream
|
30
|
+
input_stream.event_emitter.validate_event = context.config.validate_params
|
31
|
+
end
|
32
|
+
requests << {
|
33
|
+
operation_name: context.operation_name,
|
34
|
+
params: context.params,
|
35
|
+
context: context
|
36
|
+
}
|
37
|
+
@handler.call(context)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_events
|
42
|
+
if config.stub_responses
|
43
|
+
@send_events
|
44
|
+
else
|
45
|
+
msg = 'This method is only implemented for stubbed clients, and is '
|
46
|
+
msg << 'available when you enable stubbing in the constructor with `stub_responses: true`'
|
47
|
+
raise NotImplementedError.new(msg)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class StubStream
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@state = :open
|
55
|
+
end
|
56
|
+
|
57
|
+
attr_accessor :send_events
|
58
|
+
|
59
|
+
attr_reader :state
|
60
|
+
|
61
|
+
def data(bytes, options = {})
|
62
|
+
if options[:end_stream]
|
63
|
+
@state = :closed
|
64
|
+
else
|
65
|
+
decoder = Aws::EventStream::Decoder.new
|
66
|
+
event = decoder.decode_chunk(bytes).first
|
67
|
+
@send_events << decoder.decode_chunk(event.payload.read).first
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def closed?
|
72
|
+
@state == :closed
|
73
|
+
end
|
74
|
+
|
75
|
+
def close
|
76
|
+
@state = :closed
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/aws-sdk-core/binary.rb
CHANGED
@@ -23,11 +23,19 @@ module Aws
|
|
23
23
|
|
24
24
|
context.http_response.on_headers(200) do
|
25
25
|
protocol = context.config.api.metadata['protocol']
|
26
|
+
output_handler = context[:output_event_stream_handler] || context[:event_stream_handler]
|
26
27
|
context.http_response.body = EventStreamDecoder.new(
|
27
28
|
protocol,
|
28
29
|
rules,
|
30
|
+
context.operation.output,
|
31
|
+
context.operation.errors,
|
29
32
|
context.http_response.body,
|
30
|
-
|
33
|
+
output_handler)
|
34
|
+
if input_emitter = context[:input_event_emitter]
|
35
|
+
# #emit will be blocked until 200 success
|
36
|
+
# see Aws::EventEmitter#emit
|
37
|
+
input_emitter.signal_queue << "ready"
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
41
|
context.http_response.on_success(200) do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Aws
|
2
|
+
module Binary
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
class EncodeHandler < Seahorse::Client::Handler
|
6
|
+
|
7
|
+
def call(context)
|
8
|
+
if eventstream_member = eventstream_input?(context)
|
9
|
+
input_es_handler = context[:input_event_stream_handler]
|
10
|
+
input_es_handler.event_emitter.encoder = EventStreamEncoder.new(
|
11
|
+
context.config.api.metadata['protocol'],
|
12
|
+
eventstream_member,
|
13
|
+
context.operation.input,
|
14
|
+
context.config.sigv4_signer
|
15
|
+
)
|
16
|
+
context[:input_event_emitter] = input_es_handler.event_emitter
|
17
|
+
end
|
18
|
+
@handler.call(context)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def eventstream_input?(ctx)
|
24
|
+
ctx.operation.input.shape.members.each do |_, ref|
|
25
|
+
return ref if ref.eventstream
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Aws
|
2
|
+
module Binary
|
3
|
+
# @api private
|
4
|
+
class EventBuilder
|
5
|
+
|
6
|
+
include Seahorse::Model::Shapes
|
7
|
+
|
8
|
+
# @param [Class] serializer_class
|
9
|
+
# @param [Seahorse::Model::ShapeRef] rules (of eventstream member)
|
10
|
+
def initialize(serializer_class, rules)
|
11
|
+
@serializer_class = serializer_class
|
12
|
+
@rules = rules
|
13
|
+
end
|
14
|
+
|
15
|
+
def apply(event_type, params)
|
16
|
+
event_ref = @rules.shape.member(event_type)
|
17
|
+
_event_stream_message(event_ref, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def _event_stream_message(event_ref, params)
|
23
|
+
es_headers = {}
|
24
|
+
payload = ""
|
25
|
+
|
26
|
+
es_headers[":message-type"] = Aws::EventStream::HeaderValue.new(
|
27
|
+
type: "string", value: "event")
|
28
|
+
es_headers[":event-type"] = Aws::EventStream::HeaderValue.new(
|
29
|
+
type: "string", value: event_ref.location_name)
|
30
|
+
|
31
|
+
explicit_payload = false
|
32
|
+
implicit_payload_members = {}
|
33
|
+
event_ref.shape.members.each do |member_name, member_ref|
|
34
|
+
unless member_ref.eventheader
|
35
|
+
if member_ref.eventpayload
|
36
|
+
explicit_payload = true
|
37
|
+
else
|
38
|
+
implicit_payload_members[member_name] = member_ref
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# implict payload
|
44
|
+
if !explicit_payload && !implicit_payload_members.empty?
|
45
|
+
if implicit_payload_members.size > 1
|
46
|
+
payload_shape = Shapes::StructureShape.new
|
47
|
+
implicit_payload_members.each do |m_name, m_ref|
|
48
|
+
payload_shape.add_member(m_name, m_ref)
|
49
|
+
end
|
50
|
+
payload_ref = Shapes::ShapeRef.new(shape: payload_shape)
|
51
|
+
|
52
|
+
payload = build_payload_members(payload_ref, params)
|
53
|
+
else
|
54
|
+
m_name, m_ref = implicit_payload_members.first
|
55
|
+
streaming, content_type = _content_type(m_ref.shape)
|
56
|
+
|
57
|
+
es_headers[":content-type"] = Aws::EventStream::HeaderValue.new(
|
58
|
+
type: "string", value: content_type)
|
59
|
+
payload = _build_payload(streaming, m_ref, params[m_name])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
event_ref.shape.members.each do |member_name, member_ref|
|
65
|
+
if member_ref.eventheader && params[member_name]
|
66
|
+
header_value = params[member_name]
|
67
|
+
es_headers[member_ref.shape.name] = Aws::EventStream::HeaderValue.new(
|
68
|
+
type: _header_value_type(member_ref.shape, header_value),
|
69
|
+
value: header_value
|
70
|
+
)
|
71
|
+
elsif member_ref.eventpayload && params[member_name]
|
72
|
+
# explicit payload
|
73
|
+
streaming, content_type = _content_type(member_ref.shape)
|
74
|
+
|
75
|
+
es_headers[":content-type"] = Aws::EventStream::HeaderValue.new(
|
76
|
+
type: "string", value: content_type)
|
77
|
+
payload = _build_payload(streaming, member_ref, params[member_name])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
Aws::EventStream::Message.new(
|
82
|
+
headers: es_headers,
|
83
|
+
payload: StringIO.new(payload)
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
def _content_type(shape)
|
88
|
+
case shape
|
89
|
+
when BlobShape then [true, "application/octet-stream"]
|
90
|
+
when StringShape then [true, "text/plain"]
|
91
|
+
when StructureShape then
|
92
|
+
if @serializer_class.name.include?('Xml')
|
93
|
+
[false, "text/xml"]
|
94
|
+
elsif @serializer_class.name.include?('Json')
|
95
|
+
[false, "application/json"]
|
96
|
+
end
|
97
|
+
else
|
98
|
+
raise Aws::Errors::EventStreamBuilderError.new(
|
99
|
+
"Unsupport eventpayload shape: #{shape.name}")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def _header_value_type(shape, value)
|
104
|
+
case shape
|
105
|
+
when StringShape then "string"
|
106
|
+
when IntegerShape then "integer"
|
107
|
+
when TimestampShape then "timestamp"
|
108
|
+
when BlobShape then "bytes"
|
109
|
+
when BooleanShape then !!value ? "bool_true" : "bool_false"
|
110
|
+
else
|
111
|
+
raise Aws::Errors::EventStreamBuilderError.new(
|
112
|
+
"Unsupported eventheader shape: #{shape.name}")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def _build_payload(streaming, ref, value)
|
117
|
+
streaming ? value : @serializer_class.new(ref).serialize(value)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|