carrierwave-aws 1.5.0 → 1.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b420ef988503bad151d75b1794b45ef1d3c2906077df034ddbdf067369f003aa
4
- data.tar.gz: 167626ab412b4b49d26927c7044445974120a273c7fda2398faea3f3d549ff0c
3
+ metadata.gz: a5f21a2f65d6fc529886cc06a0b9a796d61775b249655519c0401336b0076383
4
+ data.tar.gz: 7c33f49c78db4c5996e6db75e8841864184db6e9a3c70186a982735f59c5c253
5
5
  SHA512:
6
- metadata.gz: 0f1c69cf12347fa87723f671de01166a1b6373e3863b36acca438f6cc253d1e50cd76f6835c55d860078003d08d9d9692b596d40736f7eade764a458de5cb826
7
- data.tar.gz: c153eaa6992b88e00c34d3eeca7e8666b6f5f9a665a137b365214f3dc2be9520ef8701cbd3a4b6451d854d160466b4a4e16b3469171a0eac2540553f28d3fc5f
6
+ metadata.gz: d5f7d35bfc4eaae8eef5a8c314b175c1e37a0394f19896c5ef96daf38c1d16ae37f269d03cb832f66765cfeba2b05d5339d0b6ea649fc0524e4614fd280268ca
7
+ data.tar.gz: 7277c6e4455acfc23dc2afd4f2e23d25bd5e550606c395151de2a75c969874cfd8b77b492d631c266c28f7f737d3c2a4cd07c679a1a12e404fb3022ec8e916da
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Carrierwave
4
4
  module AWS
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.1'
6
6
  end
7
7
  end
@@ -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
@@ -55,14 +57,19 @@ module CarrierWave
55
57
  def store(new_file)
56
58
  if new_file.is_a?(self.class)
57
59
  new_file.move_to(path)
60
+ elsif Aws::S3.const_defined?(:TransferManager)
61
+ options = aws_options.write_options(new_file).except(:body)
62
+ options[:multipart_threshold] = AWSOptions::MULTIPART_THRESHOLD
63
+ Aws::S3::TransferManager.new(client: connection.client).upload_file(new_file.path, bucket: bucket.name,
64
+ key: path, **options)
58
65
  else
59
66
  file.upload_file(new_file.path, aws_options.write_options(new_file))
60
67
  end
61
68
  end
62
69
 
63
70
  def copy_to(new_path)
64
- bucket.object(new_path).copy_from(
65
- "#{bucket.name}/#{file.key}",
71
+ file.copy_to(
72
+ bucket.object(new_path),
66
73
  aws_options.copy_options(self)
67
74
  )
68
75
  end
@@ -79,12 +86,16 @@ module CarrierWave
79
86
  end
80
87
 
81
88
  def authenticated_url(options = {})
89
+ if asset_host && asset_host == bucket.name
90
+ # Can't use https, since plain S3 doesn't support custom TLS certificates
91
+ options = options.reverse_merge(secure: false, virtual_host: true)
92
+ end
82
93
  file.presigned_url(:get, aws_options.expiration_options(options))
83
94
  end
84
95
 
85
96
  def public_url
86
- if uploader.asset_host
87
- "#{uploader.asset_host}/#{uri_path}"
97
+ if asset_host
98
+ "#{asset_host}/#{uri_path}"
88
99
  else
89
100
  file.public_url.to_s
90
101
  end
@@ -117,6 +128,14 @@ module CarrierWave
117
128
  def public?
118
129
  uploader.aws_acl.to_s == 'public-read' || uploader.asset_host_public
119
130
  end
131
+
132
+ def asset_host
133
+ if uploader.asset_host.respond_to? :call
134
+ uploader.asset_host.call(self)
135
+ else
136
+ uploader.asset_host
137
+ end
138
+ end
120
139
  end
121
140
  end
122
141
  end
@@ -3,7 +3,10 @@
3
3
  module CarrierWave
4
4
  module Storage
5
5
  class AWSOptions
6
- MULTIPART_TRESHOLD = 15 * 1024 * 1024
6
+ MULTIPART_THRESHOLD = 15 * 1024 * 1024
7
+
8
+ # Backward compatibility
9
+ MULTIPART_TRESHOLD = MULTIPART_THRESHOLD
7
10
 
8
11
  attr_reader :uploader
9
12
 
@@ -26,7 +29,7 @@ module CarrierWave
26
29
  def move_options(file)
27
30
  {
28
31
  acl: uploader.aws_acl,
29
- multipart_copy: file.size >= MULTIPART_TRESHOLD
32
+ multipart_copy: file.size >= MULTIPART_THRESHOLD
30
33
  }.merge(aws_attributes).merge(aws_write_options)
31
34
  end
32
35
  alias copy_options move_options
@@ -42,6 +45,7 @@ module CarrierWave
42
45
  def aws_attributes
43
46
  attributes = uploader.aws_attributes
44
47
  return {} if attributes.nil?
48
+
45
49
  attributes.respond_to?(:call) ? attributes.call : attributes
46
50
  end
47
51
 
@@ -40,6 +40,8 @@ module CarrierWave
40
40
  end
41
41
 
42
42
  def self.normalized_acl(acl)
43
+ return nil if acl.nil?
44
+
43
45
  normalized = acl.to_s.downcase.sub('_', '-')
44
46
 
45
47
  unless ACCEPTED_ACL.include?(normalized)
@@ -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
@@ -129,9 +141,36 @@ describe CarrierWave::Storage::AWSFile do
129
141
  CarrierWave::SanitizedFile.new('spec/fixtures/image.png')
130
142
  end
131
143
 
132
- it 'uploads the file using with multipart support' do
133
- expect(file).to(receive(:upload_file)
134
- .with(new_file.path, an_instance_of(Hash)))
144
+ it 'uploads the file using TransferManager' do
145
+ client = instance_double('Aws::S3::Client')
146
+
147
+ allow(bucket).to receive(:name).and_return('example-com')
148
+ allow(connection).to receive(:client).and_return(client)
149
+
150
+ if Aws::S3.const_defined?(:TransferManager)
151
+ transfer_manager = instance_double('Aws::S3::TransferManager')
152
+ allow(Aws::S3::TransferManager).to receive(:new).with(client: client).and_return(transfer_manager)
153
+
154
+ expect(transfer_manager).to receive(:upload_file).with(
155
+ new_file.path,
156
+ bucket: 'example-com',
157
+ key: path,
158
+ acl: :'public-read',
159
+ content_type: new_file.content_type,
160
+ encryption_key: 'def',
161
+ multipart_threshold: CarrierWave::Storage::AWSOptions::MULTIPART_THRESHOLD
162
+ )
163
+ else
164
+ expect(file).to receive(:upload_file).with(
165
+ new_file.path,
166
+ hash_including(
167
+ acl: :'public-read',
168
+ content_type: new_file.content_type,
169
+ encryption_key: 'def'
170
+ )
171
+ )
172
+ end
173
+
135
174
  aws_file.store(new_file)
136
175
  end
137
176
  end
@@ -144,4 +183,21 @@ describe CarrierWave::Storage::AWSFile do
144
183
  expect(aws_file.public_url).to eq 'http://example.com/uploads/images/jekyll%2Band%2Bhyde.txt'
145
184
  end
146
185
  end
186
+
187
+ describe '#copy_to' do
188
+ let(:new_s3_object) { instance_double('Aws::S3::Object') }
189
+
190
+ it 'copies file to target path' do
191
+ new_path = 'files/2/file.txt'
192
+ expect(bucket).to receive(:object).with(new_path).and_return(new_s3_object)
193
+ expect(file).to receive(:size).at_least(:once).and_return(1024)
194
+ expect(file).to(
195
+ receive(:copy_to).with(
196
+ new_s3_object,
197
+ aws_file.aws_options.copy_options(aws_file)
198
+ )
199
+ )
200
+ aws_file.copy_to new_path
201
+ end
202
+ end
147
203
  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: 'public-read',
43
- content_type: 'image/png',
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: 1.week.from_now.httpdate } }
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 acess control values' do
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: ENV['S3_ACCESS_KEY'],
52
+ access_key_id: ENV['S3_ACCESS_KEY'],
53
53
  secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
54
- region: ENV['AWS_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.5.0
4
+ version: 1.6.1
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: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2026-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: carrierwave
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: '2.0'
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: '2.0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: aws-sdk-s3
28
+ name: carrierwave
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
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: '1.0'
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: '0'
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.0.3
112
- signing_key:
131
+ rubygems_version: 3.5.22
132
+ signing_key:
113
133
  specification_version: 4
114
134
  summary: Native aws-sdk support for S3 in CarrierWave
115
135
  test_files: