carrierwave-aws 1.5.0 → 1.6.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 +4 -4
- data/lib/carrierwave/aws/version.rb +1 -1
- data/lib/carrierwave/storage/aws_file.rb +18 -4
- data/lib/carrierwave/storage/aws_options.rb +1 -0
- data/lib/carrierwave-aws.rb +2 -0
- data/spec/carrierwave/storage/aws_file_spec.rb +30 -1
- data/spec/carrierwave/storage/aws_options_spec.rb +3 -3
- data/spec/carrierwave/support/uri_filename_spec.rb +1 -3
- data/spec/carrierwave-aws_spec.rb +8 -1
- data/spec/features/storing_files_spec.rb +29 -1
- data/spec/spec_helper.rb +8 -3
- metadata +37 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac60b2f92e091d9a99068561005dbf5cd44376269a0e7f101d0a64b2581cd07d
|
4
|
+
data.tar.gz: fdb3e1990f6c8845bfe79fb48c44f7ab4a04d5126a550dfd3d4196bb305344df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ff06f23bfd7ad4486adbaeb788be01ccee910eb4d81a786428034031bae77d069c0088dd55873df599bf9bc148530e800607d846d66827b7cebe5659d82633
|
7
|
+
data.tar.gz: 4eb6671f489ca213531f3c8bb0aa34da3e6ed6658bae7ae3870d95b321614c1d54ee87f277fc237838ddab3ac9dd537c7a2f7ad817fe862a8bb615ae1fe92a3a
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
3
5
|
module CarrierWave
|
4
6
|
module Storage
|
5
7
|
class AWSFile
|
@@ -61,8 +63,8 @@ module CarrierWave
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def copy_to(new_path)
|
64
|
-
|
65
|
-
|
66
|
+
file.copy_to(
|
67
|
+
bucket.object(new_path),
|
66
68
|
aws_options.copy_options(self)
|
67
69
|
)
|
68
70
|
end
|
@@ -79,12 +81,16 @@ module CarrierWave
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def authenticated_url(options = {})
|
84
|
+
if asset_host && asset_host == bucket.name
|
85
|
+
# Can't use https, since plain S3 doesn't support custom TLS certificates
|
86
|
+
options = options.reverse_merge(secure: false, virtual_host: true)
|
87
|
+
end
|
82
88
|
file.presigned_url(:get, aws_options.expiration_options(options))
|
83
89
|
end
|
84
90
|
|
85
91
|
def public_url
|
86
|
-
if
|
87
|
-
"#{
|
92
|
+
if asset_host
|
93
|
+
"#{asset_host}/#{uri_path}"
|
88
94
|
else
|
89
95
|
file.public_url.to_s
|
90
96
|
end
|
@@ -117,6 +123,14 @@ module CarrierWave
|
|
117
123
|
def public?
|
118
124
|
uploader.aws_acl.to_s == 'public-read' || uploader.asset_host_public
|
119
125
|
end
|
126
|
+
|
127
|
+
def asset_host
|
128
|
+
if uploader.asset_host.respond_to? :call
|
129
|
+
uploader.asset_host.call(self)
|
130
|
+
else
|
131
|
+
uploader.asset_host
|
132
|
+
end
|
133
|
+
end
|
120
134
|
end
|
121
135
|
end
|
122
136
|
end
|
data/lib/carrierwave-aws.rb
CHANGED
@@ -86,7 +86,7 @@ describe CarrierWave::Storage::AWSFile do
|
|
86
86
|
allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
|
87
87
|
allow(uploader).to receive(:asset_host_public) { false }
|
88
88
|
|
89
|
-
expect(file).to receive(:presigned_url).with(:get, expires_in: 60)
|
89
|
+
expect(file).to receive(:presigned_url).with(:get, { expires_in: 60 })
|
90
90
|
|
91
91
|
aws_file.url
|
92
92
|
end
|
@@ -110,6 +110,18 @@ describe CarrierWave::Storage::AWSFile do
|
|
110
110
|
|
111
111
|
expect(aws_file.url).to eq('http://example.com/files/1/file.txt')
|
112
112
|
end
|
113
|
+
|
114
|
+
it 'accepts the asset_host given as a proc' do
|
115
|
+
allow(uploader).to receive(:aws_acl) { :'public-read' }
|
116
|
+
allow(uploader).to receive(:asset_host) do
|
117
|
+
proc do |file|
|
118
|
+
expect(file).to be_instance_of(CarrierWave::Storage::AWSFile)
|
119
|
+
'https://example.com'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(aws_file.url).to eq('https://example.com/files/1/file.txt')
|
124
|
+
end
|
113
125
|
end
|
114
126
|
|
115
127
|
describe '#store' do
|
@@ -144,4 +156,21 @@ describe CarrierWave::Storage::AWSFile do
|
|
144
156
|
expect(aws_file.public_url).to eq 'http://example.com/uploads/images/jekyll%2Band%2Bhyde.txt'
|
145
157
|
end
|
146
158
|
end
|
159
|
+
|
160
|
+
describe '#copy_to' do
|
161
|
+
let(:new_s3_object) { instance_double('Aws::S3::Object') }
|
162
|
+
|
163
|
+
it 'copies file to target path' do
|
164
|
+
new_path = 'files/2/file.txt'
|
165
|
+
expect(bucket).to receive(:object).with(new_path).and_return(new_s3_object)
|
166
|
+
expect(file).to receive(:size).at_least(:once).and_return(1024)
|
167
|
+
expect(file).to(
|
168
|
+
receive(:copy_to).with(
|
169
|
+
new_s3_object,
|
170
|
+
aws_file.aws_options.copy_options(aws_file)
|
171
|
+
)
|
172
|
+
)
|
173
|
+
aws_file.copy_to new_path
|
174
|
+
end
|
175
|
+
end
|
147
176
|
end
|
@@ -39,8 +39,8 @@ describe CarrierWave::Storage::AWSOptions do
|
|
39
39
|
write_options = options.write_options(file)
|
40
40
|
|
41
41
|
expect(write_options).to include(
|
42
|
-
acl:
|
43
|
-
content_type:
|
42
|
+
acl: 'public-read',
|
43
|
+
content_type: 'image/png',
|
44
44
|
encryption_key: 'def'
|
45
45
|
)
|
46
46
|
expect(write_options[:body].path).to eq(file.path)
|
@@ -54,7 +54,7 @@ describe CarrierWave::Storage::AWSOptions do
|
|
54
54
|
|
55
55
|
it 'works if aws_attributes is a Proc' do
|
56
56
|
expect(uploader).to receive(:aws_attributes).and_return(
|
57
|
-
-> { { expires:
|
57
|
+
-> { { expires: (Date.today + 7).httpdate } }
|
58
58
|
)
|
59
59
|
|
60
60
|
expect { options.write_options(file) }.to_not raise_error
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CarrierWave::Support::UriFilename do
|
4
|
-
UriFilename = CarrierWave::Support::UriFilename
|
5
|
-
|
6
4
|
describe '.filename' do
|
7
5
|
it 'extracts a decoded filename from file uri' do
|
8
6
|
samples = {
|
@@ -11,7 +9,7 @@ describe CarrierWave::Support::UriFilename do
|
|
11
9
|
}
|
12
10
|
|
13
11
|
samples.each do |uri, name|
|
14
|
-
expect(UriFilename.filename(uri)).to eq(name)
|
12
|
+
expect(CarrierWave::Support::UriFilename.filename(uri)).to eq(name)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -20,7 +20,7 @@ describe CarrierWave::Uploader::Base do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#aws_acl' do
|
23
|
-
it 'allows known
|
23
|
+
it 'allows known access control values' do
|
24
24
|
expect do
|
25
25
|
uploader.aws_acl = 'private'
|
26
26
|
uploader.aws_acl = 'public-read'
|
@@ -28,6 +28,13 @@ describe CarrierWave::Uploader::Base do
|
|
28
28
|
end.not_to raise_exception
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'allows nil' do
|
32
|
+
uploader.aws_acl = 'public-read'
|
33
|
+
expect do
|
34
|
+
uploader.aws_acl = nil
|
35
|
+
end.to change { uploader.aws_acl }.from('public-read').to(nil)
|
36
|
+
end
|
37
|
+
|
31
38
|
it 'does not allow unknown control values' do
|
32
39
|
expect do
|
33
40
|
uploader.aws_acl = 'everybody'
|
@@ -73,7 +73,7 @@ describe 'Storing Files', type: :feature do
|
|
73
73
|
image.close
|
74
74
|
end
|
75
75
|
|
76
|
-
it 'gets a url for remote files' do
|
76
|
+
it 'gets a public url for remote files' do
|
77
77
|
instance.store!(image)
|
78
78
|
instance.retrieve_from_store!('image.png')
|
79
79
|
|
@@ -84,6 +84,34 @@ describe 'Storing Files', type: :feature do
|
|
84
84
|
instance.file.delete
|
85
85
|
end
|
86
86
|
|
87
|
+
it 'gets a private url for remote files' do
|
88
|
+
instance.aws_acl = 'private'
|
89
|
+
instance.store!(image)
|
90
|
+
instance.retrieve_from_store!('image.png')
|
91
|
+
|
92
|
+
expect(instance.url).to include(ENV['S3_BUCKET_NAME'])
|
93
|
+
expect(instance.url).to include(instance.path)
|
94
|
+
expect(instance.url).to include('X-Amz-Signature=')
|
95
|
+
|
96
|
+
image.close
|
97
|
+
instance.file.delete
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'respects asset_host for private urls' do
|
101
|
+
allow(instance).to receive(:asset_host).and_return(ENV['S3_BUCKET_NAME'])
|
102
|
+
instance.aws_acl = 'private'
|
103
|
+
instance.store!(image)
|
104
|
+
instance.retrieve_from_store!('image.png')
|
105
|
+
|
106
|
+
expect(URI.parse(instance.url).scheme).to eq 'http'
|
107
|
+
expect(URI.parse(instance.url).hostname).to eq ENV['S3_BUCKET_NAME']
|
108
|
+
expect(instance.url).to include(instance.path)
|
109
|
+
expect(instance.url).to include('X-Amz-Signature=')
|
110
|
+
|
111
|
+
image.close
|
112
|
+
instance.file.delete
|
113
|
+
end
|
114
|
+
|
87
115
|
it 'uploads the cache file to the configured bucket' do
|
88
116
|
instance.cache!(image)
|
89
117
|
instance.retrieve_from_cache!(instance.cache_name)
|
data/spec/spec_helper.rb
CHANGED
@@ -49,10 +49,15 @@ RSpec.configure do |config|
|
|
49
49
|
cw_config.aws_acl = :'public-read'
|
50
50
|
|
51
51
|
cw_config.aws_credentials = {
|
52
|
-
access_key_id:
|
52
|
+
access_key_id: ENV['S3_ACCESS_KEY'],
|
53
53
|
secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
|
54
|
-
region:
|
55
|
-
}
|
54
|
+
region: ENV['AWS_REGION']
|
55
|
+
}.merge(
|
56
|
+
ENV['CI'] && {
|
57
|
+
endpoint: 'http://127.0.0.1:9000',
|
58
|
+
force_path_style: true
|
59
|
+
} || {}
|
60
|
+
)
|
56
61
|
end
|
57
62
|
end
|
58
63
|
end
|
metadata
CHANGED
@@ -1,55 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sdk-s3
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: carrierwave
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '4'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '2.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: nokogiri
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: rake
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
|
-
- - "
|
65
|
+
- - ">="
|
46
66
|
- !ruby/object:Gem::Version
|
47
67
|
version: '10.0'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
|
-
- - "
|
72
|
+
- - ">="
|
53
73
|
- !ruby/object:Gem::Version
|
54
74
|
version: '10.0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +113,7 @@ homepage: https://github.com/sorentwo/carrierwave-aws
|
|
93
113
|
licenses:
|
94
114
|
- MIT
|
95
115
|
metadata: {}
|
96
|
-
post_install_message:
|
116
|
+
post_install_message:
|
97
117
|
rdoc_options: []
|
98
118
|
require_paths:
|
99
119
|
- lib
|
@@ -101,15 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
121
|
requirements:
|
102
122
|
- - ">="
|
103
123
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
124
|
+
version: 2.5.0
|
105
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
126
|
requirements:
|
107
127
|
- - ">="
|
108
128
|
- !ruby/object:Gem::Version
|
109
129
|
version: '0'
|
110
130
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
-
signing_key:
|
131
|
+
rubygems_version: 3.3.7
|
132
|
+
signing_key:
|
113
133
|
specification_version: 4
|
114
134
|
summary: Native aws-sdk support for S3 in CarrierWave
|
115
135
|
test_files:
|