aws-sdk-resources 2.11.412 → 3.67.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aws-v3.rb +201 -0
- data/lib/aws-sdk-resources.rb +221 -87
- metadata +3042 -69
- data/lib/aws-sdk-resources/batch.rb +0 -143
- data/lib/aws-sdk-resources/builder.rb +0 -85
- data/lib/aws-sdk-resources/builder_sources.rb +0 -105
- data/lib/aws-sdk-resources/collection.rb +0 -107
- data/lib/aws-sdk-resources/definition.rb +0 -331
- data/lib/aws-sdk-resources/documenter.rb +0 -70
- data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +0 -279
- data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +0 -25
- data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +0 -69
- data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +0 -66
- data/lib/aws-sdk-resources/documenter/operation_documenter.rb +0 -20
- data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +0 -53
- data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +0 -77
- data/lib/aws-sdk-resources/errors.rb +0 -15
- data/lib/aws-sdk-resources/operation_methods.rb +0 -83
- data/lib/aws-sdk-resources/operations.rb +0 -280
- data/lib/aws-sdk-resources/options.rb +0 -17
- data/lib/aws-sdk-resources/request.rb +0 -39
- data/lib/aws-sdk-resources/request_params.rb +0 -140
- data/lib/aws-sdk-resources/resource.rb +0 -243
- data/lib/aws-sdk-resources/services/ec2.rb +0 -21
- data/lib/aws-sdk-resources/services/ec2/instance.rb +0 -29
- data/lib/aws-sdk-resources/services/iam.rb +0 -19
- data/lib/aws-sdk-resources/services/s3.rb +0 -20
- data/lib/aws-sdk-resources/services/s3/bucket.rb +0 -127
- data/lib/aws-sdk-resources/services/s3/encryption.rb +0 -21
- data/lib/aws-sdk-resources/services/s3/encryption/client.rb +0 -369
- data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +0 -174
- data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +0 -63
- data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +0 -38
- data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +0 -50
- data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +0 -13
- data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +0 -56
- data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +0 -29
- data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +0 -69
- data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +0 -29
- data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +0 -71
- data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +0 -58
- data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +0 -79
- data/lib/aws-sdk-resources/services/s3/file_downloader.rb +0 -169
- data/lib/aws-sdk-resources/services/s3/file_part.rb +0 -75
- data/lib/aws-sdk-resources/services/s3/file_uploader.rb +0 -58
- data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +0 -187
- data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +0 -42
- data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +0 -16
- data/lib/aws-sdk-resources/services/s3/object.rb +0 -290
- data/lib/aws-sdk-resources/services/s3/object_copier.rb +0 -99
- data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +0 -180
- data/lib/aws-sdk-resources/services/s3/object_summary.rb +0 -73
- data/lib/aws-sdk-resources/services/s3/presigned_post.rb +0 -647
- data/lib/aws-sdk-resources/services/sns.rb +0 -7
- data/lib/aws-sdk-resources/services/sns/message_verifier.rb +0 -171
- data/lib/aws-sdk-resources/services/sqs.rb +0 -7
- data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +0 -521
- data/lib/aws-sdk-resources/source.rb +0 -39
@@ -1,143 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
|
4
|
-
# A batch provides array like access to a list of resources. Batches
|
5
|
-
# also provide the ability to invoke certain operations against
|
6
|
-
# the entire batch.
|
7
|
-
#
|
8
|
-
# ## Getting a Batch
|
9
|
-
#
|
10
|
-
# You should normally not need to construct a batch. Anywhere a list
|
11
|
-
# of resources is returned, they are returned as a batch:
|
12
|
-
#
|
13
|
-
# # security_groups is a batch
|
14
|
-
# security_groups = ec2.instance('i-12345678').security_groups
|
15
|
-
#
|
16
|
-
# When the possible number of resources is unknown or large, the
|
17
|
-
# resources will be returned in a collection. Collections can enumerate
|
18
|
-
# individual resources or batches. They manage paging over the
|
19
|
-
# AWS request/responses to produce batches.
|
20
|
-
#
|
21
|
-
# # objects is a collection
|
22
|
-
# objects = s3.bucket('aws-sdk').objects
|
23
|
-
#
|
24
|
-
# You can invoke batch operations against collections and they will
|
25
|
-
# invoke them on each batch.
|
26
|
-
#
|
27
|
-
# # delete all objects in this bucket in batches of 1k
|
28
|
-
# objects = s3.bucket('aws-sdk').objects
|
29
|
-
# objects.delete
|
30
|
-
#
|
31
|
-
# ## Batch Operations
|
32
|
-
#
|
33
|
-
# Batches provide operations that operate on the entire batch. These
|
34
|
-
# operations are only defined for resources where the AWS API accepts
|
35
|
-
# multiple inputs. This means a batch operation for n resources will
|
36
|
-
# only make one request.
|
37
|
-
#
|
38
|
-
# Resource classes document each of their own batch operations.
|
39
|
-
# See {S3::Object} for an example.
|
40
|
-
#
|
41
|
-
class Batch
|
42
|
-
|
43
|
-
include Enumerable
|
44
|
-
|
45
|
-
# @param [Array<Resource>] resources
|
46
|
-
# @option options [Seahorse::Client::Response] :response
|
47
|
-
def initialize(resource_class, resources, options = {})
|
48
|
-
@resource_class = resource_class
|
49
|
-
@resources = resources
|
50
|
-
@response = options[:response]
|
51
|
-
@size = resources.size
|
52
|
-
@options = options
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [Class<Resource>]
|
56
|
-
attr_reader :resource_class
|
57
|
-
|
58
|
-
# @return [Seahorse::Client::Response, nil]
|
59
|
-
attr_reader :response
|
60
|
-
|
61
|
-
# @return [Integer]
|
62
|
-
attr_reader :size
|
63
|
-
|
64
|
-
alias count size
|
65
|
-
|
66
|
-
# @param [Integer] index
|
67
|
-
# @return [Resource]
|
68
|
-
def [](index)
|
69
|
-
@resources[index]
|
70
|
-
end
|
71
|
-
|
72
|
-
# Yields each resource of the batch, one at a time.
|
73
|
-
def each(&block)
|
74
|
-
enum = @resources.to_enum
|
75
|
-
enum.each(&block) if block_given?
|
76
|
-
enum
|
77
|
-
end
|
78
|
-
|
79
|
-
# @param [Integer] count
|
80
|
-
# @return [Resource, Batch]
|
81
|
-
def first(count = nil)
|
82
|
-
if count
|
83
|
-
self.class.new(@resource_class, @resources.first(count), @options)
|
84
|
-
else
|
85
|
-
@resources.first
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# @return [Boolean]
|
90
|
-
def empty?
|
91
|
-
@resources.empty?
|
92
|
-
end
|
93
|
-
|
94
|
-
# @api private
|
95
|
-
def inspect
|
96
|
-
"#<#{self.class.name} resources=#{@resources.inspect}>"
|
97
|
-
end
|
98
|
-
|
99
|
-
# @api private
|
100
|
-
def respond_to?(method_name, *args)
|
101
|
-
if @resource_class.batch_operation_names.include?(method_name.to_sym)
|
102
|
-
true
|
103
|
-
else
|
104
|
-
super
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# @api private
|
109
|
-
def method_missing(method_name, *args, &block)
|
110
|
-
if respond_to?(method_name)
|
111
|
-
invoke_batch_operation(method_name, args, block) unless empty?
|
112
|
-
else
|
113
|
-
super
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
def invoke_batch_operation(method_name, args, block)
|
120
|
-
self.class.validate_batch_args!(args)
|
121
|
-
operation = @resource_class.batch_operation(method_name)
|
122
|
-
operation.call(resource:self, args:args, block:block)
|
123
|
-
end
|
124
|
-
|
125
|
-
class << self
|
126
|
-
|
127
|
-
# @api private
|
128
|
-
def validate_batch_args!(args)
|
129
|
-
case args.count
|
130
|
-
when 0
|
131
|
-
when 1
|
132
|
-
unless Hash === args.first
|
133
|
-
raise ArgumentError, "expected options to be a hash"
|
134
|
-
end
|
135
|
-
else
|
136
|
-
raise ArgumentError, "wrong number of arguments, expected 0 or 1"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
|
4
|
-
# A {Builder} construct resource objects. It extracts resource identifiers
|
5
|
-
# for the objects it builds from another resource object and/or an
|
6
|
-
# AWS response.
|
7
|
-
class Builder
|
8
|
-
|
9
|
-
include Options
|
10
|
-
|
11
|
-
# @option options [required, Class<Resource>] resource_class
|
12
|
-
# @option options [Array<BuilderSources::Source>] :sources ([])
|
13
|
-
def initialize(options = {})
|
14
|
-
@resource_class = options[:resource_class]
|
15
|
-
@sources = options[:sources] || []
|
16
|
-
end
|
17
|
-
|
18
|
-
# @return [Class<Resource>]
|
19
|
-
attr_reader :resource_class
|
20
|
-
|
21
|
-
# @return [Array<BuilderSources::Source>] A list of resource
|
22
|
-
# identifier sources.
|
23
|
-
attr_reader :sources
|
24
|
-
|
25
|
-
# @return [Boolean] Returns `true` if this builder returns an array
|
26
|
-
# of resource objects from {#build}.
|
27
|
-
def plural?
|
28
|
-
@sources.any?(&:plural?)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @option [Resource] :resource
|
32
|
-
# @option [Seahorse::Client::Response] :response
|
33
|
-
# @return [Resource, Array<Resource>] Returns a resource object or an
|
34
|
-
# array of resource objects if {#plural?}.
|
35
|
-
def build(options = {})
|
36
|
-
identifier_map = @sources.each.with_object({}) do |source, hash|
|
37
|
-
hash[source.target] = source.extract(options)
|
38
|
-
end
|
39
|
-
if plural?
|
40
|
-
build_batch(identifier_map, options)
|
41
|
-
else
|
42
|
-
build_one(identifier_map, options)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def build_batch(identifier_map, options, &block)
|
49
|
-
resources = (0...resource_count(identifier_map)).collect do |n|
|
50
|
-
identifiers = @sources.inject({}) do |hash, source|
|
51
|
-
value = identifier_map[source.target]
|
52
|
-
value = value[n] if source.plural?
|
53
|
-
hash[source.target] = value
|
54
|
-
hash
|
55
|
-
end
|
56
|
-
resource = build_one(identifiers, options)
|
57
|
-
yield(resource) if block_given?
|
58
|
-
resource
|
59
|
-
end
|
60
|
-
Batch.new(resource_class, resources, options)
|
61
|
-
end
|
62
|
-
|
63
|
-
def build_one(identifiers, options)
|
64
|
-
if identifiers.count > 0 && identifiers.values.any?(&:nil?)
|
65
|
-
nil
|
66
|
-
else
|
67
|
-
@resource_class.new(identifiers.merge(
|
68
|
-
client: client(options)
|
69
|
-
))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def resource_count(identifier_map)
|
74
|
-
identifier_map.values.inject(0) do |max, values|
|
75
|
-
[max, values.is_a?(Array) ? values.size : 0].max
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def client(options)
|
80
|
-
Array(options[:resource]).first.client
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
module BuilderSources
|
4
|
-
|
5
|
-
module Source
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
@source = options[:source]
|
9
|
-
@target = options[:target].to_sym
|
10
|
-
end
|
11
|
-
|
12
|
-
# @return [String, nil]
|
13
|
-
attr_reader :source
|
14
|
-
|
15
|
-
# @return [Symbol]
|
16
|
-
attr_reader :target
|
17
|
-
|
18
|
-
# @return [Boolean]
|
19
|
-
def plural?
|
20
|
-
!!(@source && @source.include?('['))
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
class Argument
|
26
|
-
|
27
|
-
include Source
|
28
|
-
|
29
|
-
# @option [required, String] :argument
|
30
|
-
def extract(options)
|
31
|
-
(options[:args] || [])[@source]
|
32
|
-
end
|
33
|
-
|
34
|
-
def plural?
|
35
|
-
false
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
# Extracts an identifier from a parent resource identifier. Used
|
41
|
-
# when building a {Resource} from the context of another resource.
|
42
|
-
class Identifier
|
43
|
-
|
44
|
-
include Source
|
45
|
-
|
46
|
-
# @option [required, Resource] :resource
|
47
|
-
def extract(options)
|
48
|
-
options[:resource].send(@source)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
# Extracts an identifier from the data of a parent resource. Used
|
54
|
-
# when building a {Resource} from the context of another resource.
|
55
|
-
class DataMember
|
56
|
-
|
57
|
-
include Source
|
58
|
-
|
59
|
-
# @option [required, Resource] :resource
|
60
|
-
def extract(options)
|
61
|
-
JMESPath.search(@source, options[:resource].data)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
# Extracts an identifier from the request parameters used to generate
|
67
|
-
# a response. Used when building a {Resource} object from the response
|
68
|
-
# of an operation.
|
69
|
-
class RequestParameter
|
70
|
-
|
71
|
-
include Source
|
72
|
-
|
73
|
-
# @option [required, Seahorse::Client::Response] :response
|
74
|
-
def extract(options)
|
75
|
-
JMESPath.search(@source, options[:response].context.params)
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
# Extracts an identifier from the data of a response. Used when
|
81
|
-
# building a {Resource} object from the response of an operation.
|
82
|
-
class ResponsePath
|
83
|
-
|
84
|
-
include Source
|
85
|
-
|
86
|
-
# @option [required, Seahorse::Client::Response] :response
|
87
|
-
def extract(options)
|
88
|
-
JMESPath.search(@source, options[:response].data)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
# Supplies a string literal.
|
94
|
-
class StringLiteral
|
95
|
-
|
96
|
-
include Source
|
97
|
-
|
98
|
-
def extract(options)
|
99
|
-
@source
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
class Collection
|
4
|
-
|
5
|
-
include Enumerable
|
6
|
-
|
7
|
-
# @param [HasManyOperation] operation
|
8
|
-
# @option (see HasManyOperation#call)
|
9
|
-
# @api private
|
10
|
-
def initialize(operation, options)
|
11
|
-
@operation = operation
|
12
|
-
@options = options
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [Enumerator<Resource>]
|
16
|
-
def each(&block)
|
17
|
-
if block_given?
|
18
|
-
batches.each { |batch| batch.each(&block) }
|
19
|
-
else
|
20
|
-
self
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# @api private
|
25
|
-
# @return [Enumerator<Batch>]
|
26
|
-
def batches(&block)
|
27
|
-
@operation.batches(@options)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Specifies the maximum number of items to enumerate.
|
31
|
-
#
|
32
|
-
# collection.limit(10).each do |resource|
|
33
|
-
# # yields at most 10 times
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# @param [Integer] limit The maximum number of items to yield
|
37
|
-
# via {#each} or {#batches}.
|
38
|
-
# @return [Collection]
|
39
|
-
def limit(limit)
|
40
|
-
self.class.new(@operation, @options.merge(limit: limit))
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns the first resource from the collection.
|
44
|
-
#
|
45
|
-
# resource = collection.first
|
46
|
-
#
|
47
|
-
# If you pass a count, then the first `count` resources are returned in
|
48
|
-
# a single batch. See the resource specific batch documentation for
|
49
|
-
# a list of supported batch methods.
|
50
|
-
#
|
51
|
-
# resources = collection.first(10)
|
52
|
-
# resources.delete
|
53
|
-
#
|
54
|
-
# @return [Resource, Batch]
|
55
|
-
def first(count = 1)
|
56
|
-
if count == 1
|
57
|
-
limit(1).to_a.first
|
58
|
-
else
|
59
|
-
Batch.new(resource_class, limit(count).to_a)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# @api private
|
64
|
-
def respond_to?(method_name, *args)
|
65
|
-
if resource_class.batch_operation_names.include?(method_name.to_sym)
|
66
|
-
true
|
67
|
-
else
|
68
|
-
super
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# @api private
|
73
|
-
def method_missing(method_name, *args, &block)
|
74
|
-
if respond_to?(method_name)
|
75
|
-
Batch.validate_batch_args!(args)
|
76
|
-
batches.each do |batch|
|
77
|
-
batch.send(method_name, *args, &block)
|
78
|
-
end
|
79
|
-
else
|
80
|
-
super
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# @api private
|
85
|
-
def inspect
|
86
|
-
parts = {}
|
87
|
-
parts[:type] = resource_class.name
|
88
|
-
parts[:limit] = @options[:limit]
|
89
|
-
parts[:params] = @options[:params] || {}
|
90
|
-
parts = parts.inject("") {|s,(k,v)| s << " #{k}=#{v.inspect}" }
|
91
|
-
['#<', self.class.name, parts, '>'].join
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
# @api private
|
97
|
-
def limit_key
|
98
|
-
@operation.limit_key
|
99
|
-
end
|
100
|
-
|
101
|
-
def resource_class
|
102
|
-
@operation.builder.resource_class
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,331 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
module Resources
|
5
|
-
|
6
|
-
# Given a resource definition document, a {Definition} can build a set
|
7
|
-
# of related resource classes.
|
8
|
-
class Definition
|
9
|
-
|
10
|
-
# @param [Hash] definition
|
11
|
-
# @option options [String] :source_path
|
12
|
-
def initialize(definition = {}, options = {})
|
13
|
-
@source = definition
|
14
|
-
@source_path = options[:source_path]
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [Module<Service>] namespace
|
18
|
-
# @return [void]
|
19
|
-
def apply(namespace)
|
20
|
-
build_resource_classes(namespace)
|
21
|
-
each_resource_class(namespace) do |resource, definition|
|
22
|
-
define_load(namespace, resource, definition['load'])
|
23
|
-
define_actions(namespace, resource, definition['actions'] || {})
|
24
|
-
define_batch_actions(namespace, resource, definition['batchActions'] || {})
|
25
|
-
define_waiters(namespace, resource, definition['waiters'] || {})
|
26
|
-
define_has(namespace, resource, definition['has'] || {})
|
27
|
-
define_has_many(namespace, resource, definition['hasMany'] || {})
|
28
|
-
define_data_attributes(namespace, resource, definition)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def build_resource_classes(namespace)
|
35
|
-
each_definition do |name, definition|
|
36
|
-
resource_class = Class.new(Resource)
|
37
|
-
resource_class.client_class = namespace::Client
|
38
|
-
resource_class.resource_name = name
|
39
|
-
(definition['identifiers'] || []).each do |identifier|
|
40
|
-
resource_class.add_identifier(underscore(identifier['name']))
|
41
|
-
end
|
42
|
-
namespace.const_set(name, resource_class)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def each_resource_class(namespace, &block)
|
47
|
-
each_definition do |name, definition|
|
48
|
-
yield(namespace.const_get(name), definition)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def define_batch_actions(namespace, resource, batch_actions)
|
53
|
-
batch_actions.each do |name, definition|
|
54
|
-
method_name = "batch_" + underscore(name)
|
55
|
-
method_name += '!' if dangerous?(name, definition)
|
56
|
-
operation = build_operation(namespace, resource, definition)
|
57
|
-
resource.add_batch_operation(method_name, operation)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def dangerous?(name, definition)
|
62
|
-
if
|
63
|
-
name.match(/delete/i) ||
|
64
|
-
name.match(/terminate/i) ||
|
65
|
-
definition['request']['operation'].match(/delete/i) ||
|
66
|
-
definition['request']['operation'].match(/terminate/i)
|
67
|
-
then
|
68
|
-
true
|
69
|
-
else
|
70
|
-
false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def define_data_attributes(namespace, resource, definition)
|
75
|
-
if shape_name = definition['shape']
|
76
|
-
shape = resource.client_class.api.metadata['shapes'][shape_name]
|
77
|
-
shape.member_names.each do |member_name|
|
78
|
-
if
|
79
|
-
resource.instance_methods.include?(member_name) ||
|
80
|
-
data_attribute_is_an_identifier?(member_name, resource, definition)
|
81
|
-
then
|
82
|
-
next # some data attributes are duplicates to identifiers
|
83
|
-
else
|
84
|
-
resource.add_data_attribute(member_name)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def data_attribute_is_an_identifier?(attr_name, resource, definition)
|
91
|
-
resource.identifiers.include?(attr_name) ||
|
92
|
-
definition['identifiers'].any? { |i| underscore(i['dataMember']) == attr_name.to_s }
|
93
|
-
end
|
94
|
-
|
95
|
-
def define_load(namespace, resource, definition)
|
96
|
-
return unless definition
|
97
|
-
resource.load_operation = Operations::LoadOperation.new(
|
98
|
-
request: define_request(definition['request']),
|
99
|
-
path: underscore(definition['path']),
|
100
|
-
source: source(definition),
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
def define_actions(namespace, resource, actions)
|
105
|
-
actions.each do |name, action|
|
106
|
-
operation = build_operation(namespace, resource, action)
|
107
|
-
resource.add_operation(underscore(name), operation)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def define_waiters(namespace, resource, waiters)
|
112
|
-
waiters.each do |name, definition|
|
113
|
-
operation = build_waiter_operation(namespace, resource, definition)
|
114
|
-
resource.add_operation("wait_until_#{underscore(name)}", operation)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def build_operation(namespace, resource, definition)
|
119
|
-
if definition['resource']
|
120
|
-
build_resource_action(namespace, resource, definition)
|
121
|
-
else
|
122
|
-
build_basic_action(namespace, resource, definition)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def build_basic_action(namespace, resource, definition)
|
127
|
-
Operations::Operation.new(
|
128
|
-
request: define_request(definition['request']),
|
129
|
-
source: source(definition)
|
130
|
-
)
|
131
|
-
end
|
132
|
-
|
133
|
-
def build_resource_action(namespace, resource, definition)
|
134
|
-
builder = define_builder(namespace, definition['resource'])
|
135
|
-
if path = definition['resource']['path']
|
136
|
-
builder.sources << BuilderSources::ResponsePath.new({
|
137
|
-
source: underscore(path),
|
138
|
-
target: :data,
|
139
|
-
})
|
140
|
-
end
|
141
|
-
Operations::ResourceOperation.new(
|
142
|
-
request: define_request(definition['request']),
|
143
|
-
builder: builder,
|
144
|
-
source: source(definition)
|
145
|
-
)
|
146
|
-
end
|
147
|
-
|
148
|
-
def has_many(namespace, resource, definition)
|
149
|
-
builder = define_builder(namespace, definition['resource'])
|
150
|
-
if path = definition['resource']['path']
|
151
|
-
builder.sources << BuilderSources::ResponsePath.new({
|
152
|
-
source: underscore(path),
|
153
|
-
target: :data,
|
154
|
-
})
|
155
|
-
end
|
156
|
-
Operations::HasManyOperation.new(
|
157
|
-
request: define_request(definition['request']),
|
158
|
-
builder: builder,
|
159
|
-
source: source(definition),
|
160
|
-
limit_key: limit_key(resource, definition))
|
161
|
-
end
|
162
|
-
|
163
|
-
def build_waiter_operation(namespace, resource, definition)
|
164
|
-
Operations::WaiterOperation.new(
|
165
|
-
waiter_name: underscore(definition['waiterName']).to_sym,
|
166
|
-
waiter_params: request_params(definition['params']),
|
167
|
-
path: underscore(definition['path'])
|
168
|
-
)
|
169
|
-
end
|
170
|
-
|
171
|
-
def limit_key(resource, definition)
|
172
|
-
operation_name = definition['request']['operation']
|
173
|
-
operation = resource.client_class.api.operation(underscore(operation_name))
|
174
|
-
if operation[:pager]
|
175
|
-
operation[:pager].limit_key
|
176
|
-
else
|
177
|
-
nil
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def define_request(definition)
|
182
|
-
Request.new(
|
183
|
-
method_name: underscore(definition['operation']),
|
184
|
-
params: request_params(definition['params'] || [])
|
185
|
-
)
|
186
|
-
end
|
187
|
-
|
188
|
-
def request_params(params)
|
189
|
-
params.map do |definition|
|
190
|
-
send("#{definition['source']}_request_param", definition)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def identifier_request_param(definition)
|
195
|
-
RequestParams::Identifier.new({
|
196
|
-
target: underscore(definition['target']),
|
197
|
-
name: underscore(definition['name']).to_sym,
|
198
|
-
})
|
199
|
-
end
|
200
|
-
|
201
|
-
def data_request_param(definition)
|
202
|
-
RequestParams::DataMember.new({
|
203
|
-
target: underscore(definition['target']),
|
204
|
-
path: underscore(definition['path']),
|
205
|
-
})
|
206
|
-
end
|
207
|
-
|
208
|
-
def string_request_param(definition)
|
209
|
-
RequestParams::Literal.new({
|
210
|
-
target: underscore(definition['target']),
|
211
|
-
value: definition['value'],
|
212
|
-
})
|
213
|
-
end
|
214
|
-
alias integer_request_param string_request_param
|
215
|
-
alias float_request_param string_request_param
|
216
|
-
alias boolean_request_param string_request_param
|
217
|
-
alias null_request_param string_request_param
|
218
|
-
|
219
|
-
def define_has_many(namespace, resource, has_many)
|
220
|
-
has_many.each do |name, definition|
|
221
|
-
operation = has_many(namespace, resource, definition)
|
222
|
-
resource.add_operation(underscore(name), operation)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def define_has(namespace, resource, has)
|
227
|
-
has.each do |name, definition|
|
228
|
-
has_operation(namespace, resource, name, definition)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def has_operation(namespace, resource, name, definition)
|
233
|
-
builder = define_builder(namespace, definition['resource'])
|
234
|
-
if path = definition['resource']['path']
|
235
|
-
builder.sources << BuilderSources::DataMember.new({
|
236
|
-
source: underscore(path),
|
237
|
-
target: :data,
|
238
|
-
})
|
239
|
-
end
|
240
|
-
operation = Operations::HasOperation.new(
|
241
|
-
builder: builder,
|
242
|
-
source: source(definition))
|
243
|
-
resource.add_operation(underscore(name), operation)
|
244
|
-
end
|
245
|
-
|
246
|
-
def define_builder(namespace, definition)
|
247
|
-
Builder.new(
|
248
|
-
resource_class: namespace.const_get(definition['type']),
|
249
|
-
sources: builder_sources(definition['identifiers'] || [])
|
250
|
-
)
|
251
|
-
end
|
252
|
-
|
253
|
-
def builder_sources(sources)
|
254
|
-
sources.map do |definition|
|
255
|
-
send("#{definition['source']}_builder_source", definition, sources)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
def input_builder_source(definition, sources)
|
260
|
-
arguments = sources.select { |s| s['source'] == 'input' }
|
261
|
-
BuilderSources::Argument.new({
|
262
|
-
source: arguments.index(definition),
|
263
|
-
target: underscore(definition['target']),
|
264
|
-
})
|
265
|
-
end
|
266
|
-
|
267
|
-
def identifier_builder_source(definition, _)
|
268
|
-
BuilderSources::Identifier.new({
|
269
|
-
source: underscore(definition['name']),
|
270
|
-
target: underscore(definition['target']),
|
271
|
-
})
|
272
|
-
end
|
273
|
-
|
274
|
-
def data_builder_source(definition, _)
|
275
|
-
BuilderSources::DataMember.new({
|
276
|
-
source: underscore(definition['path']),
|
277
|
-
target: underscore(definition['target']),
|
278
|
-
})
|
279
|
-
end
|
280
|
-
|
281
|
-
def requestParameter_builder_source(definition, _)
|
282
|
-
BuilderSources::RequestParameter.new({
|
283
|
-
source: underscore(definition['path']),
|
284
|
-
target: underscore(definition['target']),
|
285
|
-
})
|
286
|
-
end
|
287
|
-
|
288
|
-
def response_builder_source(definition, _)
|
289
|
-
BuilderSources::ResponsePath.new({
|
290
|
-
source: underscore(definition['path']),
|
291
|
-
target: underscore(definition['target']),
|
292
|
-
})
|
293
|
-
end
|
294
|
-
|
295
|
-
def string_builder_source(definition, _)
|
296
|
-
BuilderSources::ResponsePath.new({
|
297
|
-
source: underscore(definition['value']),
|
298
|
-
target: underscore(definition['target']),
|
299
|
-
})
|
300
|
-
end
|
301
|
-
|
302
|
-
def svc_definition
|
303
|
-
@source['service'] || {}
|
304
|
-
end
|
305
|
-
|
306
|
-
def resource_definitions
|
307
|
-
@source['resources'] || {}
|
308
|
-
end
|
309
|
-
|
310
|
-
def each_definition(&block)
|
311
|
-
yield('Resource', svc_definition)
|
312
|
-
resource_definitions.each(&block)
|
313
|
-
end
|
314
|
-
|
315
|
-
def underscore(str)
|
316
|
-
if str
|
317
|
-
str.gsub(/\w+/) { |part| Seahorse::Util.underscore(part) }
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
def source(definition)
|
322
|
-
if ENV['SOURCE']
|
323
|
-
Source.new(definition, @source_path)
|
324
|
-
else
|
325
|
-
nil
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|