aws-sdk-s3 1.75.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/aws-sdk-s3.rb +73 -0
- data/lib/aws-sdk-s3/bucket.rb +861 -0
- data/lib/aws-sdk-s3/bucket_acl.rb +277 -0
- data/lib/aws-sdk-s3/bucket_cors.rb +262 -0
- data/lib/aws-sdk-s3/bucket_lifecycle.rb +264 -0
- data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +283 -0
- data/lib/aws-sdk-s3/bucket_logging.rb +251 -0
- data/lib/aws-sdk-s3/bucket_notification.rb +293 -0
- data/lib/aws-sdk-s3/bucket_policy.rb +242 -0
- data/lib/aws-sdk-s3/bucket_region_cache.rb +81 -0
- data/lib/aws-sdk-s3/bucket_request_payment.rb +236 -0
- data/lib/aws-sdk-s3/bucket_tagging.rb +251 -0
- data/lib/aws-sdk-s3/bucket_versioning.rb +312 -0
- data/lib/aws-sdk-s3/bucket_website.rb +292 -0
- data/lib/aws-sdk-s3/client.rb +11818 -0
- data/lib/aws-sdk-s3/client_api.rb +3014 -0
- data/lib/aws-sdk-s3/customizations.rb +34 -0
- data/lib/aws-sdk-s3/customizations/bucket.rb +162 -0
- data/lib/aws-sdk-s3/customizations/multipart_upload.rb +44 -0
- data/lib/aws-sdk-s3/customizations/object.rb +389 -0
- data/lib/aws-sdk-s3/customizations/object_summary.rb +85 -0
- data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +13 -0
- data/lib/aws-sdk-s3/encryption.rb +21 -0
- data/lib/aws-sdk-s3/encryption/client.rb +375 -0
- data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +190 -0
- data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +65 -0
- data/lib/aws-sdk-s3/encryption/default_key_provider.rb +40 -0
- data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +61 -0
- data/lib/aws-sdk-s3/encryption/errors.rb +15 -0
- data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +58 -0
- data/lib/aws-sdk-s3/encryption/io_decrypter.rb +36 -0
- data/lib/aws-sdk-s3/encryption/io_encrypter.rb +71 -0
- data/lib/aws-sdk-s3/encryption/key_provider.rb +31 -0
- data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +75 -0
- data/lib/aws-sdk-s3/encryption/materials.rb +60 -0
- data/lib/aws-sdk-s3/encryption/utils.rb +81 -0
- data/lib/aws-sdk-s3/encryptionV2/client.rb +388 -0
- data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +198 -0
- data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +103 -0
- data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +38 -0
- data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +66 -0
- data/lib/aws-sdk-s3/encryptionV2/errors.rb +13 -0
- data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +56 -0
- data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +35 -0
- data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +71 -0
- data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +29 -0
- data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +99 -0
- data/lib/aws-sdk-s3/encryptionV2/materials.rb +58 -0
- data/lib/aws-sdk-s3/encryptionV2/utils.rb +116 -0
- data/lib/aws-sdk-s3/encryption_v2.rb +20 -0
- data/lib/aws-sdk-s3/errors.rb +115 -0
- data/lib/aws-sdk-s3/event_streams.rb +69 -0
- data/lib/aws-sdk-s3/file_downloader.rb +142 -0
- data/lib/aws-sdk-s3/file_part.rb +78 -0
- data/lib/aws-sdk-s3/file_uploader.rb +70 -0
- data/lib/aws-sdk-s3/legacy_signer.rb +189 -0
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +227 -0
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +173 -0
- data/lib/aws-sdk-s3/multipart_upload.rb +401 -0
- data/lib/aws-sdk-s3/multipart_upload_error.rb +18 -0
- data/lib/aws-sdk-s3/multipart_upload_part.rb +423 -0
- data/lib/aws-sdk-s3/object.rb +1422 -0
- data/lib/aws-sdk-s3/object_acl.rb +333 -0
- data/lib/aws-sdk-s3/object_copier.rb +101 -0
- data/lib/aws-sdk-s3/object_multipart_copier.rb +182 -0
- data/lib/aws-sdk-s3/object_summary.rb +1181 -0
- data/lib/aws-sdk-s3/object_version.rb +550 -0
- data/lib/aws-sdk-s3/plugins/accelerate.rb +87 -0
- data/lib/aws-sdk-s3/plugins/bucket_arn.rb +212 -0
- data/lib/aws-sdk-s3/plugins/bucket_dns.rb +91 -0
- data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +45 -0
- data/lib/aws-sdk-s3/plugins/dualstack.rb +74 -0
- data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +28 -0
- data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +25 -0
- data/lib/aws-sdk-s3/plugins/http_200_errors.rb +55 -0
- data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +62 -0
- data/lib/aws-sdk-s3/plugins/location_constraint.rb +35 -0
- data/lib/aws-sdk-s3/plugins/md5s.rb +84 -0
- data/lib/aws-sdk-s3/plugins/redirects.rb +45 -0
- data/lib/aws-sdk-s3/plugins/s3_host_id.rb +30 -0
- data/lib/aws-sdk-s3/plugins/s3_signer.rb +222 -0
- data/lib/aws-sdk-s3/plugins/sse_cpk.rb +70 -0
- data/lib/aws-sdk-s3/plugins/streaming_retry.rb +118 -0
- data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +97 -0
- data/lib/aws-sdk-s3/presigned_post.rb +686 -0
- data/lib/aws-sdk-s3/presigner.rb +253 -0
- data/lib/aws-sdk-s3/resource.rb +117 -0
- data/lib/aws-sdk-s3/types.rb +13154 -0
- data/lib/aws-sdk-s3/waiters.rb +243 -0
- metadata +184 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module S3
|
5
|
+
class ObjectSummary
|
6
|
+
|
7
|
+
alias content_length size
|
8
|
+
|
9
|
+
# Make the method redefinable
|
10
|
+
alias_method :copy_from, :copy_from
|
11
|
+
|
12
|
+
# @param (see Object#copy_from)
|
13
|
+
# @options (see Object#copy_from)
|
14
|
+
# @return (see Object#copy_from)
|
15
|
+
# @see Object#copy_from
|
16
|
+
def copy_from(source, options = {})
|
17
|
+
object.copy_from(source, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param (see Object#copy_to)
|
21
|
+
# @options (see Object#copy_to)
|
22
|
+
# @return (see Object#copy_to)
|
23
|
+
# @see Object#copy_to
|
24
|
+
def copy_to(target, options = {})
|
25
|
+
object.copy_to(target, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param (see Object#move_to)
|
29
|
+
# @options (see Object#move_to)
|
30
|
+
# @return (see Object#move_to)
|
31
|
+
# @see Object#move_to
|
32
|
+
def move_to(target, options = {})
|
33
|
+
object.move_to(target, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param (see Object#presigned_post)
|
37
|
+
# @options (see Object#presigned_post)
|
38
|
+
# @return (see Object#presigned_post)
|
39
|
+
# @see Object#presigned_post
|
40
|
+
def presigned_post(options = {})
|
41
|
+
object.presigned_post(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param (see Object#presigned_url)
|
45
|
+
# @options (see Object#presigned_url)
|
46
|
+
# @return (see Object#presigned_url)
|
47
|
+
# @see Object#presigned_url
|
48
|
+
def presigned_url(http_method, params = {})
|
49
|
+
object.presigned_url(http_method, params)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param (see Object#public_url)
|
53
|
+
# @options (see Object#public_url)
|
54
|
+
# @return (see Object#public_url)
|
55
|
+
# @see Object#public_url
|
56
|
+
def public_url(options = {})
|
57
|
+
object.public_url(options)
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param (see Object#upload_file)
|
61
|
+
# @options (see Object#upload_file)
|
62
|
+
# @return (see Object#upload_file)
|
63
|
+
# @see Object#upload_file
|
64
|
+
def upload_file(source, options = {})
|
65
|
+
object.upload_file(source, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
# @options (see Object#upload_stream)
|
69
|
+
# @return (see Object#upload_stream)
|
70
|
+
# @see Object#upload_stream
|
71
|
+
def upload_stream(options = {}, &block)
|
72
|
+
object.upload_stream(options, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param (see Object#download_file)
|
76
|
+
# @options (see Object#download_file)
|
77
|
+
# @return (see Object#download_file)
|
78
|
+
# @see Object#download_file
|
79
|
+
def download_file(destination, options = {})
|
80
|
+
object.download_file(destination, options)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Aws::S3::Types::ListObjectVersionsOutput
|
4
|
+
|
5
|
+
# TODO : Remove this customization once the resource code
|
6
|
+
# generator correct handles the JMESPath || expression.
|
7
|
+
# Only used by the Bucket#object_versions collection.
|
8
|
+
# @api private
|
9
|
+
def versions_delete_markers
|
10
|
+
versions + delete_markers
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-s3/encryption/client'
|
4
|
+
require 'aws-sdk-s3/encryption/decrypt_handler'
|
5
|
+
require 'aws-sdk-s3/encryption/default_cipher_provider'
|
6
|
+
require 'aws-sdk-s3/encryption/encrypt_handler'
|
7
|
+
require 'aws-sdk-s3/encryption/errors'
|
8
|
+
require 'aws-sdk-s3/encryption/io_encrypter'
|
9
|
+
require 'aws-sdk-s3/encryption/io_decrypter'
|
10
|
+
require 'aws-sdk-s3/encryption/io_auth_decrypter'
|
11
|
+
require 'aws-sdk-s3/encryption/key_provider'
|
12
|
+
require 'aws-sdk-s3/encryption/kms_cipher_provider'
|
13
|
+
require 'aws-sdk-s3/encryption/materials'
|
14
|
+
require 'aws-sdk-s3/encryption/utils'
|
15
|
+
require 'aws-sdk-s3/encryption/default_key_provider'
|
16
|
+
|
17
|
+
module Aws
|
18
|
+
module S3
|
19
|
+
module Encryption; end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,375 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module S3
|
7
|
+
|
8
|
+
# Provides an encryption client that encrypts and decrypts data client-side,
|
9
|
+
# storing the encrypted data in Amazon S3.
|
10
|
+
#
|
11
|
+
# This client uses a process called "envelope encryption". Your private
|
12
|
+
# encryption keys and your data's plain-text are **never** sent to
|
13
|
+
# Amazon S3. **If you lose you encryption keys, you will not be able to
|
14
|
+
# decrypt your data.**
|
15
|
+
#
|
16
|
+
# ## Envelope Encryption Overview
|
17
|
+
#
|
18
|
+
# The goal of envelope encryption is to combine the performance of
|
19
|
+
# fast symmetric encryption while maintaining the secure key management
|
20
|
+
# that asymmetric keys provide.
|
21
|
+
#
|
22
|
+
# A one-time-use symmetric key (envelope key) is generated client-side.
|
23
|
+
# This is used to encrypt the data client-side. This key is then
|
24
|
+
# encrypted by your master key and stored alongside your data in Amazon
|
25
|
+
# S3.
|
26
|
+
#
|
27
|
+
# When accessing your encrypted data with the encryption client,
|
28
|
+
# the encrypted envelope key is retrieved and decrypted client-side
|
29
|
+
# with your master key. The envelope key is then used to decrypt the
|
30
|
+
# data client-side.
|
31
|
+
#
|
32
|
+
# One of the benefits of envelope encryption is that if your master key
|
33
|
+
# is compromised, you have the option of just re-encrypting the stored
|
34
|
+
# envelope symmetric keys, instead of re-encrypting all of the
|
35
|
+
# data in your account.
|
36
|
+
#
|
37
|
+
# ## Basic Usage
|
38
|
+
#
|
39
|
+
# The encryption client requires an {Aws::S3::Client}. If you do not
|
40
|
+
# provide a `:client`, then a client will be constructed for you.
|
41
|
+
#
|
42
|
+
# require 'openssl'
|
43
|
+
# key = OpenSSL::PKey::RSA.new(1024)
|
44
|
+
#
|
45
|
+
# # encryption client
|
46
|
+
# s3 = Aws::S3::Encryption::Client.new(encryption_key: key)
|
47
|
+
#
|
48
|
+
# # round-trip an object, encrypted/decrypted locally
|
49
|
+
# s3.put_object(bucket:'aws-sdk', key:'secret', body:'handshake')
|
50
|
+
# s3.get_object(bucket:'aws-sdk', key:'secret').body.read
|
51
|
+
# #=> 'handshake'
|
52
|
+
#
|
53
|
+
# # reading encrypted object without the encryption client
|
54
|
+
# # results in the getting the cipher text
|
55
|
+
# Aws::S3::Client.new.get_object(bucket:'aws-sdk', key:'secret').body.read
|
56
|
+
# #=> "... cipher text ..."
|
57
|
+
#
|
58
|
+
# ## Keys
|
59
|
+
#
|
60
|
+
# For client-side encryption to work, you must provide one of the following:
|
61
|
+
#
|
62
|
+
# * An encryption key
|
63
|
+
# * A {KeyProvider}
|
64
|
+
# * A KMS encryption key id
|
65
|
+
#
|
66
|
+
# ### An Encryption Key
|
67
|
+
#
|
68
|
+
# You can pass a single encryption key. This is used as a master key
|
69
|
+
# encrypting and decrypting all object keys.
|
70
|
+
#
|
71
|
+
# key = OpenSSL::Cipher.new("AES-256-ECB").random_key # symmetric key
|
72
|
+
# key = OpenSSL::PKey::RSA.new(1024) # asymmetric key pair
|
73
|
+
#
|
74
|
+
# s3 = Aws::S3::Encryption::Client.new(encryption_key: key)
|
75
|
+
#
|
76
|
+
# ### Key Provider
|
77
|
+
#
|
78
|
+
# Alternatively, you can use a {KeyProvider}. A key provider makes
|
79
|
+
# it easy to work with multiple keys and simplifies key rotation.
|
80
|
+
#
|
81
|
+
# ### KMS Encryption Key Id
|
82
|
+
#
|
83
|
+
# If you pass the id to an AWS Key Management Service (KMS) key,
|
84
|
+
# then KMS will be used to generate, encrypt and decrypt object keys.
|
85
|
+
#
|
86
|
+
# # keep track of the kms key id
|
87
|
+
# kms = Aws::KMS::Client.new
|
88
|
+
# key_id = kms.create_key.key_metadata.key_id
|
89
|
+
#
|
90
|
+
# Aws::S3::Encryption::Client.new(
|
91
|
+
# kms_key_id: key_id,
|
92
|
+
# kms_client: kms,
|
93
|
+
# )
|
94
|
+
#
|
95
|
+
# ## Custom Key Providers
|
96
|
+
#
|
97
|
+
# A {KeyProvider} is any object that responds to:
|
98
|
+
#
|
99
|
+
# * `#encryption_materials`
|
100
|
+
# * `#key_for(materials_description)`
|
101
|
+
#
|
102
|
+
# Here is a trivial implementation of an in-memory key provider.
|
103
|
+
# This is provided as a demonstration of the key provider interface,
|
104
|
+
# and should not be used in production:
|
105
|
+
#
|
106
|
+
# class KeyProvider
|
107
|
+
#
|
108
|
+
# def initialize(default_key_name, keys)
|
109
|
+
# @keys = keys
|
110
|
+
# @encryption_materials = Aws::S3::Encryption::Materials.new(
|
111
|
+
# key: @keys[default_key_name],
|
112
|
+
# description: JSON.dump(key: default_key_name),
|
113
|
+
# )
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# attr_reader :encryption_materials
|
117
|
+
#
|
118
|
+
# def key_for(matdesc)
|
119
|
+
# key_name = JSON.load(matdesc)['key']
|
120
|
+
# if key = @keys[key_name]
|
121
|
+
# key
|
122
|
+
# else
|
123
|
+
# raise "encryption key not found for: #{matdesc.inspect}"
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# Given the above key provider, you can create an encryption client that
|
129
|
+
# chooses the key to use based on the materials description stored with
|
130
|
+
# the encrypted object. This makes it possible to use multiple keys
|
131
|
+
# and simplifies key rotation.
|
132
|
+
#
|
133
|
+
# # uses "new-key" for encrypting objects, uses either for decrypting
|
134
|
+
# keys = KeyProvider.new('new-key', {
|
135
|
+
# "old-key" => Base64.decode64("kM5UVbhE/4rtMZJfsadYEdm2vaKFsmV2f5+URSeUCV4="),
|
136
|
+
# "new-key" => Base64.decode64("w1WLio3agRWRTSJK/Ouh8NHoqRQ6fn5WbSXDTHjXMSo="),
|
137
|
+
# }),
|
138
|
+
#
|
139
|
+
# # chooses the key based on the materials description stored
|
140
|
+
# # with the encrypted object
|
141
|
+
# s3 = Aws::S3::Encryption::Client.new(key_provider: keys)
|
142
|
+
#
|
143
|
+
# ## Materials Description
|
144
|
+
#
|
145
|
+
# A materials description is JSON document string that is stored
|
146
|
+
# in the metadata (or instruction file) of an encrypted object.
|
147
|
+
# The {DefaultKeyProvider} uses the empty JSON document `"{}"`.
|
148
|
+
#
|
149
|
+
# When building a key provider, you are free to store whatever
|
150
|
+
# information you need to identify the master key that was used
|
151
|
+
# to encrypt the object.
|
152
|
+
#
|
153
|
+
# ## Envelope Location
|
154
|
+
#
|
155
|
+
# By default, the encryption client store the encryption envelope
|
156
|
+
# with the object, as metadata. You can choose to have the envelope
|
157
|
+
# stored in a separate "instruction file". An instruction file
|
158
|
+
# is an object, with the key of the encrypted object, suffixed with
|
159
|
+
# `".instruction"`.
|
160
|
+
#
|
161
|
+
# Specify the `:envelope_location` option as `:instruction_file` to
|
162
|
+
# use an instruction file for storing the envelope.
|
163
|
+
#
|
164
|
+
# # default behavior
|
165
|
+
# s3 = Aws::S3::Encryption::Client.new(
|
166
|
+
# key_provider: ...,
|
167
|
+
# envelope_location: :metadata,
|
168
|
+
# )
|
169
|
+
#
|
170
|
+
# # store envelope in a separate object
|
171
|
+
# s3 = Aws::S3::Encryption::Client.new(
|
172
|
+
# key_provider: ...,
|
173
|
+
# envelope_location: :instruction_file,
|
174
|
+
# instruction_file_suffix: '.instruction' # default
|
175
|
+
# )
|
176
|
+
#
|
177
|
+
# When using an instruction file, multiple requests are made when
|
178
|
+
# putting and getting the object. **This may cause issues if you are
|
179
|
+
# issuing concurrent PUT and GET requests to an encrypted object.**
|
180
|
+
#
|
181
|
+
module Encryption
|
182
|
+
class Client
|
183
|
+
|
184
|
+
extend Deprecations
|
185
|
+
extend Forwardable
|
186
|
+
def_delegators :@client, :config, :delete_object, :head_object, :build_request
|
187
|
+
|
188
|
+
# Creates a new encryption client. You must provide one of the following
|
189
|
+
# options:
|
190
|
+
#
|
191
|
+
# * `:encryption_key`
|
192
|
+
# * `:kms_key_id`
|
193
|
+
# * `:key_provider`
|
194
|
+
#
|
195
|
+
# You may also pass any other options accepted by `Client#initialize`.
|
196
|
+
#
|
197
|
+
# @option options [S3::Client] :client A basic S3 client that is used
|
198
|
+
# to make api calls. If a `:client` is not provided, a new {S3::Client}
|
199
|
+
# will be constructed.
|
200
|
+
#
|
201
|
+
# @option options [OpenSSL::PKey::RSA, String] :encryption_key The master
|
202
|
+
# key to use for encrypting/decrypting all objects.
|
203
|
+
#
|
204
|
+
# @option options [String] :kms_key_id When you provide a `:kms_key_id`,
|
205
|
+
# then AWS Key Management Service (KMS) will be used to manage the
|
206
|
+
# object encryption keys. By default a {KMS::Client} will be
|
207
|
+
# constructed for KMS API calls. Alternatively, you can provide
|
208
|
+
# your own via `:kms_client`.
|
209
|
+
#
|
210
|
+
# @option options [#key_for] :key_provider Any object that responds
|
211
|
+
# to `#key_for`. This method should accept a materials description
|
212
|
+
# JSON document string and return return an encryption key.
|
213
|
+
#
|
214
|
+
# @option options [Symbol] :envelope_location (:metadata) Where to
|
215
|
+
# store the envelope encryption keys. By default, the envelope is
|
216
|
+
# stored with the encrypted object. If you pass `:instruction_file`,
|
217
|
+
# then the envelope is stored in a separate object in Amazon S3.
|
218
|
+
#
|
219
|
+
# @option options [String] :instruction_file_suffix ('.instruction')
|
220
|
+
# When `:envelope_location` is `:instruction_file` then the
|
221
|
+
# instruction file uses the object key with this suffix appended.
|
222
|
+
#
|
223
|
+
# @option options [KMS::Client] :kms_client A default {KMS::Client}
|
224
|
+
# is constructed when using KMS to manage encryption keys.
|
225
|
+
#
|
226
|
+
def initialize(options = {})
|
227
|
+
@client = extract_client(options)
|
228
|
+
@cipher_provider = cipher_provider(options)
|
229
|
+
@envelope_location = extract_location(options)
|
230
|
+
@instruction_file_suffix = extract_suffix(options)
|
231
|
+
end
|
232
|
+
|
233
|
+
# @return [S3::Client]
|
234
|
+
attr_reader :client
|
235
|
+
|
236
|
+
# @return [KeyProvider, nil] Returns `nil` if you are using
|
237
|
+
# AWS Key Management Service (KMS).
|
238
|
+
attr_reader :key_provider
|
239
|
+
|
240
|
+
# @return [Symbol<:metadata, :instruction_file>]
|
241
|
+
attr_reader :envelope_location
|
242
|
+
|
243
|
+
# @return [String] When {#envelope_location} is `:instruction_file`,
|
244
|
+
# the envelope is stored in the object with the object key suffixed
|
245
|
+
# by this string.
|
246
|
+
attr_reader :instruction_file_suffix
|
247
|
+
|
248
|
+
# Uploads an object to Amazon S3, encrypting data client-side.
|
249
|
+
# See {S3::Client#put_object} for documentation on accepted
|
250
|
+
# request parameters.
|
251
|
+
# @option (see S3::Client#put_object)
|
252
|
+
# @return (see S3::Client#put_object)
|
253
|
+
# @see S3::Client#put_object
|
254
|
+
def put_object(params = {})
|
255
|
+
req = @client.build_request(:put_object, params)
|
256
|
+
req.handlers.add(EncryptHandler, priority: 95)
|
257
|
+
req.context[:encryption] = {
|
258
|
+
cipher_provider: @cipher_provider,
|
259
|
+
envelope_location: @envelope_location,
|
260
|
+
instruction_file_suffix: @instruction_file_suffix,
|
261
|
+
}
|
262
|
+
req.send_request
|
263
|
+
end
|
264
|
+
|
265
|
+
# Gets an object from Amazon S3, decrypting data locally.
|
266
|
+
# See {S3::Client#get_object} for documentation on accepted
|
267
|
+
# request parameters.
|
268
|
+
# @option params [String] :instruction_file_suffix The suffix
|
269
|
+
# used to find the instruction file containing the encryption
|
270
|
+
# envelope. You should not set this option when the envelope
|
271
|
+
# is stored in the object metadata. Defaults to
|
272
|
+
# {#instruction_file_suffix}.
|
273
|
+
# @option params [String] :instruction_file_suffix
|
274
|
+
# @option (see S3::Client#get_object)
|
275
|
+
# @return (see S3::Client#get_object)
|
276
|
+
# @see S3::Client#get_object
|
277
|
+
# @note The `:range` request parameter is not yet supported.
|
278
|
+
def get_object(params = {}, &block)
|
279
|
+
if params[:range]
|
280
|
+
raise NotImplementedError, '#get_object with :range not supported yet'
|
281
|
+
end
|
282
|
+
envelope_location, instruction_file_suffix = envelope_options(params)
|
283
|
+
req = @client.build_request(:get_object, params)
|
284
|
+
req.handlers.add(DecryptHandler)
|
285
|
+
req.context[:encryption] = {
|
286
|
+
cipher_provider: @cipher_provider,
|
287
|
+
envelope_location: envelope_location,
|
288
|
+
instruction_file_suffix: instruction_file_suffix,
|
289
|
+
}
|
290
|
+
req.send_request(target: block)
|
291
|
+
end
|
292
|
+
|
293
|
+
private
|
294
|
+
|
295
|
+
def extract_client(options)
|
296
|
+
options[:client] || begin
|
297
|
+
options = options.dup
|
298
|
+
options.delete(:kms_key_id)
|
299
|
+
options.delete(:kms_client)
|
300
|
+
options.delete(:key_provider)
|
301
|
+
options.delete(:encryption_key)
|
302
|
+
options.delete(:envelope_location)
|
303
|
+
options.delete(:instruction_file_suffix)
|
304
|
+
S3::Client.new(options)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def kms_client(options)
|
309
|
+
options[:kms_client] || begin
|
310
|
+
KMS::Client.new(
|
311
|
+
region: @client.config.region,
|
312
|
+
credentials: @client.config.credentials,
|
313
|
+
)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def cipher_provider(options)
|
318
|
+
if options[:kms_key_id]
|
319
|
+
KmsCipherProvider.new(
|
320
|
+
kms_key_id: options[:kms_key_id],
|
321
|
+
kms_client: kms_client(options),
|
322
|
+
)
|
323
|
+
else
|
324
|
+
# kept here for backwards compatability, {#key_provider} is deprecated
|
325
|
+
@key_provider = extract_key_provider(options)
|
326
|
+
DefaultCipherProvider.new(key_provider: @key_provider)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def extract_key_provider(options)
|
331
|
+
if options[:key_provider]
|
332
|
+
options[:key_provider]
|
333
|
+
elsif options[:encryption_key]
|
334
|
+
DefaultKeyProvider.new(options)
|
335
|
+
else
|
336
|
+
msg = 'you must pass a :kms_key_id, :key_provider, or :encryption_key'
|
337
|
+
raise ArgumentError, msg
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def envelope_options(params)
|
342
|
+
location = params.delete(:envelope_location) || @envelope_location
|
343
|
+
suffix = params.delete(:instruction_file_suffix)
|
344
|
+
if suffix
|
345
|
+
[:instruction_file, suffix]
|
346
|
+
else
|
347
|
+
[location, @instruction_file_suffix]
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
def extract_location(options)
|
352
|
+
location = options[:envelope_location] || :metadata
|
353
|
+
if [:metadata, :instruction_file].include?(location)
|
354
|
+
location
|
355
|
+
else
|
356
|
+
msg = ':envelope_location must be :metadata or :instruction_file '\
|
357
|
+
"got #{location.inspect}"
|
358
|
+
raise ArgumentError, msg
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def extract_suffix(options)
|
363
|
+
suffix = options[:instruction_file_suffix] || '.instruction'
|
364
|
+
if String === suffix
|
365
|
+
suffix
|
366
|
+
else
|
367
|
+
msg = ':instruction_file_suffix must be a String'
|
368
|
+
raise ArgumentError, msg
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|