aws-sdk-resources 2.11.549

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aws-sdk-resources.rb +91 -0
  3. data/lib/aws-sdk-resources/batch.rb +143 -0
  4. data/lib/aws-sdk-resources/builder.rb +85 -0
  5. data/lib/aws-sdk-resources/builder_sources.rb +105 -0
  6. data/lib/aws-sdk-resources/collection.rb +107 -0
  7. data/lib/aws-sdk-resources/definition.rb +331 -0
  8. data/lib/aws-sdk-resources/documenter.rb +70 -0
  9. data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +279 -0
  10. data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +25 -0
  11. data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +69 -0
  12. data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +66 -0
  13. data/lib/aws-sdk-resources/documenter/operation_documenter.rb +20 -0
  14. data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +53 -0
  15. data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +77 -0
  16. data/lib/aws-sdk-resources/errors.rb +15 -0
  17. data/lib/aws-sdk-resources/operation_methods.rb +83 -0
  18. data/lib/aws-sdk-resources/operations.rb +280 -0
  19. data/lib/aws-sdk-resources/options.rb +17 -0
  20. data/lib/aws-sdk-resources/request.rb +39 -0
  21. data/lib/aws-sdk-resources/request_params.rb +140 -0
  22. data/lib/aws-sdk-resources/resource.rb +243 -0
  23. data/lib/aws-sdk-resources/services/ec2.rb +21 -0
  24. data/lib/aws-sdk-resources/services/ec2/instance.rb +29 -0
  25. data/lib/aws-sdk-resources/services/iam.rb +19 -0
  26. data/lib/aws-sdk-resources/services/s3.rb +20 -0
  27. data/lib/aws-sdk-resources/services/s3/bucket.rb +131 -0
  28. data/lib/aws-sdk-resources/services/s3/encryption.rb +21 -0
  29. data/lib/aws-sdk-resources/services/s3/encryption/client.rb +369 -0
  30. data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +174 -0
  31. data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +63 -0
  32. data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +38 -0
  33. data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +50 -0
  34. data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +13 -0
  35. data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +56 -0
  36. data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +29 -0
  37. data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +69 -0
  38. data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +29 -0
  39. data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +71 -0
  40. data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +58 -0
  41. data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +79 -0
  42. data/lib/aws-sdk-resources/services/s3/file_downloader.rb +169 -0
  43. data/lib/aws-sdk-resources/services/s3/file_part.rb +75 -0
  44. data/lib/aws-sdk-resources/services/s3/file_uploader.rb +58 -0
  45. data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +187 -0
  46. data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +42 -0
  47. data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +16 -0
  48. data/lib/aws-sdk-resources/services/s3/object.rb +290 -0
  49. data/lib/aws-sdk-resources/services/s3/object_copier.rb +99 -0
  50. data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +180 -0
  51. data/lib/aws-sdk-resources/services/s3/object_summary.rb +73 -0
  52. data/lib/aws-sdk-resources/services/s3/presigned_post.rb +651 -0
  53. data/lib/aws-sdk-resources/services/sns.rb +7 -0
  54. data/lib/aws-sdk-resources/services/sns/message_verifier.rb +171 -0
  55. data/lib/aws-sdk-resources/services/sqs.rb +7 -0
  56. data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +521 -0
  57. data/lib/aws-sdk-resources/source.rb +39 -0
  58. metadata +118 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c24aca2605287ac2f68422f15fd61da45f9ebacc7449a5fef118df22eb7d8fa7
4
+ data.tar.gz: cf15ec889d63c546e1eab715aa13ef62fc3ea77bd10752546e590428ca2f52a9
5
+ SHA512:
6
+ metadata.gz: 2f61b440ca06fbffc4c2cf82dbb2c202a8f1d9bf86cf1bb49e3e43519cb794645a14c21b7be91fe3626e51e3fb1ffa823053b16ff579ef2b404f2ad442e2fa04
7
+ data.tar.gz: 1d8e32e797be5c217f760fb44a738fe6339a587bca103ec00c4006229aff08a538c23ffb6a4b7342a64afb12b61b2511c86d73534733ce012370f91095632173
@@ -0,0 +1,91 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module Aws
4
+
5
+ module Resources
6
+ autoload :Batch, 'aws-sdk-resources/batch'
7
+ autoload :Builder, 'aws-sdk-resources/builder'
8
+ autoload :BuilderSources, 'aws-sdk-resources/builder_sources'
9
+ autoload :Collection, 'aws-sdk-resources/collection'
10
+ autoload :Definition, 'aws-sdk-resources/definition'
11
+ autoload :Documenter, 'aws-sdk-resources/documenter'
12
+ autoload :Errors, 'aws-sdk-resources/errors'
13
+ autoload :OperationMethods, 'aws-sdk-resources/operation_methods'
14
+ autoload :Operations, 'aws-sdk-resources/operations'
15
+ autoload :Options, 'aws-sdk-resources/options'
16
+ autoload :Request, 'aws-sdk-resources/request'
17
+ autoload :RequestParams, 'aws-sdk-resources/request_params'
18
+ autoload :Resource, 'aws-sdk-resources/resource'
19
+ autoload :Source, 'aws-sdk-resources/source'
20
+ end
21
+
22
+ service_added do |name, svc_module, options|
23
+ definition = options[:resources]
24
+ definition = case definition
25
+ when nil then Resources::Definition.new({})
26
+ when Resources::Definition then definition
27
+ when Hash then Resources::Definition.new(definition)
28
+ when String
29
+ Resources::Definition.new(Json.load_file(definition), source_path: definition)
30
+ else raise ArgumentError, "invalid resource definition #{definition}"
31
+ end
32
+ definition.apply(svc_module)
33
+
34
+ # load customizations
35
+ svc = File.join(
36
+ File.dirname(__FILE__),
37
+ 'aws-sdk-resources',
38
+ 'services',
39
+ "#{name.downcase}.rb")
40
+
41
+ require(svc) if File.exist?(svc)
42
+ end
43
+
44
+ # In version 2.2, all batch resource operations were renamed:
45
+ #
46
+ # * All operations are now prefixed with `batch_`, e.g. `#start`
47
+ # became `#batch_start`.
48
+ #
49
+ # * All batch operations with "delete" or "terminate" in the name
50
+ # are now suffixed with `!`, e.g. `#delete` is now `#batch_delete!`
51
+ #
52
+ # For backwards compatibility, existing batch methods must still respond
53
+ # to their old names. This callback registers these methods with their
54
+ # old names.
55
+ service_added do |name, svc_module, options|
56
+ unless ENV['DOCSTRINGS']
57
+ case name
58
+ when 'EC2'
59
+ {
60
+ 'create_tags' => 'batch_create_tags',
61
+ 'monitor' => 'batch_create_tags',
62
+ 'reboot' => 'batch_reboot',
63
+ 'start' => 'batch_start',
64
+ 'stop' => 'batch_stop',
65
+ 'terminate' => 'batch_terminate!',
66
+ 'unmonitor' => 'batch_unmonitor',
67
+ }.each do |deprecated_name, correct_name|
68
+ Resources::Operations::DeprecatedOperation.define({
69
+ resource_class: EC2::Instance,
70
+ deprecated_name: deprecated_name,
71
+ name: correct_name,
72
+ })
73
+ end
74
+ Resources::Operations::DeprecatedOperation.define({
75
+ resource_class: EC2::Tag,
76
+ deprecated_name: 'delete',
77
+ name: 'batch_delete!',
78
+ })
79
+ when 'S3'
80
+ [S3::Object, S3::ObjectSummary, S3::ObjectVersion].each do |klass|
81
+ Resources::Operations::DeprecatedOperation.define({
82
+ resource_class: klass,
83
+ deprecated_name: 'delete',
84
+ name: 'batch_delete!',
85
+ })
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,143 @@
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
@@ -0,0 +1,85 @@
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
@@ -0,0 +1,105 @@
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
@@ -0,0 +1,107 @@
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