carrierwave-aws 1.3.0 → 1.5.0
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 +5 -5
- data/lib/carrierwave-aws.rb +9 -0
- data/lib/carrierwave/aws/version.rb +1 -1
- data/lib/carrierwave/storage/aws_file.rb +15 -7
- data/lib/carrierwave/storage/aws_options.rb +13 -1
- data/lib/carrierwave/support/uri_filename.rb +1 -1
- data/spec/carrierwave-aws_spec.rb +39 -0
- data/spec/carrierwave/storage/aws_file_spec.rb +18 -0
- data/spec/carrierwave/storage/aws_options_spec.rb +8 -0
- metadata +5 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b420ef988503bad151d75b1794b45ef1d3c2906077df034ddbdf067369f003aa
|
4
|
+
data.tar.gz: 167626ab412b4b49d26927c7044445974120a273c7fda2398faea3f3d549ff0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f1c69cf12347fa87723f671de01166a1b6373e3863b36acca438f6cc253d1e50cd76f6835c55d860078003d08d9d9692b596d40736f7eade764a458de5cb826
|
7
|
+
data.tar.gz: c153eaa6992b88e00c34d3eeca7e8666b6f5f9a665a137b365214f3dc2be9520ef8701cbd3a4b6451d854d160466b4a4e16b3469171a0eac2540553f28d3fc5f
|
data/lib/carrierwave-aws.rb
CHANGED
@@ -29,6 +29,7 @@ module CarrierWave
|
|
29
29
|
add_config :aws_write_options
|
30
30
|
add_config :aws_acl
|
31
31
|
add_config :aws_signer
|
32
|
+
add_config :asset_host_public
|
32
33
|
|
33
34
|
configure do |config|
|
34
35
|
config.storage_engines[:aws] = 'CarrierWave::Storage::AWS'
|
@@ -83,6 +84,14 @@ module CarrierWave
|
|
83
84
|
self.class.aws_signer
|
84
85
|
end
|
85
86
|
end
|
87
|
+
|
88
|
+
def asset_host_public
|
89
|
+
if instance_variable_defined?('@asset_host_public')
|
90
|
+
@asset_host_public
|
91
|
+
else
|
92
|
+
self.class.asset_host_public
|
93
|
+
end || false
|
94
|
+
end
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
@@ -62,15 +62,15 @@ module CarrierWave
|
|
62
62
|
|
63
63
|
def copy_to(new_path)
|
64
64
|
bucket.object(new_path).copy_from(
|
65
|
-
|
66
|
-
|
65
|
+
"#{bucket.name}/#{file.key}",
|
66
|
+
aws_options.copy_options(self)
|
67
67
|
)
|
68
68
|
end
|
69
69
|
|
70
70
|
def move_to(new_path)
|
71
71
|
file.move_to(
|
72
72
|
"#{bucket.name}/#{new_path}",
|
73
|
-
|
73
|
+
aws_options.move_options(self)
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
@@ -84,7 +84,7 @@ module CarrierWave
|
|
84
84
|
|
85
85
|
def public_url
|
86
86
|
if uploader.asset_host
|
87
|
-
"#{uploader.asset_host}/#{
|
87
|
+
"#{uploader.asset_host}/#{uri_path}"
|
88
88
|
else
|
89
89
|
file.public_url.to_s
|
90
90
|
end
|
@@ -93,10 +93,10 @@ module CarrierWave
|
|
93
93
|
def url(options = {})
|
94
94
|
if signer
|
95
95
|
signed_url(options)
|
96
|
-
elsif
|
97
|
-
authenticated_url(options)
|
98
|
-
else
|
96
|
+
elsif public?
|
99
97
|
public_url
|
98
|
+
else
|
99
|
+
authenticated_url(options)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -109,6 +109,14 @@ module CarrierWave
|
|
109
109
|
def signer
|
110
110
|
uploader.aws_signer
|
111
111
|
end
|
112
|
+
|
113
|
+
def uri_path
|
114
|
+
path.gsub(%r{[^/]+}) { |segment| Seahorse::Util.uri_escape(segment) }
|
115
|
+
end
|
116
|
+
|
117
|
+
def public?
|
118
|
+
uploader.aws_acl.to_s == 'public-read' || uploader.asset_host_public
|
119
|
+
end
|
112
120
|
end
|
113
121
|
end
|
114
122
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Storage
|
5
5
|
class AWSOptions
|
6
|
+
MULTIPART_TRESHOLD = 15 * 1024 * 1024
|
7
|
+
|
6
8
|
attr_reader :uploader
|
7
9
|
|
8
10
|
def initialize(uploader)
|
@@ -21,6 +23,14 @@ module CarrierWave
|
|
21
23
|
}.merge(aws_attributes).merge(aws_write_options)
|
22
24
|
end
|
23
25
|
|
26
|
+
def move_options(file)
|
27
|
+
{
|
28
|
+
acl: uploader.aws_acl,
|
29
|
+
multipart_copy: file.size >= MULTIPART_TRESHOLD
|
30
|
+
}.merge(aws_attributes).merge(aws_write_options)
|
31
|
+
end
|
32
|
+
alias copy_options move_options
|
33
|
+
|
24
34
|
def expiration_options(options = {})
|
25
35
|
uploader_expiration = uploader.aws_authenticated_url_expiration
|
26
36
|
|
@@ -30,7 +40,9 @@ module CarrierWave
|
|
30
40
|
private
|
31
41
|
|
32
42
|
def aws_attributes
|
33
|
-
uploader.aws_attributes
|
43
|
+
attributes = uploader.aws_attributes
|
44
|
+
return {} if attributes.nil?
|
45
|
+
attributes.respond_to?(:call) ? attributes.call : attributes
|
34
46
|
end
|
35
47
|
|
36
48
|
def aws_read_options
|
@@ -138,4 +138,43 @@ describe CarrierWave::Uploader::Base do
|
|
138
138
|
expect(uploader.aws_signer).to eql(signer_proc)
|
139
139
|
end
|
140
140
|
end
|
141
|
+
|
142
|
+
describe '#asset_host_public' do
|
143
|
+
it 'can be overridden on an instance level' do
|
144
|
+
instance = uploader.new
|
145
|
+
|
146
|
+
uploader.asset_host_public = true
|
147
|
+
instance.asset_host_public = false
|
148
|
+
|
149
|
+
expect(uploader.asset_host_public).to eq(true)
|
150
|
+
expect(instance.asset_host_public).to eq(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'can be looked up from superclass' do
|
154
|
+
uploader.asset_host_public = true
|
155
|
+
instance = derived_uploader.new
|
156
|
+
|
157
|
+
expect(derived_uploader.asset_host_public).to eq(true)
|
158
|
+
expect(instance.asset_host_public).to eq(true)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'can be overridden on a class level' do
|
162
|
+
uploader.asset_host_public = true
|
163
|
+
derived_uploader.asset_host_public = false
|
164
|
+
|
165
|
+
base = uploader.new
|
166
|
+
expect(base.asset_host_public).to eq(true)
|
167
|
+
|
168
|
+
instance = derived_uploader.new
|
169
|
+
expect(instance.asset_host_public).to eq(false)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'can be set with the configure block' do
|
173
|
+
uploader.configure do |config|
|
174
|
+
config.asset_host_public = true
|
175
|
+
end
|
176
|
+
|
177
|
+
expect(uploader.asset_host_public).to eq(true)
|
178
|
+
end
|
179
|
+
end
|
141
180
|
end
|
@@ -72,9 +72,19 @@ describe CarrierWave::Storage::AWSFile do
|
|
72
72
|
aws_file.url
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'requests a public url if asset_host_public' do
|
76
|
+
allow(uploader).to receive(:aws_acl) { :'authenticated-read' }
|
77
|
+
allow(uploader).to receive(:asset_host_public) { true }
|
78
|
+
|
79
|
+
expect(file).to receive(:public_url)
|
80
|
+
|
81
|
+
aws_file.url
|
82
|
+
end
|
83
|
+
|
75
84
|
it 'requests an authenticated url if acl is not public readable' do
|
76
85
|
allow(uploader).to receive(:aws_acl) { :private }
|
77
86
|
allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
|
87
|
+
allow(uploader).to receive(:asset_host_public) { false }
|
78
88
|
|
79
89
|
expect(file).to receive(:presigned_url).with(:get, expires_in: 60)
|
80
90
|
|
@@ -126,4 +136,12 @@ describe CarrierWave::Storage::AWSFile do
|
|
126
136
|
end
|
127
137
|
end
|
128
138
|
end
|
139
|
+
|
140
|
+
describe '#public_url' do
|
141
|
+
it 'uri-encodes the path' do
|
142
|
+
allow(uploader).to receive(:asset_host) { 'http://example.com' }
|
143
|
+
aws_file.path = 'uploads/images/jekyll+and+hyde.txt'
|
144
|
+
expect(aws_file.public_url).to eq 'http://example.com/uploads/images/jekyll%2Band%2Bhyde.txt'
|
145
|
+
end
|
146
|
+
end
|
129
147
|
end
|
@@ -52,6 +52,14 @@ describe CarrierWave::Storage::AWSOptions do
|
|
52
52
|
expect { options.write_options(file) }.to_not raise_error
|
53
53
|
end
|
54
54
|
|
55
|
+
it 'works if aws_attributes is a Proc' do
|
56
|
+
expect(uploader).to receive(:aws_attributes).and_return(
|
57
|
+
-> { { expires: 1.week.from_now.httpdate } }
|
58
|
+
)
|
59
|
+
|
60
|
+
expect { options.write_options(file) }.to_not raise_error
|
61
|
+
end
|
62
|
+
|
55
63
|
it 'works if aws_write_options is nil' do
|
56
64
|
expect(uploader).to receive(:aws_write_options) { nil }
|
57
65
|
|
metadata
CHANGED
@@ -1,33 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.7'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '2.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.7'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: '2.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
@@ -114,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
108
|
- !ruby/object:Gem::Version
|
115
109
|
version: '0'
|
116
110
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.5.2.1
|
111
|
+
rubygems_version: 3.0.3
|
119
112
|
signing_key:
|
120
113
|
specification_version: 4
|
121
114
|
summary: Native aws-sdk support for S3 in CarrierWave
|