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 option fog_public #377

Merged
merged 1 commit into from
Dec 7, 2018
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
23 changes: 22 additions & 1 deletion lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
[email protected]?
end
end
end
end
11 changes: 9 additions & 2 deletions lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions lib/generators/asset_sync/templates/asset_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#
Expand Down
11 changes: 11 additions & 0 deletions lib/generators/asset_sync/templates/asset_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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/']

Expand Down