Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added fog_aws_accelerate options for fog storage provider #2108

Merged
merged 1 commit into from Mar 5, 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
5 changes: 4 additions & 1 deletion lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Storage
# [:fog_authenticated_url_expiration] (optional) time (in seconds) that authenticated urls
# will be valid, when fog_public is false and provider is AWS or Google, defaults to 600
# [:fog_use_ssl_for_aws] (optional) #public_url will use https for the AWS generated URL]
# [:fog_aws_accelerate] (optional) #public_url will use s3-accelerate subdomain
# instead of s3, defaults to false
#
#
# AWS credentials contain the following keys:
Expand Down Expand Up @@ -349,7 +351,8 @@ def public_url
protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http"
# if directory is a valid subdomain, use that style for access
if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
"#{protocol}://#{@uploader.fog_directory}.s3.amazonaws.com/#{encoded_path}"
s3_subdomain = @uploader.fog_aws_accelerate ? "s3-accelerate" : "s3"
"#{protocol}://#{@uploader.fog_directory}.#{s3_subdomain}.amazonaws.com/#{encoded_path}"
else
# directory is not a valid subdomain, so use path style for access
"#{protocol}://s3.amazonaws.com/#{@uploader.fog_directory}/#{encoded_path}"
Expand Down
3 changes: 2 additions & 1 deletion lib/carrierwave/uploader/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Configuration
add_config :fog_public
add_config :fog_authenticated_url_expiration
add_config :fog_use_ssl_for_aws
add_config :fog_aws_accelerate

# Mounting
add_config :ignore_integrity_errors
Expand Down Expand Up @@ -177,6 +178,7 @@ def reset_config
config.fog_public = true
config.fog_authenticated_url_expiration = 600
config.fog_use_ssl_for_aws = true
config.fog_aws_accelerate = false
config.store_dir = 'uploads'
config.cache_dir = 'uploads/tmp'
config.delete_tmp_file_after_storage = true
Expand All @@ -200,4 +202,3 @@ def reset_config
end
end
end

18 changes: 15 additions & 3 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,22 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end
end

it "should use a subdomain URL for AWS if the directory is a valid subdomain" do
if @provider == 'AWS'
context "directory is a valid subdomain" do
before do
allow(@uploader).to receive(:fog_directory).and_return('assets.site.com')
expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com')
end

it "should use a subdomain URL for AWS" do
if @provider == 'AWS'
expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com')
end
end

it "should use accelerate domain if fog_aws_accelerate is true" do
if @provider == 'AWS'
allow(@uploader).to receive(:fog_aws_accelerate).and_return(true)
expect(@fog_file.public_url).to include('https://assets.site.com.s3-accelerate.amazonaws.com')
end
end
end

Expand Down