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

support Azure Blob storage #363

Merged
merged 11 commits into from Dec 12, 2017
Next

add AzureRM provider

it depends on fog-azure-rm gem
  • Loading branch information...
devchick committed Dec 7, 2017
commit b07da5b1143850d0183bf0a151f1beeb1b230e65
Copy path View file
@@ -42,6 +42,10 @@ class Invalid < StandardError; end
# Google Storage
attr_accessor :google_storage_secret_access_key, :google_storage_access_key_id

# Azure Blob with Fog::AzureRM
attr_accessor :azure_storage_account_name
attr_accessor :azure_storage_access_key

validates :existing_remote_files, :inclusion => { :in => %w(keep delete ignore) }

validates :fog_provider, :presence => true
@@ -120,6 +124,10 @@ def google?
fog_provider =~ /google/i
end

def azure_rm?
fog_provider =~ /azurerm/i
end

def cache_asset_regexp=(cache_asset_regexp)
self.cache_asset_regexps = [cache_asset_regexp]
end
@@ -175,6 +183,9 @@ def load_yml!
self.cdn_distribution_id = yml['cdn_distribution_id'] if yml.has_key?("cdn_distribution_id")
self.cache_asset_regexps = yml['cache_asset_regexps'] if yml.has_key?("cache_asset_regexps")

self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")

# TODO deprecate the other old style config settings. FML.
self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
self.aws_secret_access_key = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
@@ -222,11 +233,19 @@ def fog_options
:google_storage_secret_access_key => google_storage_secret_access_key,
:google_storage_access_key_id => google_storage_access_key_id
})
elsif azure_rm?
options.merge!({
:azure_storage_account_name => azure_storage_account_name,
:azure_storage_access_key => azure_storage_access_key,
})
options.merge!({
:environment => fog_region
}) if fog_region
else
raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
end

options.merge!({:region => fog_region}) if fog_region && !rackspace?
options.merge!({:region => fog_region}) if fog_region && !rackspace? && !azure_rm?

This comment has been minimized.

Copy link
@PikachuEXE

PikachuEXE Dec 11, 2017

Member

Should really put this line into every if except rackspace

This comment has been minimized.

Copy link
@PikachuEXE

PikachuEXE Dec 11, 2017

Member

I can refactor this later you can leave this unchanged :P

This comment has been minimized.

Copy link
@devchick

devchick Dec 11, 2017

Author Contributor

Do you mean like below?

if aws?
  ...
  options.merge!({:region => fog_region}) if fog_region
elsif rackspace?
  ...
  options.merge!({:rackspace_region => fog_region}) if fog_region
elsif google?
  ...
  options.merge!({:region => fog_region}) if fog_region
elsif azure_rm?
  ...
  options.merge!({:environment => fog_region}) if fog_region
else
  ...
end
return options
end

Copy path View file
@@ -31,6 +31,9 @@ class Engine < Rails::Engine
config.google_storage_access_key_id = ENV['GOOGLE_STORAGE_ACCESS_KEY_ID'] if ENV.has_key?('GOOGLE_STORAGE_ACCESS_KEY_ID')
config.google_storage_secret_access_key = ENV['GOOGLE_STORAGE_SECRET_ACCESS_KEY'] if ENV.has_key?('GOOGLE_STORAGE_SECRET_ACCESS_KEY')

config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME'] if ENV.has_key?('AZURE_STORAGE_ACCOUNT_NAME')
config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY'] if ENV.has_key?('AZURE_STORAGE_ACCESS_KEY')

config.enabled = (ENV['ASSET_SYNC_ENABLED'] == 'true') if ENV.has_key?('ASSET_SYNC_ENABLED')

config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
@@ -23,6 +23,10 @@ def rackspace?
options[:provider] == 'Rackspace'
end

def azure_rm?
options[:provider] == 'AzureRm'
end

def aws_access_key_id
"<%= ENV['AWS_ACCESS_KEY_ID'] %>"
end
@@ -47,6 +51,14 @@ def rackspace_api_key
"<%= ENV['RACKSPACE_API_KEY'] %>"
end

def azure_storage_account_name
"<%= ENV['AZURE_STORAGE_ACCOUNT_NAME'] %>"
end

def azure_storage_access_key
"<%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>"
end

def app_name
@app_name ||= Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "").downcase
end
@@ -26,6 +26,12 @@
# if you need to change rackspace_auth_url (e.g. if you need to use Rackspace London)
# config.rackspace_auth_url = "lon.auth.api.rackspacecloud.com"
<%- elsif rackspace? -%>
config.fog_provider = 'AzureRM'
config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME']
config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY']

# config.fog_directory specifies container name of Azure Blob storage
<%- end -%>
config.fog_directory = ENV['FOG_DIRECTORY']
@@ -24,6 +24,12 @@ defaults: &defaults
rackspace_api_key: "<%= rackspace_api_key %>"
# if you need to change rackspace_auth_url (e.g. if you need to use Rackspace London)
# rackspace_auth_url: "https://lon.identity.api.rackspacecloud.com/v2.0"
<%- elsif azure_rm? -%>
fog_provider: 'AzureRM'
azure_storage_account_name: "<%= azure_storage_account_name %>"
azure_storage_access_key: "<%= azure_storage_access_key %>"

# 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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.