Skip to content

Commit

Permalink
You can now pass client options in to Aws::S3::Encryption::Client.
Browse files Browse the repository at this point in the history
Fixes #800
Fixes #801
  • Loading branch information
trevorrowe committed May 1, 2015
1 parent f0c8a45 commit f2bfe0d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Unreleased Changes
------------------

* Feature - Aws::S3::Encryption::Client - You can now pass vanilla
client constructor options to the encryption client constructor and these
will pass through when generating the underlying client. This increases
the parity with the vanilla client.

See [related GitHub issue #800](https://github.com/aws/aws-sdk-ruby/pull/800)
and [related GitHub issue #801](https://github.com/aws/aws-sdk-ruby/pull/801).

* Feature - Aws::S3 - Added the ability to pass a block to
`Aws::S3::Encryption::Client#get_object` that yields data as it is
decrypted. This increases parity with the vanilla `Aws::S3::Client#get_object`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class Client
# * `:key_provider`
# * `:encryption_key`
#
# You may also pass any other options accepted by {S3::Client.new}.
#
# @option options [S3::Client] :client A basic S3 client that is used
# to make api calls. If a `:client` is not provided, a new {S3::Client}
# will be constructed.
Expand All @@ -180,7 +182,7 @@ class Client
# instruction file uses the object key with this suffix appended.
#
def initialize(options = {})
@client = options[:client] || S3::Client.new
@client = extract_client(options)
@key_provider = extract_key_provider(options)
@envelope_location = extract_location(options)
@instruction_file_suffix = extract_suffix(options)
Expand Down Expand Up @@ -247,6 +249,17 @@ def get_object(params = {}, &block)

private

def extract_client(options)
options[:client] || begin
options = options.dup
options.delete(:key_provider)
options.delete(:encryption_key)
options.delete(:envelope_location)
options.delete(:instruction_file_suffix)
S3::Client.new(options)
end
end

def envelope_options(params)
location = params.delete(:envelope_location) || @envelope_location
suffix = params.delete(:instruction_file_suffix)
Expand Down
12 changes: 12 additions & 0 deletions aws-sdk-resources/spec/services/s3/encryption/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ module Encryption
expect(client.client).to be(api_client)
end

it 'accepts vanilla client options' do
opts = {
region: 'us-west-2',
credentials:Credentials.new('akid', 'secret'),
encryption_key: '.' * 32,
}
enc_client = Encryption::Client.new(opts)
expect(enc_client.client.config.region).to eq('us-west-2')
expect(enc_client.client.config.credentials.access_key_id).to eq('akid')
expect(enc_client.client.config.credentials.secret_access_key).to eq('secret')
end

it 'requires an encryption key or provider' do
expect {
options.delete(:encryption_key)
Expand Down

0 comments on commit f2bfe0d

Please sign in to comment.