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

Allow the use of fog options from .fog file #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class Invalid < StandardError; end
validates :fog_provider, :presence => true
validates :fog_directory, :presence => true

validates :aws_access_key_id, :presence => true, :if => :aws?
validates :aws_secret_access_key, :presence => true, :if => :aws?
validates :rackspace_username, :presence => true, :if => :rackspace?
validates :rackspace_api_key, :presence => true, :if => :rackspace?
validates :google_storage_secret_access_key, :presence => true, :if => :google?
validates :google_storage_access_key_id, :presence => true, :if => :google?

def initialize
self.fog_region = nil
self.existing_remote_files = 'keep'
Expand Down Expand Up @@ -155,35 +148,31 @@ def load_yml!
self.fog_region = yml["region"] if yml.has_key?("region")
end


def fog_options
options = { :provider => fog_provider }
{ :provider => fog_provider }.tap { |options|
fog_option_keys.each do |key|
val = send(key)
options[key] = val unless val.blank?
end

options[:region] = fog_region if fog_region
}
end

private

def fog_option_keys
if aws?
options.merge!({
:aws_access_key_id => aws_access_key_id,
:aws_secret_access_key => aws_secret_access_key
})
[:aws_access_key_id, :aws_secret_access_key]
elsif rackspace?
options.merge!({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key
})
options.merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url
[:rackspace_username, :rackspace_api_key, :rackspace_auth_url]
elsif google?
options.merge!({
:google_storage_secret_access_key => google_storage_secret_access_key,
:google_storage_access_key_id => google_storage_access_key_id
})
[:google_storage_secret_access_key, :google_storage_access_key_id]
else
raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS and Rackspace are supported currently."
end

options.merge!({:region => fog_region}) if fog_region
return options
end

private

def default_manifest_directory
File.join(Rails.public_path, assets_prefix)
end
Expand Down