Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support fog's new use_iam_profile option #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/dragonfly/data_storage/s3data_store.rb
Expand Up @@ -12,6 +12,7 @@ class S3DataStore
configurable_attr :access_key_id configurable_attr :access_key_id
configurable_attr :secret_access_key configurable_attr :secret_access_key
configurable_attr :region configurable_attr :region
configurable_attr :use_iam_profile
configurable_attr :use_filesystem, true configurable_attr :use_filesystem, true
configurable_attr :storage_headers, {'x-amz-acl' => 'public-read'} configurable_attr :storage_headers, {'x-amz-acl' => 'public-read'}
configurable_attr :url_scheme, 'http' configurable_attr :url_scheme, 'http'
Expand All @@ -33,6 +34,7 @@ def initialize(opts={})
self.access_key_id = opts[:access_key_id] self.access_key_id = opts[:access_key_id]
self.secret_access_key = opts[:secret_access_key] self.secret_access_key = opts[:secret_access_key]
self.region = opts[:region] self.region = opts[:region]
self.use_iam_profile = opts[:use_iam_profile]
end end


def store(temp_object, opts={}) def store(temp_object, opts={})
Expand Down Expand Up @@ -96,12 +98,13 @@ def domain


def storage def storage
@storage ||= begin @storage ||= begin
storage = Fog::Storage.new( storage = Fog::Storage.new({
:provider => 'AWS', :provider => 'AWS',
:aws_access_key_id => access_key_id, :aws_access_key_id => access_key_id,
:aws_secret_access_key => secret_access_key, :aws_secret_access_key => secret_access_key,
:region => region :region => region,
) :use_iam_profile => use_iam_profile
}.reject {|name, option| option.nil?})
storage.sync_clock storage.sync_clock
storage storage
end end
Expand All @@ -118,8 +121,12 @@ def bucket_exists?


def ensure_configured def ensure_configured
unless @configured unless @configured
[:bucket_name, :access_key_id, :secret_access_key].each do |attr| if use_iam_profile
raise NotConfigured, "You need to configure #{self.class.name} with #{attr}" if send(attr).nil? raise NotConfigured, "You need to configure #{self.class.name} with #{attr}" if bucket_name.nil?
else
[:bucket_name, :access_key_id, :secret_access_key].each do |attr|
raise NotConfigured, "You need to configure #{self.class.name} with #{attr}" if send(attr).nil?
end
end end
@configured = true @configured = true
end end
Expand Down
10 changes: 10 additions & 0 deletions spec/dragonfly/data_storage/s3_data_store_spec.rb
Expand Up @@ -176,6 +176,16 @@
@data_store.secret_access_key = nil @data_store.secret_access_key = nil
proc{ @data_store.retrieve('asdf') }.should raise_error(Dragonfly::Configurable::NotConfigured) proc{ @data_store.retrieve('asdf') }.should raise_error(Dragonfly::Configurable::NotConfigured)
end end

if !enabled #this will fail since the specs are not running on an ec2 instance with an iam role defined
it 'should allow missing secret key and access key on store if iam profiles are allowed' do
@data_store.use_iam_profile = true
@data_store.secret_access_key = nil
@data_store.access_key_id = nil
proc{ @data_store.store(@temp_object) }.should_not raise_error(Dragonfly::Configurable::NotConfigured)
end
end

end end


describe "autocreating the bucket" do describe "autocreating the bucket" do
Expand Down