Skip to content

Commit

Permalink
Merge pull request #377 from AssetSync/feature/fog-public
Browse files Browse the repository at this point in the history
+ Add option fog_public
  • Loading branch information
PikachuEXE authored Dec 7, 2018
2 parents e4a9dff + 51e4cc9 commit 1aa091d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
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
!@value.nil?
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

0 comments on commit 1aa091d

Please sign in to comment.