dragonfly-s3_data_store 1.1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/lib/dragonfly/s3_data_store.rb +4 -3
- data/lib/dragonfly/s3_data_store/version.rb +1 -1
- data/spec/s3_data_store_spec.rb +11 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 768cec2575b167242c6c5bf6b02313d61add3dbe
|
4
|
+
data.tar.gz: dfa4bc29b433f342556df40ba346a4967b915265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c5156cd14a58c7feeeb580cd4d79125071a9bf543df232828c88a6c4e3c5351587aa8d0dfc1a386cbbedf77eadebef2df379820322ef3e9a5b570f322cbd1a
|
7
|
+
data.tar.gz: 3dd4be70964435582b15ff3bd2fe15f06e28383dd6e974b63cfb4002639bda5385b0d13ccf83a5e2320afda29fedf92faa958b6a3f2b5780f240ad6ad5f0a814
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
Amazon AWS S3 data store for use with the [Dragonfly](http://github.com/markevans/dragonfly) gem.
|
4
4
|
|
5
|
+
**NOTE:** version 1.2 saves files into a different directory structure, e.g. '2015/08/03/5bccfdd8-0de2-4efc-b3f3-f4e96bcc4afa/file.png' rather than '2015/08/03/12/03/24/492/file.png'.
|
6
|
+
|
7
|
+
However this does not affect any functionality and won't break any of your old content!
|
8
|
+
It's just more robust.
|
9
|
+
|
5
10
|
## Gemfile
|
6
11
|
|
7
12
|
```ruby
|
@@ -43,7 +48,7 @@ end
|
|
43
48
|
|
44
49
|
### Per-storage options
|
45
50
|
```ruby
|
46
|
-
Dragonfly.app.store(some_file, path: 'some/path.txt', headers: {'x-amz-acl' => 'public-read-write'})
|
51
|
+
Dragonfly.app.store(some_file, {'some' => 'metadata'}, path: 'some/path.txt', headers: {'x-amz-acl' => 'public-read-write'})
|
47
52
|
```
|
48
53
|
|
49
54
|
or
|
@@ -95,3 +100,9 @@ or with a custom host:
|
|
95
100
|
```ruby
|
96
101
|
my_model.attachment.remote_url(host: 'custom.domain') # also configurable for all urls with 'url_host'
|
97
102
|
```
|
103
|
+
|
104
|
+
or with other query parameters (needs an expiry):
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
my_model.attachment.remote_url(expires: 3.days.from_now, query: {'response-content-disposition' => 'attachment'}) # URL that downloads the file
|
108
|
+
```
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fog/aws'
|
2
2
|
require 'dragonfly'
|
3
3
|
require 'cgi'
|
4
|
+
require 'securerandom'
|
4
5
|
|
5
6
|
Dragonfly::App.register_datastore(:s3){ Dragonfly::S3DataStore }
|
6
7
|
|
@@ -71,8 +72,8 @@ module Dragonfly
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def url_for(uid, opts={})
|
74
|
-
if opts[:expires]
|
75
|
-
storage.get_object_https_url(bucket_name, full_path(uid), opts[:
|
75
|
+
if expires = opts[:expires]
|
76
|
+
storage.get_object_https_url(bucket_name, full_path(uid), expires, {:query => opts[:query]})
|
76
77
|
else
|
77
78
|
scheme = opts[:scheme] || url_scheme
|
78
79
|
host = opts[:host] || url_host || (
|
@@ -136,7 +137,7 @@ module Dragonfly
|
|
136
137
|
end
|
137
138
|
|
138
139
|
def generate_uid(name)
|
139
|
-
"#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{
|
140
|
+
"#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{SecureRandom.uuid}/#{name}"
|
140
141
|
end
|
141
142
|
|
142
143
|
def full_path(uid)
|
data/spec/s3_data_store_spec.rb
CHANGED
@@ -196,20 +196,6 @@ describe Dragonfly::S3DataStore do
|
|
196
196
|
@data_store.storage.should_receive(:delete_object).with(BUCKET_NAME, /^some\/path\/.*\/something\.png$/)
|
197
197
|
@data_store.destroy(uid)
|
198
198
|
end
|
199
|
-
|
200
|
-
describe "url_for" do
|
201
|
-
before do
|
202
|
-
@uid = @data_store.write(content)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "returns the uid prefixed with the root_path" do
|
206
|
-
@data_store.url_for(@uid).should =~ /some\/path\/.*\/something\.png/
|
207
|
-
end
|
208
|
-
|
209
|
-
it "gives an expiring url" do
|
210
|
-
@data_store.url_for(@uid, :expires => 1301476942).should =~ /\/some\/path\/.*\/something\.png\?X-Amz-Expires=/
|
211
|
-
end
|
212
|
-
end
|
213
199
|
end
|
214
200
|
|
215
201
|
describe "autocreating the bucket" do
|
@@ -291,7 +277,12 @@ describe Dragonfly::S3DataStore do
|
|
291
277
|
|
292
278
|
it "should give an expiring url" do
|
293
279
|
@data_store.url_for(@uid, :expires => 1301476942).should =~
|
294
|
-
%r{^https://#{BUCKET_NAME}\.#{@data_store.domain}/some/path/on/s3
|
280
|
+
%r{^https://#{BUCKET_NAME}\.#{@data_store.domain}/some/path/on/s3\?.*X-Amz-Expires=}
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should add query params" do
|
284
|
+
@data_store.url_for(@uid, :expires => 1301476942, :query => {'response-content-disposition' => 'attachment'}).should =~
|
285
|
+
%r{^https://#{BUCKET_NAME}\.#{@data_store.domain}/some/path/on/s3\?.*response-content-disposition=attachment}
|
295
286
|
end
|
296
287
|
|
297
288
|
it "should allow for using https" do
|
@@ -342,12 +333,13 @@ describe Dragonfly::S3DataStore do
|
|
342
333
|
|
343
334
|
describe "fog_storage_options" do
|
344
335
|
it "adds options to Fog::Storage object" do
|
336
|
+
allow(Fog::Storage).to receive(:new).and_call_original
|
345
337
|
@data_store.fog_storage_options = {:random_option => 'look at me!'}
|
346
|
-
Fog::Storage.should_receive(:new).with do |hash|
|
347
|
-
hash[:random_option].should == 'look at me!'
|
348
|
-
hash[:aws_access_key_id].should match /\w+/
|
349
|
-
end.and_call_original
|
350
338
|
@data_store.storage
|
339
|
+
expect(Fog::Storage).to have_received(:new).with(hash_including(
|
340
|
+
:random_option => 'look at me!',
|
341
|
+
:aws_access_key_id => anything
|
342
|
+
))
|
351
343
|
end
|
352
344
|
end
|
353
345
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly-s3_data_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|