aws-sdk-resources 2.11.632 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/lib/aws-sdk-resources.rb +1 -91
  3. metadata +14 -85
  4. data/lib/aws-sdk-resources/batch.rb +0 -143
  5. data/lib/aws-sdk-resources/builder.rb +0 -85
  6. data/lib/aws-sdk-resources/builder_sources.rb +0 -105
  7. data/lib/aws-sdk-resources/collection.rb +0 -107
  8. data/lib/aws-sdk-resources/definition.rb +0 -331
  9. data/lib/aws-sdk-resources/documenter.rb +0 -70
  10. data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +0 -279
  11. data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +0 -25
  12. data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +0 -69
  13. data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +0 -66
  14. data/lib/aws-sdk-resources/documenter/operation_documenter.rb +0 -20
  15. data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +0 -53
  16. data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +0 -77
  17. data/lib/aws-sdk-resources/errors.rb +0 -15
  18. data/lib/aws-sdk-resources/operation_methods.rb +0 -83
  19. data/lib/aws-sdk-resources/operations.rb +0 -280
  20. data/lib/aws-sdk-resources/options.rb +0 -17
  21. data/lib/aws-sdk-resources/request.rb +0 -39
  22. data/lib/aws-sdk-resources/request_params.rb +0 -140
  23. data/lib/aws-sdk-resources/resource.rb +0 -243
  24. data/lib/aws-sdk-resources/services/ec2.rb +0 -21
  25. data/lib/aws-sdk-resources/services/ec2/instance.rb +0 -29
  26. data/lib/aws-sdk-resources/services/iam.rb +0 -19
  27. data/lib/aws-sdk-resources/services/s3.rb +0 -21
  28. data/lib/aws-sdk-resources/services/s3/bucket.rb +0 -131
  29. data/lib/aws-sdk-resources/services/s3/encryption.rb +0 -24
  30. data/lib/aws-sdk-resources/services/s3/encryption/client.rb +0 -386
  31. data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +0 -225
  32. data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +0 -101
  33. data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +0 -40
  34. data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +0 -61
  35. data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +0 -15
  36. data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +0 -58
  37. data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +0 -37
  38. data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +0 -71
  39. data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +0 -31
  40. data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +0 -104
  41. data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +0 -60
  42. data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +0 -104
  43. data/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb +0 -561
  44. data/lib/aws-sdk-resources/services/s3/encryptionV2/decrypt_handler.rb +0 -214
  45. data/lib/aws-sdk-resources/services/s3/encryptionV2/default_cipher_provider.rb +0 -170
  46. data/lib/aws-sdk-resources/services/s3/encryptionV2/default_key_provider.rb +0 -40
  47. data/lib/aws-sdk-resources/services/s3/encryptionV2/encrypt_handler.rb +0 -69
  48. data/lib/aws-sdk-resources/services/s3/encryptionV2/errors.rb +0 -37
  49. data/lib/aws-sdk-resources/services/s3/encryptionV2/io_auth_decrypter.rb +0 -58
  50. data/lib/aws-sdk-resources/services/s3/encryptionV2/io_decrypter.rb +0 -37
  51. data/lib/aws-sdk-resources/services/s3/encryptionV2/io_encrypter.rb +0 -73
  52. data/lib/aws-sdk-resources/services/s3/encryptionV2/key_provider.rb +0 -31
  53. data/lib/aws-sdk-resources/services/s3/encryptionV2/kms_cipher_provider.rb +0 -169
  54. data/lib/aws-sdk-resources/services/s3/encryptionV2/materials.rb +0 -60
  55. data/lib/aws-sdk-resources/services/s3/encryptionV2/utils.rb +0 -103
  56. data/lib/aws-sdk-resources/services/s3/encryption_v2.rb +0 -24
  57. data/lib/aws-sdk-resources/services/s3/file_downloader.rb +0 -169
  58. data/lib/aws-sdk-resources/services/s3/file_part.rb +0 -75
  59. data/lib/aws-sdk-resources/services/s3/file_uploader.rb +0 -58
  60. data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +0 -187
  61. data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +0 -42
  62. data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +0 -16
  63. data/lib/aws-sdk-resources/services/s3/object.rb +0 -290
  64. data/lib/aws-sdk-resources/services/s3/object_copier.rb +0 -99
  65. data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +0 -180
  66. data/lib/aws-sdk-resources/services/s3/object_summary.rb +0 -73
  67. data/lib/aws-sdk-resources/services/s3/presigned_post.rb +0 -651
  68. data/lib/aws-sdk-resources/services/sns.rb +0 -7
  69. data/lib/aws-sdk-resources/services/sns/message_verifier.rb +0 -171
  70. data/lib/aws-sdk-resources/services/sqs.rb +0 -7
  71. data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +0 -521
  72. data/lib/aws-sdk-resources/source.rb +0 -39
@@ -1,29 +0,0 @@
1
- require 'openssl'
2
-
3
- module Aws
4
- module EC2
5
- class Instance
6
-
7
- # @param [String, Pathname] key_pair_path
8
- # @return [String]
9
- def decrypt_windows_password(key_pair_path)
10
- decoded = Base64.decode64(encrypted_password)
11
- pem_bytes = File.open(key_pair_path, 'rb') { |f| f.read }
12
- private_key = OpenSSL::PKey::RSA.new(pem_bytes)
13
- private_key.private_decrypt(decoded)
14
- end
15
-
16
- private
17
-
18
- def encrypted_password
19
- bytes = client.get_password_data(instance_id: id).password_data
20
- if bytes == ''
21
- raise 'password not available yet'
22
- else
23
- bytes
24
- end
25
- end
26
-
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- module Aws
2
- module IAM
3
- class Resource
4
-
5
- # @return [Seahorse::Client::Response, false] Returns the response
6
- # from {Client#delete_account_alias} if an alias was deleted.
7
- # Returns `false` if this account had no alias to remove.
8
- # @see Client#delete_account_alias
9
- def delete_account_alias
10
- if name = @client.list_account_aliases.account_aliases.first
11
- @client.delete_account_alias(account_alias: name)
12
- else
13
- false
14
- end
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,21 +0,0 @@
1
- module Aws
2
- module S3
3
-
4
- require 'aws-sdk-resources/services/s3/bucket'
5
- require 'aws-sdk-resources/services/s3/object'
6
- require 'aws-sdk-resources/services/s3/object_summary'
7
- require 'aws-sdk-resources/services/s3/multipart_upload'
8
-
9
- autoload :Encryption, 'aws-sdk-resources/services/s3/encryption'
10
- autoload :EncryptionV2, 'aws-sdk-resources/services/s3/encryption_v2'
11
- autoload :FilePart, 'aws-sdk-resources/services/s3/file_part'
12
- autoload :FileUploader, 'aws-sdk-resources/services/s3/file_uploader'
13
- autoload :FileDownloader, 'aws-sdk-resources/services/s3/file_downloader'
14
- autoload :MultipartFileUploader, 'aws-sdk-resources/services/s3/multipart_file_uploader'
15
- autoload :MultipartUploadError, 'aws-sdk-resources/services/s3/multipart_upload_error'
16
- autoload :ObjectCopier, 'aws-sdk-resources/services/s3/object_copier'
17
- autoload :ObjectMultipartCopier, 'aws-sdk-resources/services/s3/object_multipart_copier'
18
- autoload :PresignedPost, 'aws-sdk-resources/services/s3/presigned_post'
19
-
20
- end
21
- end
@@ -1,131 +0,0 @@
1
- require 'uri'
2
-
3
- module Aws
4
- module S3
5
- class Bucket
6
-
7
- # Deletes all objects and versioned objects from this bucket
8
- #
9
- # @example
10
- #
11
- # bucket.clear!
12
- #
13
- # @return [void]
14
- def clear!
15
- object_versions.batch_delete!
16
- end
17
-
18
- # Deletes all objects and versioned objects from this bucket and
19
- # then deletes the bucket.
20
- #
21
- # @example
22
- #
23
- # bucket.delete!
24
- #
25
- # @option options [Integer] :max_attempts (3) Maximum number of times to
26
- # attempt to delete the empty bucket before raising
27
- # `Aws::S3::Errors::BucketNotEmpty`.
28
- #
29
- # @option options [Float] :initial_wait (1.3) Seconds to wait before
30
- # retrying the call to delete the bucket, exponentially increased for
31
- # each attempt.
32
- #
33
- # @return [void]
34
- def delete! options = { }
35
- options = {
36
- initial_wait: 1.3,
37
- max_attempts: 3,
38
- }.merge(options)
39
-
40
- attempts = 0
41
- begin
42
- clear!
43
- delete
44
- rescue Errors::BucketNotEmpty
45
- attempts += 1
46
- if attempts >= options[:max_attempts]
47
- raise
48
- else
49
- Kernel.sleep(options[:initial_wait] ** attempts)
50
- retry
51
- end
52
- end
53
- end
54
-
55
- # Returns a public URL for this bucket.
56
- #
57
- # bucket = s3.bucket('bucket-name')
58
- # bucket.url
59
- # #=> "https://bucket-name.s3.amazonaws.com"
60
- #
61
- # You can pass `virtual_host: true` to use the bucket name as the
62
- # host name.
63
- #
64
- # bucket = s3.bucket('my.bucket.com', virtual_host: true)
65
- # bucket.url
66
- # #=> "http://my.bucket.com"
67
- #
68
- # @option options [Boolean] :virtual_host (false) When `true`,
69
- # the bucket name will be used as the host name. This is useful
70
- # when you have a CNAME configured for this bucket.
71
- #
72
- # @return [String] the URL for this bucket.
73
- def url(options = {})
74
- if options[:virtual_host]
75
- "http://#{name}"
76
- else
77
- s3_bucket_url
78
- end
79
- end
80
-
81
- # Creates a {PresignedPost} that makes it easy to upload a file from
82
- # a web browser direct to Amazon S3 using an HTML post form with
83
- # a file field.
84
- #
85
- # See the {PresignedPost} documentation for more information.
86
- # @note You must specify `:key` or `:key_starts_with`. All other options
87
- # are optional.
88
- # @option (see PresignedPost#initialize)
89
- # @return [PresignedPost]
90
- # @see PresignedPost
91
- def presigned_post(options = {})
92
- PresignedPost.new(
93
- client.config.credentials,
94
- client.config.region,
95
- name,
96
- {url: url}.merge(options)
97
- )
98
- end
99
-
100
- # @api private
101
- def load
102
- @data = client.list_buckets.buckets.find { |b| b.name == name }
103
- raise "unable to load bucket #{name}" if @data.nil?
104
- self
105
- end
106
-
107
- private
108
-
109
- def s3_bucket_url
110
- url = client.config.endpoint.dup
111
- if bucket_as_hostname?(url.scheme == 'https')
112
- url.host = "#{name}.#{url.host}"
113
- else
114
- url.path += '/' unless url.path[-1] == '/'
115
- url.path += Seahorse::Util.uri_escape(name)
116
- end
117
- if (client.config.region == 'us-east-1') &&
118
- (client.config.s3_us_east_1_regional_endpoint == 'legacy')
119
- url.host = Plugins::S3IADRegionalEndpoint.legacy_host(url.host)
120
- end
121
- url.to_s
122
- end
123
-
124
- def bucket_as_hostname?(https)
125
- Plugins::S3BucketDns.dns_compatible?(name, https) &&
126
- !client.config.force_path_style
127
- end
128
-
129
- end
130
- end
131
- end
@@ -1,24 +0,0 @@
1
- module Aws
2
- module S3
3
- module Encryption
4
-
5
- AES_GCM_TAG_LEN_BYTES = 16
6
- EC_USER_AGENT = 'S3CryptoV1n'
7
-
8
- autoload :Client, 'aws-sdk-resources/services/s3/encryption/client'
9
- autoload :DecryptHandler, 'aws-sdk-resources/services/s3/encryption/decrypt_handler'
10
- autoload :DefaultCipherProvider, 'aws-sdk-resources/services/s3/encryption/default_cipher_provider'
11
- autoload :DefaultKeyProvider, 'aws-sdk-resources/services/s3/encryption/default_key_provider'
12
- autoload :EncryptHandler, 'aws-sdk-resources/services/s3/encryption/encrypt_handler'
13
- autoload :Errors, 'aws-sdk-resources/services/s3/encryption/errors'
14
- autoload :IOEncrypter, 'aws-sdk-resources/services/s3/encryption/io_encrypter'
15
- autoload :IOAuthDecrypter, 'aws-sdk-resources/services/s3/encryption/io_auth_decrypter'
16
- autoload :IODecrypter, 'aws-sdk-resources/services/s3/encryption/io_decrypter'
17
- autoload :KeyProvider, 'aws-sdk-resources/services/s3/encryption/key_provider'
18
- autoload :KmsCipherProvider, 'aws-sdk-resources/services/s3/encryption/kms_cipher_provider'
19
- autoload :Materials, 'aws-sdk-resources/services/s3/encryption/materials'
20
- autoload :Utils, 'aws-sdk-resources/services/s3/encryption/utils'
21
-
22
- end
23
- end
24
- end
@@ -1,386 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Aws
6
- module S3
7
-
8
- # [MAINTENANCE MODE] There is a new version of the Encryption Client.
9
- # AWS strongly recommends upgrading to the {Aws::S3::EncryptionV2::Client},
10
- # which provides updated data security best practices.
11
- # See documentation for {Aws::S3::EncryptionV2::Client}.
12
- # Provides an encryption client that encrypts and decrypts data client-side,
13
- # storing the encrypted data in Amazon S3.
14
- #
15
- # This client uses a process called "envelope encryption". Your private
16
- # encryption keys and your data's plain-text are **never** sent to
17
- # Amazon S3. **If you lose you encryption keys, you will not be able to
18
- # decrypt your data.**
19
- #
20
- # ## Envelope Encryption Overview
21
- #
22
- # The goal of envelope encryption is to combine the performance of
23
- # fast symmetric encryption while maintaining the secure key management
24
- # that asymmetric keys provide.
25
- #
26
- # A one-time-use symmetric key (envelope key) is generated client-side.
27
- # This is used to encrypt the data client-side. This key is then
28
- # encrypted by your master key and stored alongside your data in Amazon
29
- # S3.
30
- #
31
- # When accessing your encrypted data with the encryption client,
32
- # the encrypted envelope key is retrieved and decrypted client-side
33
- # with your master key. The envelope key is then used to decrypt the
34
- # data client-side.
35
- #
36
- # One of the benefits of envelope encryption is that if your master key
37
- # is compromised, you have the option of just re-encrypting the stored
38
- # envelope symmetric keys, instead of re-encrypting all of the
39
- # data in your account.
40
- #
41
- # ## Basic Usage
42
- #
43
- # The encryption client requires an {Aws::S3::Client}. If you do not
44
- # provide a `:client`, then a client will be constructed for you.
45
- #
46
- # require 'openssl'
47
- # key = OpenSSL::PKey::RSA.new(1024)
48
- #
49
- # # encryption client
50
- # s3 = Aws::S3::Encryption::Client.new(encryption_key: key)
51
- #
52
- # # round-trip an object, encrypted/decrypted locally
53
- # s3.put_object(bucket:'aws-sdk', key:'secret', body:'handshake')
54
- # s3.get_object(bucket:'aws-sdk', key:'secret').body.read
55
- # #=> 'handshake'
56
- #
57
- # # reading encrypted object without the encryption client
58
- # # results in the getting the cipher text
59
- # Aws::S3::Client.new.get_object(bucket:'aws-sdk', key:'secret').body.read
60
- # #=> "... cipher text ..."
61
- #
62
- # ## Keys
63
- #
64
- # For client-side encryption to work, you must provide one of the following:
65
- #
66
- # * An encryption key
67
- # * A {KeyProvider}
68
- # * A KMS encryption key id
69
- #
70
- # ### An Encryption Key
71
- #
72
- # You can pass a single encryption key. This is used as a master key
73
- # encrypting and decrypting all object keys.
74
- #
75
- # key = OpenSSL::Cipher.new("AES-256-ECB").random_key # symmetric key
76
- # key = OpenSSL::PKey::RSA.new(1024) # asymmetric key pair
77
- #
78
- # s3 = Aws::S3::Encryption::Client.new(encryption_key: key)
79
- #
80
- # ### Key Provider
81
- #
82
- # Alternatively, you can use a {KeyProvider}. A key provider makes
83
- # it easy to work with multiple keys and simplifies key rotation.
84
- #
85
- # ### KMS Encryption Key Id
86
- #
87
- # If you pass the id to an AWS Key Management Service (KMS) key,
88
- # then KMS will be used to generate, encrypt and decrypt object keys.
89
- #
90
- # # keep track of the kms key id
91
- # kms = Aws::KMS::Client.new
92
- # key_id = kms.create_key.key_metadata.key_id
93
- #
94
- # Aws::S3::Encryption::Client.new(
95
- # kms_key_id: key_id,
96
- # kms_client: kms,
97
- # )
98
- #
99
- # ## Custom Key Providers
100
- #
101
- # A {KeyProvider} is any object that responds to:
102
- #
103
- # * `#encryption_materials`
104
- # * `#key_for(materials_description)`
105
- #
106
- # Here is a trivial implementation of an in-memory key provider.
107
- # This is provided as a demonstration of the key provider interface,
108
- # and should not be used in production:
109
- #
110
- # class KeyProvider
111
- #
112
- # def initialize(default_key_name, keys)
113
- # @keys = keys
114
- # @encryption_materials = Aws::S3::Encryption::Materials.new(
115
- # key: @keys[default_key_name],
116
- # description: JSON.dump(key: default_key_name),
117
- # )
118
- # end
119
- #
120
- # attr_reader :encryption_materials
121
- #
122
- # def key_for(matdesc)
123
- # key_name = JSON.load(matdesc)['key']
124
- # if key = @keys[key_name]
125
- # key
126
- # else
127
- # raise "encryption key not found for: #{matdesc.inspect}"
128
- # end
129
- # end
130
- # end
131
- #
132
- # Given the above key provider, you can create an encryption client that
133
- # chooses the key to use based on the materials description stored with
134
- # the encrypted object. This makes it possible to use multiple keys
135
- # and simplifies key rotation.
136
- #
137
- # # uses "new-key" for encrypting objects, uses either for decrypting
138
- # keys = KeyProvider.new('new-key', {
139
- # "old-key" => Base64.decode64("kM5UVbhE/4rtMZJfsadYEdm2vaKFsmV2f5+URSeUCV4="),
140
- # "new-key" => Base64.decode64("w1WLio3agRWRTSJK/Ouh8NHoqRQ6fn5WbSXDTHjXMSo="),
141
- # }),
142
- #
143
- # # chooses the key based on the materials description stored
144
- # # with the encrypted object
145
- # s3 = Aws::S3::Encryption::Client.new(key_provider: keys)
146
- #
147
- # ## Materials Description
148
- #
149
- # A materials description is JSON document string that is stored
150
- # in the metadata (or instruction file) of an encrypted object.
151
- # The {DefaultKeyProvider} uses the empty JSON document `"{}"`.
152
- #
153
- # When building a key provider, you are free to store whatever
154
- # information you need to identify the master key that was used
155
- # to encrypt the object.
156
- #
157
- # ## Envelope Location
158
- #
159
- # By default, the encryption client store the encryption envelope
160
- # with the object, as metadata. You can choose to have the envelope
161
- # stored in a separate "instruction file". An instruction file
162
- # is an object, with the key of the encrypted object, suffixed with
163
- # `".instruction"`.
164
- #
165
- # Specify the `:envelope_location` option as `:instruction_file` to
166
- # use an instruction file for storing the envelope.
167
- #
168
- # # default behavior
169
- # s3 = Aws::S3::Encryption::Client.new(
170
- # key_provider: ...,
171
- # envelope_location: :metadata,
172
- # )
173
- #
174
- # # store envelope in a separate object
175
- # s3 = Aws::S3::Encryption::Client.new(
176
- # key_provider: ...,
177
- # envelope_location: :instruction_file,
178
- # instruction_file_suffix: '.instruction' # default
179
- # )
180
- #
181
- # When using an instruction file, multiple requests are made when
182
- # putting and getting the object. **This may cause issues if you are
183
- # issuing concurrent PUT and GET requests to an encrypted object.**
184
- #
185
- module Encryption
186
- class Client
187
-
188
- extend Deprecations
189
- extend Forwardable
190
- def_delegators :@client, :config, :delete_object, :head_object, :build_request
191
-
192
- # Creates a new encryption client. You must provide one of the following
193
- # options:
194
- #
195
- # * `:encryption_key`
196
- # * `:kms_key_id`
197
- # * `:key_provider`
198
- #
199
- # You may also pass any other options accepted by `Client#initialize`.
200
- #
201
- # @option options [S3::Client] :client A basic S3 client that is used
202
- # to make api calls. If a `:client` is not provided, a new {S3::Client}
203
- # will be constructed.
204
- #
205
- # @option options [OpenSSL::PKey::RSA, String] :encryption_key The master
206
- # key to use for encrypting/decrypting all objects.
207
- #
208
- # @option options [String] :kms_key_id When you provide a `:kms_key_id`,
209
- # then AWS Key Management Service (KMS) will be used to manage the
210
- # object encryption keys. By default a {KMS::Client} will be
211
- # constructed for KMS API calls. Alternatively, you can provide
212
- # your own via `:kms_client`.
213
- #
214
- # @option options [#key_for] :key_provider Any object that responds
215
- # to `#key_for`. This method should accept a materials description
216
- # JSON document string and return return an encryption key.
217
- #
218
- # @option options [Symbol] :envelope_location (:metadata) Where to
219
- # store the envelope encryption keys. By default, the envelope is
220
- # stored with the encrypted object. If you pass `:instruction_file`,
221
- # then the envelope is stored in a separate object in Amazon S3.
222
- #
223
- # @option options [String] :instruction_file_suffix ('.instruction')
224
- # When `:envelope_location` is `:instruction_file` then the
225
- # instruction file uses the object key with this suffix appended.
226
- #
227
- # @option options [KMS::Client] :kms_client A default {KMS::Client}
228
- # is constructed when using KMS to manage encryption keys.
229
- #
230
- def initialize(options = {})
231
- @client = extract_client(options)
232
- @cipher_provider = cipher_provider(options)
233
- @envelope_location = extract_location(options)
234
- @instruction_file_suffix = extract_suffix(options)
235
- end
236
- deprecated :initialize,
237
- message:
238
- '[MAINTENANCE MODE] This version of the S3 Encryption client is currently in maintenance mode. ' \
239
- 'AWS strongly recommends upgrading to the Aws::S3::EncryptionV2::Client, ' \
240
- 'which provides updated data security best practices. ' \
241
- 'See documentation for Aws::S3::EncryptionV2::Client.'
242
-
243
-
244
- # @return [S3::Client]
245
- attr_reader :client
246
-
247
- # @return [KeyProvider, nil] Returns `nil` if you are using
248
- # AWS Key Management Service (KMS).
249
- attr_reader :key_provider
250
-
251
- # @return [Symbol<:metadata, :instruction_file>]
252
- attr_reader :envelope_location
253
-
254
- # @return [String] When {#envelope_location} is `:instruction_file`,
255
- # the envelope is stored in the object with the object key suffixed
256
- # by this string.
257
- attr_reader :instruction_file_suffix
258
-
259
- # Uploads an object to Amazon S3, encrypting data client-side.
260
- # See {S3::Client#put_object} for documentation on accepted
261
- # request parameters.
262
- # @option (see S3::Client#put_object)
263
- # @return (see S3::Client#put_object)
264
- # @see S3::Client#put_object
265
- def put_object(params = {})
266
- req = @client.build_request(:put_object, params)
267
- req.handlers.add(EncryptHandler, priority: 95)
268
- req.context[:encryption] = {
269
- cipher_provider: @cipher_provider,
270
- envelope_location: @envelope_location,
271
- instruction_file_suffix: @instruction_file_suffix,
272
- }
273
- req.send_request
274
- end
275
-
276
- # Gets an object from Amazon S3, decrypting data locally.
277
- # See {S3::Client#get_object} for documentation on accepted
278
- # request parameters.
279
- # @option params [String] :instruction_file_suffix The suffix
280
- # used to find the instruction file containing the encryption
281
- # envelope. You should not set this option when the envelope
282
- # is stored in the object metadata. Defaults to
283
- # {#instruction_file_suffix}.
284
- # @option params [String] :instruction_file_suffix
285
- # @option (see S3::Client#get_object)
286
- # @return (see S3::Client#get_object)
287
- # @see S3::Client#get_object
288
- # @note The `:range` request parameter is not yet supported.
289
- def get_object(params = {}, &block)
290
- if params[:range]
291
- raise NotImplementedError, '#get_object with :range not supported yet'
292
- end
293
- envelope_location, instruction_file_suffix = envelope_options(params)
294
- req = @client.build_request(:get_object, params)
295
- req.handlers.add(DecryptHandler)
296
- req.context[:encryption] = {
297
- cipher_provider: @cipher_provider,
298
- envelope_location: envelope_location,
299
- instruction_file_suffix: instruction_file_suffix,
300
- }
301
- req.send_request(target: block)
302
- end
303
-
304
- private
305
-
306
- def extract_client(options)
307
- options[:client] || begin
308
- options = options.dup
309
- options.delete(:kms_key_id)
310
- options.delete(:kms_client)
311
- options.delete(:key_provider)
312
- options.delete(:encryption_key)
313
- options.delete(:envelope_location)
314
- options.delete(:instruction_file_suffix)
315
- S3::Client.new(options)
316
- end
317
- end
318
-
319
- def kms_client(options)
320
- options[:kms_client] || begin
321
- KMS::Client.new(
322
- region: @client.config.region,
323
- credentials: @client.config.credentials,
324
- )
325
- end
326
- end
327
-
328
- def cipher_provider(options)
329
- if options[:kms_key_id]
330
- KmsCipherProvider.new(
331
- kms_key_id: options[:kms_key_id],
332
- kms_client: kms_client(options),
333
- )
334
- else
335
- # kept here for backwards compatability, {#key_provider} is deprecated
336
- @key_provider = extract_key_provider(options)
337
- DefaultCipherProvider.new(key_provider: @key_provider)
338
- end
339
- end
340
-
341
- def extract_key_provider(options)
342
- if options[:key_provider]
343
- options[:key_provider]
344
- elsif options[:encryption_key]
345
- DefaultKeyProvider.new(options)
346
- else
347
- msg = 'you must pass a :kms_key_id, :key_provider, or :encryption_key'
348
- raise ArgumentError, msg
349
- end
350
- end
351
-
352
- def envelope_options(params)
353
- location = params.delete(:envelope_location) || @envelope_location
354
- suffix = params.delete(:instruction_file_suffix)
355
- if suffix
356
- [:instruction_file, suffix]
357
- else
358
- [location, @instruction_file_suffix]
359
- end
360
- end
361
-
362
- def extract_location(options)
363
- location = options[:envelope_location] || :metadata
364
- if [:metadata, :instruction_file].include?(location)
365
- location
366
- else
367
- msg = ':envelope_location must be :metadata or :instruction_file '\
368
- "got #{location.inspect}"
369
- raise ArgumentError, msg
370
- end
371
- end
372
-
373
- def extract_suffix(options)
374
- suffix = options[:instruction_file_suffix] || '.instruction'
375
- if String === suffix
376
- suffix
377
- else
378
- msg = ':instruction_file_suffix must be a String'
379
- raise ArgumentError, msg
380
- end
381
- end
382
-
383
- end
384
- end
385
- end
386
- end