Skip to content

Commit 6d256ee

Browse files
author
Sven Felix Oberquelle
committed
Add development-storage support
1 parent 2494c09 commit 6d256ee

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

lib/paperclip/storage/azure.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@ def self.extended base
8383

8484
def expiring_url(time = 3600, style_name = default_style)
8585
if path(style_name)
86-
uri = URI azure_uri(style_name)
86+
uri = URI "#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}"
8787
generator = ::Azure::Storage::Core::Auth::SharedAccessSignature.new azure_account_name,
88-
azure_credentials[:storage_access_key]
88+
azure_storage_client.storage_access_key
8989

9090
generator.signed_uri uri, false, service: 'b',
9191
resource: 'b',
9292
permissions: 'r',
9393
start: (Time.now - (5 * 60)).utc.iso8601,
9494
expiry: (Time.now + time).utc.iso8601
95+
azure_interface.generate_uri uri.path, CGI::parse(uri.query || "")
9596
else
9697
url(style_name)
9798
end
@@ -107,10 +108,7 @@ def azure_credentials
107108
end
108109

109110
def azure_account_name
110-
account_name = @options[:azure_storage_account_name] || azure_credentials[:storage_account_name]
111-
account_name = account_name.call(self) if account_name.is_a?(Proc)
112-
113-
account_name
111+
azure_storage_client.storage_account_name
114112
end
115113

116114
def container_name
@@ -132,15 +130,17 @@ def azure_interface
132130
end
133131

134132
def azure_storage_client
135-
config = {}
133+
@azure_storage_client ||= begin
134+
config = {}
136135

137-
[:storage_account_name, :storage_access_key].each do |opt|
138-
config[opt] = azure_credentials[opt] if azure_credentials[opt]
139-
end
136+
[:storage_account_name, :storage_access_key, :use_development_storage].each do |opt|
137+
config[opt] = azure_credentials[opt] if azure_credentials[opt]
138+
end
140139

141-
config[:storage_blob_host] = "https://#{azure_base_url}"
140+
config[:storage_blob_host] = "https://#{Environment.url_for azure_account_name, azure_credentials[:region]}" if azure_credentials[:region]
142141

143-
@azure_storage_client ||= ::Azure::Storage::Client.create config
142+
::Azure::Storage::Client.create config
143+
end
144144
end
145145

146146
def obtain_azure_instance_for(options)
@@ -154,7 +154,7 @@ def obtain_azure_instance_for(options)
154154
end
155155

156156
def azure_uri(style_name = default_style)
157-
"https://#{azure_base_url}/#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}"
157+
"#{azure_storage_client.storage_blob_host}/#{container_name}/#{path(style_name).gsub(%r{\A/}, '')}"
158158
end
159159

160160
def azure_base_url

spec/paperclip/storage/azure_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
container: "container",
110110
path: ":attachment/:basename:dotextension",
111111
azure_credentials: {
112-
'access_key_id' => "12345",
113-
'secret_access_key' => "54321"
112+
storage_account_name: 'storage',
113+
storage_access_key: storage_access_key
114114
}
115115

116116
File.open(fixture_file('5k.png'), 'rb') do |file|
@@ -136,7 +136,8 @@
136136
styles: { large: ["500x500#", :jpg] },
137137
container: "container",
138138
azure_credentials: {
139-
"storage_access_key" => "54321"
139+
storage_account_name: 'storage',
140+
storage_access_key: storage_access_key
140141
}
141142

142143
File.open(fixture_file("spaced file.png"), "rb") do |file|
@@ -162,18 +163,17 @@
162163
styles: { large: ['500x500#', :jpg] },
163164
container: "container",
164165
azure_credentials: {
165-
'storage_access_key' => "54321"
166+
storage_account_name: 'storage',
167+
storage_access_key: storage_access_key
166168
}
167169

168-
stringio = stringy_file
169-
class << stringio
170+
file = stringy_file
171+
class << file
170172
def original_filename
171173
"question?mark.png"
172174
end
173175
end
174176

175-
file = Paperclip.io_adapters.for(stringio)
176-
177177
@dummy = Dummy.new
178178
@dummy.avatar = file
179179
@dummy.save

0 commit comments

Comments
 (0)