From 71a8e1e5300e34e49c022fd8499924f45d21ef24 Mon Sep 17 00:00:00 2001 From: ArmandPredicSis Date: Fri, 24 Nov 2017 15:42:20 +0100 Subject: [PATCH] add some AWS options --- README.md | 10 ++++++++++ lib/asset_sync/config.rb | 14 +++++++++++--- lib/asset_sync/engine.rb | 4 ++++ lib/generators/asset_sync/templates/asset_sync.rb | 6 ++++++ lib/generators/asset_sync/templates/asset_sync.yml | 4 ++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 738f1eee..78e61fc7 100644 --- a/README.md +++ b/README.md @@ -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 # @@ -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 diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 82c6b737..0d026f18 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -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 @@ -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"] @@ -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, @@ -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 diff --git a/lib/asset_sync/engine.rb b/lib/asset_sync/engine.rb index 0f6aa534..9a1406a4 100644 --- a/lib/asset_sync/engine.rb +++ b/lib/asset_sync/engine.rb @@ -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.fog_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') diff --git a/lib/generators/asset_sync/templates/asset_sync.rb b/lib/generators/asset_sync/templates/asset_sync.rb index 8f4961ba..dff52475 100644 --- a/lib/generators/asset_sync/templates/asset_sync.rb +++ b/lib/generators/asset_sync/templates/asset_sync.rb @@ -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. + # config.fog_scheme = 'http' <%- elsif google? -%> config.fog_provider = 'Google' config.google_storage_access_key_id = ENV['GOOGLE_STORAGE_ACCESS_KEY_ID'] diff --git a/lib/generators/asset_sync/templates/asset_sync.yml b/lib/generators/asset_sync/templates/asset_sync.yml index 543e4eed..b5d9493c 100644 --- a/lib/generators/asset_sync/templates/asset_sync.yml +++ b/lib/generators/asset_sync/templates/asset_sync.yml @@ -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. + # fog_scheme: 'http' <%- elsif google? -%> fog_provider: 'Google' google_storage_access_key_id: "<%= google_storage_access_key_id %>"