Class: Aws::S3::EncryptionV2::Client
- Inherits:
-
Object
- Object
- Aws::S3::EncryptionV2::Client
- Extended by:
- Forwardable
- Defined in:
- gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb
Instance Attribute Summary collapse
-
#client ⇒ S3::Client
readonly
-
#commitment_policy ⇒ Symbol?
readonly
Optional commitment policy for V2 to V3 migration.
-
#envelope_location ⇒ Symbol<:metadata, :instruction_file>
readonly
-
#instruction_file_suffix ⇒ String
readonly
When #envelope_location is
:instruction_file, the envelope is stored in the object with the object key suffixed by this string. -
#key_provider ⇒ KeyProvider?
readonly
Returns
nilif you are using AWS Key Management Service (KMS). -
#kms_allow_decrypt_with_any_cmk ⇒ Boolean
readonly
If true the provided KMS key_id will not be used during decrypt, allowing decryption with the key_id from the object.
-
#security_profile ⇒ Symbol
readonly
Determines the support for reading objects written using older key wrap or content encryption schemas.
Instance Method Summary collapse
-
#get_object(params = {}, &block) ⇒ Types::GetObjectOutput
Gets an object from Amazon S3, decrypting data locally.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new encryption client.
-
#put_object(params = {}) ⇒ Types::PutObjectOutput
Uploads an object to Amazon S3, encrypting data client-side.
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new encryption client. You must configure all of the following:
- a key or key provider - The key provided also determines the key wrapping schema(s) supported for both encryption and decryption.
key_wrap_schema- The key wrapping schema. It must match the type of key configured.content_encryption_schema- The only supported value currently is:aes_gcm_no_paddingMore options will be added in future releases.security_profile- Determines the support for reading objects written using older key wrap or content encryption schemas. If you need to read legacy objects encrypted by an existing V1 Client, then set this to:v2_and_legacy. Otherwise, set it to:v2
To configure the key you must provide one of the following set of options:
:encryption_key:kms_key_id:key_provider
You may also pass any other options accepted by Client#initialize.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 327 def initialize( = {}) validate_params() @client = extract_client() @cipher_provider = build_cipher_provider() @key_provider = @cipher_provider.key_provider if @cipher_provider.is_a?(DefaultCipherProvider) @envelope_location = extract_location() @instruction_file_suffix = extract_suffix() @kms_allow_decrypt_with_any_cmk = [:kms_key_id] == :kms_allow_decrypt_with_any_cmk @security_profile = extract_security_profile() @commitment_policy = extract_commitment_policy() # The v3 cipher is only used for decrypt. # Therefore any configured v2 `content_encryption_schema` is going to be incorrect. @v3_cipher_provider = build_v3_cipher_provider_for_decrypt(.reject { |k, _| k == :content_encryption_schema }) end |
Instance Attribute Details
#client ⇒ S3::Client (readonly)
344 345 346 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 344 def client @client end |
#commitment_policy ⇒ Symbol? (readonly)
Returns Optional commitment policy for V2 to V3 migration. When set to :forbid_encrypt_allow_decrypt, explicitly indicates maintaining V2 encryption behavior while preparing for migration.
369 370 371 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 369 def commitment_policy @commitment_policy end |
#envelope_location ⇒ Symbol<:metadata, :instruction_file> (readonly)
359 360 361 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 359 def envelope_location @envelope_location end |
#instruction_file_suffix ⇒ String (readonly)
Returns When #envelope_location is :instruction_file,
the envelope is stored in the object with the object key suffixed
by this string.
364 365 366 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 364 def instruction_file_suffix @instruction_file_suffix end |
#key_provider ⇒ KeyProvider? (readonly)
Returns nil if you are using
AWS Key Management Service (KMS).
348 349 350 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 348 def key_provider @key_provider end |
#kms_allow_decrypt_with_any_cmk ⇒ Boolean (readonly)
Returns If true the provided KMS key_id will not be used during decrypt, allowing decryption with the key_id from the object.
356 357 358 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 356 def kms_allow_decrypt_with_any_cmk @kms_allow_decrypt_with_any_cmk end |
#security_profile ⇒ Symbol (readonly)
Returns Determines the support for reading objects written using older key wrap or content encryption schemas.
352 353 354 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 352 def security_profile @security_profile end |
Instance Method Details
#get_object(params = {}, &block) ⇒ Types::GetObjectOutput
The :range request parameter is not supported.
Gets an object from Amazon S3, decrypting data locally. See Client#get_object for documentation on accepted request parameters. Warning: If you provide a block to get_object or set the request parameter :response_target to a Proc, then read the entire object to the end before you start using the decrypted data. This is to verify that the object has not been modified since it was encrypted.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 427 def get_object(params = {}, &block) if params[:range] raise NotImplementedError, '#get_object with :range not supported' end envelope_location, instruction_file_suffix = (params) kms_encryption_context = params.delete(:kms_encryption_context) kms_any_cmk_mode = kms_any_cmk_mode(params) security_profile = security_profile_from_params(params) req = @client.build_request(:get_object, params) req.handlers.add(DecryptHandler) req.context[:encryption] = { cipher_provider: @cipher_provider, v3_cipher_provider: @v3_cipher_provider, envelope_location: envelope_location, instruction_file_suffix: instruction_file_suffix, kms_encryption_context: kms_encryption_context, kms_allow_decrypt_with_any_cmk: kms_any_cmk_mode, security_profile: security_profile } Aws::Plugins::UserAgent.metric('S3_CRYPTO_V2') do req.send_request(target: block) end end |
#put_object(params = {}) ⇒ Types::PutObjectOutput
Uploads an object to Amazon S3, encrypting data client-side. See Client#put_object for documentation on accepted request parameters.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/encryptionV2/client.rb', line 381 def put_object(params = {}) kms_encryption_context = params.delete(:kms_encryption_context) req = @client.build_request(:put_object, params) req.handlers.add(EncryptHandler, priority: 95) req.context[:encryption] = { cipher_provider: @cipher_provider, envelope_location: @envelope_location, instruction_file_suffix: @instruction_file_suffix, kms_encryption_context: kms_encryption_context } Aws::Plugins::UserAgent.metric('S3_CRYPTO_V2') do req.send_request end end |