diff --git a/README.md b/README.md index 89b02cba..1d5afd35 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,11 @@ AssetSync.configure do |config| # Increase upload performance by configuring your region # config.fog_region = 'eu-west-1' # + # Set `public` option when uploading file depending on value, + # Setting to "default" makes asset sync skip setting the option + # Possible values: true, false, "default" (default: true) + # config.fog_public = true + # # Change AWS signature version. Default is 4 # config.aws_signature_version = 4 # diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 719d151f..8ff502d4 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -32,6 +32,7 @@ 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_reader :fog_public # e.g. true, false, "default" # Amazon AWS attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version @@ -63,6 +64,7 @@ class Invalid < StandardError; end def initialize self.fog_region = nil + self.fog_public = true self.existing_remote_files = 'keep' self.gzip_compression = false self.manifest = false @@ -163,6 +165,7 @@ def load_yml! self.fog_host = yml["fog_host"] self.fog_directory = yml["fog_directory"] self.fog_region = yml["fog_region"] + self.fog_public = yml["fog_public"] if yml.has_key?("fog_public") self.fog_path_style = yml["fog_path_style"] self.fog_scheme = yml["fog_scheme"] self.aws_access_key_id = yml["aws_access_key_id"] @@ -249,7 +252,7 @@ def fog_options raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently." end - return options + options end # @api @@ -275,6 +278,10 @@ def file_ext_to_mime_type_overrides @file_ext_to_mime_type_overrides ||= FileExtToMimeTypeOverrides.new end + def fog_public=(new_val) + @fog_public = FogPublicValue.new(new_val) + end + private # This is a proc to get additional local files paths @@ -320,7 +327,21 @@ def key?(key) def fetch(key) @overrides.fetch(key) end + end + # @api private + class FogPublicValue + def initialize(val) + @value = val + end + + def use_explicit_value? + @value.to_s != "default" + end + + def to_bool + !@value.nil? + end end end end diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 0d75d5ac..d8342952 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -43,7 +43,7 @@ def ignored_files def get_manifest_path return [] unless self.config.include_manifest - + if ActionView::Base.respond_to?(:assets_manifest) manifest = Sprockets::Manifest.new(ActionView::Base.assets_manifest.environment, ActionView::Base.assets_manifest.dir) manifest_path = manifest.filename @@ -148,10 +148,17 @@ def upload_file(f) file = { :key => f, :body => file_handle, - :public => true, :content_type => mime } + # region fog_public + + if config.fog_public.use_explicit_value? + file[:public] = config.fog_public.to_bool + end + + # endregion fog_public + uncompressed_filename = f.sub(/\.gz\z/, '') basename = File.basename(uncompressed_filename, File.extname(uncompressed_filename)) diff --git a/lib/generators/asset_sync/templates/asset_sync.rb b/lib/generators/asset_sync/templates/asset_sync.rb index cf7cf973..b87f0546 100644 --- a/lib/generators/asset_sync/templates/asset_sync.rb +++ b/lib/generators/asset_sync/templates/asset_sync.rb @@ -42,6 +42,11 @@ # Increase upload performance by configuring your region # config.fog_region = 'eu-west-1' # + # Set `public` option when uploading file depending on value, + # Setting to "default" makes asset sync skip setting the option + # Possible values: true, false, "default" (default: true) + # config.fog_public = true + # # Don't delete files from the store # config.existing_remote_files = "keep" # diff --git a/lib/generators/asset_sync/templates/asset_sync.yml b/lib/generators/asset_sync/templates/asset_sync.yml index 8e8991d5..21591484 100644 --- a/lib/generators/asset_sync/templates/asset_sync.yml +++ b/lib/generators/asset_sync/templates/asset_sync.yml @@ -3,6 +3,7 @@ defaults: &defaults fog_provider: 'AWS' aws_access_key_id: "<%= aws_access_key_id %>" aws_secret_access_key: "<%= aws_secret_access_key %>" + # To use AWS reduced redundancy storage. # aws_reduced_redundancy: true # @@ -32,15 +33,25 @@ defaults: &defaults # fog_directory specifies container name of Azure Blob storage <%- end -%> fog_directory: "<%= app_name %>-assets" + # You may need to specify what region your storage bucket is in # fog_region: "eu-west-1" + + # Set `public` option when uploading file depending on value, + # Setting to "default" makes asset sync skip setting the option + # Possible values: true, false, "default" (default: true) + # config.fog_public = true + existing_remote_files: keep # To delete existing remote files. # existing_remote_files: delete + # Automatically replace files with their equivalent gzip compressed version # gzip_compression: true + # Fail silently. Useful for environments such as Heroku # fail_silently: true + # Allow custom assets to be cacheable. Note: The base filename will be matched # cache_asset_regexps: ['cache_me.js', !ruby/regexp '/cache_some\.\d{8}\.css/']