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

Add some AWS options #362

Merged
merged 2 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ AssetSync.configure do |config|
# Increase upload performance by configuring your region
# config.fog_region = 'eu-west-1'
#
# Change AWS signature version. Default is 4
# config.aws_signature_version = 4
#
# Use http instead of https.
# config.fog_scheme = 'http'
#
# Automatically replace files with their equivalent gzip compressed version
# config.gzip_compression = true
#
Expand Down Expand Up @@ -222,6 +228,10 @@ defaults: &defaults
aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
# You may need to specify what region your storage bucket is in
# fog_region: "eu-west-1"
# Change AWS signature version. Default is 4
# aws_signature_version: 4
# Use http instead of https.
# fog_scheme: 'http'
existing_remote_files: keep # Existing pre-compiled assets on S3 will be kept
# To delete existing remote files.
# existing_remote_files: delete
Expand Down
14 changes: 11 additions & 3 deletions lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class Invalid < StandardError; end
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
attr_accessor :fog_directory # e.g. 'the-bucket-name'
attr_accessor :fog_region # e.g. 'eu-west-1'
attr_accessor :fog_path_style # e.g true

# Amazon AWS
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version
attr_accessor :fog_host # e.g. 's3.amazonaws.com'
attr_accessor :fog_path_style # e.g. true
attr_accessor :fog_scheme # e.g. 'http'

# Rackspace
attr_accessor :rackspace_username, :rackspace_api_key, :rackspace_auth_url
Expand Down Expand Up @@ -146,13 +148,16 @@ def public_path
def load_yml!
self.enabled = yml["enabled"] if yml.has_key?('enabled')
self.fog_provider = yml["fog_provider"]
self.host = yml["fog_host"]
self.fog_directory = yml["fog_directory"]
self.fog_region = yml["fog_region"]
self.fog_path_style = yml["fog_path_style"]
self.fog_scheme = yml["fog_scheme"]
self.aws_access_key_id = yml["aws_access_key_id"]
self.aws_secret_access_key = yml["aws_secret_access_key"]
self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
self.aws_iam_roles = yml["aws_iam_roles"]
self.aws_signature_version = yml["aws_signature_version"]
self.rackspace_username = yml["rackspace_username"]
self.rackspace_auth_url = yml["rackspace_auth_url"] if yml.has_key?("rackspace_auth_url")
self.rackspace_api_key = yml["rackspace_api_key"]
Expand Down Expand Up @@ -199,6 +204,10 @@ def fog_options
:aws_secret_access_key => aws_secret_access_key
})
end
options.merge!({:host => fog_host}) if fog_host
options.merge!({:scheme => fog_scheme}) if fog_scheme
options.merge!({:aws_signature_version => aws_signature_version}) if aws_signature_version
options.merge!({:path_style => fog_path_style}) if fog_path_style
elsif rackspace?
options.merge!({
:rackspace_username => rackspace_username,
Expand All @@ -218,7 +227,6 @@ def fog_options
end

options.merge!({:region => fog_region}) if fog_region && !rackspace?
options.merge!({:path_style => fog_path_style}) if fog_path_style && aws?
return options
end

Expand Down
4 changes: 4 additions & 0 deletions lib/asset_sync/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ class Engine < Rails::Engine
config.fog_provider = ENV['FOG_PROVIDER'] if ENV.has_key?('FOG_PROVIDER')
config.fog_directory = ENV['FOG_DIRECTORY'] if ENV.has_key?('FOG_DIRECTORY')
config.fog_region = ENV['FOG_REGION'] if ENV.has_key?('FOG_REGION')
config.fog_host = ENV['FOG_HOST'] if ENV.has_key?('FOG_HOST')
config.fog_scheme = ENV['FOG_SCHEMA'] if ENV.has_key?('FOG_SCHEMA')
config.fog_path_style = ENV['FOG_PATH_STYLE'] if ENV.has_key?('FOG_PATH_STYLE')

config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] if ENV.has_key?('AWS_ACCESS_KEY_ID')
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] if ENV.has_key?('AWS_SECRET_ACCESS_KEY')
config.aws_signature_version = ENV['AWS_SIGNATURE_VERSION'] if ENV.has_key?('AWS_SIGNATURE_VERSION')
config.aws_reduced_redundancy = ENV['AWS_REDUCED_REDUNDANCY'] == true if ENV.has_key?('AWS_REDUCED_REDUNDANCY')

config.rackspace_username = ENV['RACKSPACE_USERNAME'] if ENV.has_key?('RACKSPACE_USERNAME')
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/asset_sync/templates/asset_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
# To use AWS reduced redundancy storage.
# config.aws_reduced_redundancy = true
#
# Change AWS signature version. Default is 4
# config.aws_signature_version = 4
#
# Use http instead of https. Default is 'http'
# config.fog_scheme = 'http'
<%- elsif google? -%>
config.fog_provider = 'Google'
config.google_storage_access_key_id = ENV['GOOGLE_STORAGE_ACCESS_KEY_ID']
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/asset_sync/templates/asset_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ defaults: &defaults
aws_secret_access_key: "<%= aws_secret_access_key %>"
# To use AWS reduced redundancy storage.
# aws_reduced_redundancy: true
# Change AWS signature version. Default is 4
# aws_signature_version: 4
# Use http instead of https. Default is 'http'
# fog_scheme: 'http'
<%- elsif google? -%>
fog_provider: 'Google'
google_storage_access_key_id: "<%= google_storage_access_key_id %>"
Expand Down