diff --git a/README.md b/README.md index e678b83..17d245d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ home :: https://github.com/supportify/paperclip-azure code :: https://github.com/supportify/paperclip-azure -rdoc :: https://www.rubydoc.info/docs/paperclip-azure +rdoc :: http://www.rubydoc.info/github/supportify/paperclip-azure/master/ bugs :: https://github.com/supportify/paperclip-azure/issues == DESCRIPTION: diff --git a/Rakefile b/Rakefile index 01c02d8..5b0a981 100644 --- a/Rakefile +++ b/Rakefile @@ -14,18 +14,23 @@ Hoe.spec "paperclip-azure" do license "MIT" # this should match the license in the README extra_deps << ['azure', '~> 0.7'] - extra_deps << ['azure-storage', '~> 0.12'] + extra_deps << ['azure-storage', '~> 0.15.0.preview'] extra_deps << ['hashie', '~> 3.5'] extra_deps << ['addressable', '~> 2.5'] extra_dev_deps << ['paperclip', '>= 4.3.6'] extra_dev_deps << ['sqlite3', '~> 1.3.8'] extra_dev_deps << ['rspec', '~> 3.0'] - extra_dev_deps << ['simplecov', '~> 0.14'] + extra_dev_deps << ['simplecov', '~> 0.16'] extra_dev_deps << ['activerecord', '>= 4.2.0'] extra_dev_deps << ['activerecord-import', '~> 0.19'] extra_dev_deps << ['activemodel', '>= 4.2.0'] extra_dev_deps << ['activesupport', '>= 4.2.0'] + extra_dev_deps << ['hoe'] + extra_dev_deps << ['hoe-bundler'] + extra_dev_deps << ['hoe-gemspec'] + extra_dev_deps << ['hoe-git'] + extra_dev_deps << ['hoe-rubygems'] end # vim: syntax=ruby diff --git a/lib/paperclip/azure.rb b/lib/paperclip/azure.rb index b01ccca..6465b1a 100644 --- a/lib/paperclip/azure.rb +++ b/lib/paperclip/azure.rb @@ -1,5 +1,5 @@ module Paperclip; end class Paperclip::Azure - VERSION = "1.0.3" + VERSION = "1.0.4" end diff --git a/lib/paperclip/storage/azure.rb b/lib/paperclip/storage/azure.rb index 9a922bb..6e83c44 100644 --- a/lib/paperclip/storage/azure.rb +++ b/lib/paperclip/storage/azure.rb @@ -83,15 +83,16 @@ def self.extended base def expiring_url(time = 3600, style_name = default_style) if path(style_name) - uri = URI azure_uri(style_name) + uri = URI "#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}" generator = ::Azure::Storage::Core::Auth::SharedAccessSignature.new azure_account_name, - azure_credentials[:storage_access_key] + azure_storage_client.storage_access_key - generator.signed_uri uri, false, service: 'b', + uri = generator.signed_uri uri, false, service: 'b', resource: 'b', permissions: 'r', start: (Time.now - (5 * 60)).utc.iso8601, expiry: (Time.now + time).utc.iso8601 + azure_interface.generate_uri(uri.path, CGI::parse(uri.query || "")).to_s else url(style_name) end @@ -107,10 +108,7 @@ def azure_credentials end def azure_account_name - account_name = @options[:azure_storage_account_name] || azure_credentials[:storage_account_name] - account_name = account_name.call(self) if account_name.is_a?(Proc) - - account_name + azure_storage_client.storage_account_name end def container_name @@ -132,13 +130,17 @@ def azure_interface end def azure_storage_client - config = {} + @azure_storage_client ||= begin + config = {} - [:storage_account_name, :storage_access_key].each do |opt| - config[opt] = azure_credentials[opt] if azure_credentials[opt] - end + [:storage_account_name, :storage_access_key, :use_development_storage].each do |opt| + config[opt] = azure_credentials[opt] if azure_credentials[opt] + end + + config[:storage_blob_host] = "https://#{Environment.url_for azure_credentials[:storage_account_name], azure_credentials[:region]}" if azure_credentials[:region] - @azure_storage_client ||= ::Azure::Storage::Client.create config + ::Azure::Storage::Client.create config + end end def obtain_azure_instance_for(options) @@ -152,7 +154,8 @@ def obtain_azure_instance_for(options) end def azure_uri(style_name = default_style) - "https://#{azure_base_url}/#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}" + uri = URI "#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}" + azure_interface.generate_uri uri.path, CGI::parse(uri.query || "") end def azure_base_url diff --git a/lib/paperclip/storage/azure/environment.rb b/lib/paperclip/storage/azure/environment.rb index 2abc73b..00abf7d 100644 --- a/lib/paperclip/storage/azure/environment.rb +++ b/lib/paperclip/storage/azure/environment.rb @@ -11,7 +11,7 @@ class Environment } def self.url_for(account_name, region = nil) - "#{account_name}.blob.#{ENVIRONMENT_SUFFIX[region || :global]}" + "#{account_name}.blob.#{ENVIRONMENT_SUFFIX[(region || :global).to_sym]}" end end end diff --git a/spec/paperclip/storage/azure_spec.rb b/spec/paperclip/storage/azure_spec.rb index 7fe586c..0e1bb74 100644 --- a/spec/paperclip/storage/azure_spec.rb +++ b/spec/paperclip/storage/azure_spec.rb @@ -109,8 +109,8 @@ container: "container", path: ":attachment/:basename:dotextension", azure_credentials: { - 'access_key_id' => "12345", - 'secret_access_key' => "54321" + storage_account_name: 'storage', + storage_access_key: storage_access_key } File.open(fixture_file('5k.png'), 'rb') do |file| @@ -136,7 +136,8 @@ styles: { large: ["500x500#", :jpg] }, container: "container", azure_credentials: { - "storage_access_key" => "54321" + storage_account_name: 'storage', + storage_access_key: storage_access_key } File.open(fixture_file("spaced file.png"), "rb") do |file| @@ -162,18 +163,17 @@ styles: { large: ['500x500#', :jpg] }, container: "container", azure_credentials: { - 'storage_access_key' => "54321" + storage_account_name: 'storage', + storage_access_key: storage_access_key } - stringio = stringy_file - class << stringio + file = stringy_file + class << file def original_filename "question?mark.png" end end - file = Paperclip.io_adapters.for(stringio) - @dummy = Dummy.new @dummy.avatar = file @dummy.save