carrierwave-aws 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df1b2dd13c2fe5d10191144d8a709b4669783478e51cd099d516b9df8fa70fa1
4
- data.tar.gz: 272ee0bea417ba78fae9ea98b4ec87a89483d8c7308630c6489cccf722442385
3
+ metadata.gz: ac60b2f92e091d9a99068561005dbf5cd44376269a0e7f101d0a64b2581cd07d
4
+ data.tar.gz: fdb3e1990f6c8845bfe79fb48c44f7ab4a04d5126a550dfd3d4196bb305344df
5
5
  SHA512:
6
- metadata.gz: ed978e69ba5751cb793fa2c63afd075c6c8e4a608de7d36999a0b9c5a8b06e4aaf42391ec211d98d21186e402cb147bf39629de28e328bf51e64c156b88fffa9
7
- data.tar.gz: '09961c9485558f613c1ce426812375b2f30d87e91042675dc3021a8dfa98c5be2a24959fa234276c55ac1612c5b4515a2674b57717cb7314b96b8e54cea552c4'
6
+ metadata.gz: d3ff06f23bfd7ad4486adbaeb788be01ccee910eb4d81a786428034031bae77d069c0088dd55873df599bf9bc148530e800607d846d66827b7cebe5659d82633
7
+ data.tar.gz: 4eb6671f489ca213531f3c8bb0aa34da3e6ed6658bae7ae3870d95b321614c1d54ee87f277fc237838ddab3ac9dd537c7a2f7ad817fe862a8bb615ae1fe92a3a
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Carrierwave
4
4
  module AWS
5
- VERSION = '1.4.0'
5
+ VERSION = '1.6.0'
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
@@ -61,8 +63,8 @@ module CarrierWave
61
63
  end
62
64
 
63
65
  def copy_to(new_path)
64
- bucket.object(new_path).copy_from(
65
- "#{bucket.name}/#{file.key}",
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 uploader.asset_host
87
- "#{uploader.asset_host}/#{uri_path}"
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
@@ -42,6 +42,7 @@ module CarrierWave
42
42
  def aws_attributes
43
43
  attributes = uploader.aws_attributes
44
44
  return {} if attributes.nil?
45
+
45
46
  attributes.respond_to?(:call) ? attributes.call : attributes
46
47
  end
47
48
 
@@ -6,7 +6,7 @@ module CarrierWave
6
6
  def self.filename(url)
7
7
  path = url.split('?').first
8
8
 
9
- URI.decode(path).gsub(%r{.*/(.*?$)}, '\1')
9
+ CGI.unescape(path).gsub(%r{.*/(.*?$)}, '\1')
10
10
  end
11
11
  end
12
12
  end
@@ -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 +88,11 @@ module CarrierWave
86
88
  end
87
89
 
88
90
  def asset_host_public
89
- @asset_host_public || false
91
+ if instance_variable_defined?('@asset_host_public')
92
+ @asset_host_public
93
+ else
94
+ self.class.asset_host_public
95
+ end || false
90
96
  end
91
97
  end
92
98
  end
@@ -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: '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'
@@ -138,4 +145,43 @@ describe CarrierWave::Uploader::Base do
138
145
  expect(uploader.aws_signer).to eql(signer_proc)
139
146
  end
140
147
  end
148
+
149
+ describe '#asset_host_public' do
150
+ it 'can be overridden on an instance level' do
151
+ instance = uploader.new
152
+
153
+ uploader.asset_host_public = true
154
+ instance.asset_host_public = false
155
+
156
+ expect(uploader.asset_host_public).to eq(true)
157
+ expect(instance.asset_host_public).to eq(false)
158
+ end
159
+
160
+ it 'can be looked up from superclass' do
161
+ uploader.asset_host_public = true
162
+ instance = derived_uploader.new
163
+
164
+ expect(derived_uploader.asset_host_public).to eq(true)
165
+ expect(instance.asset_host_public).to eq(true)
166
+ end
167
+
168
+ it 'can be overridden on a class level' do
169
+ uploader.asset_host_public = true
170
+ derived_uploader.asset_host_public = false
171
+
172
+ base = uploader.new
173
+ expect(base.asset_host_public).to eq(true)
174
+
175
+ instance = derived_uploader.new
176
+ expect(instance.asset_host_public).to eq(false)
177
+ end
178
+
179
+ it 'can be set with the configure block' do
180
+ uploader.configure do |config|
181
+ config.asset_host_public = true
182
+ end
183
+
184
+ expect(uploader.asset_host_public).to eq(true)
185
+ end
186
+ end
141
187
  end
@@ -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,61 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
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: 2019-09-04 00:00:00.000000000 Z
11
+ date: 2023-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-s3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: carrierwave
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '0.7'
33
+ version: '2.0'
20
34
  - - "<"
21
35
  - !ruby/object:Gem::Version
22
- version: '2.1'
36
+ version: '4'
23
37
  type: :runtime
24
38
  prerelease: false
25
39
  version_requirements: !ruby/object:Gem::Requirement
26
40
  requirements:
27
41
  - - ">="
28
42
  - !ruby/object:Gem::Version
29
- version: '0.7'
43
+ version: '2.0'
30
44
  - - "<"
31
45
  - !ruby/object:Gem::Version
32
- version: '2.1'
46
+ version: '4'
33
47
  - !ruby/object:Gem::Dependency
34
- name: aws-sdk-s3
48
+ name: nokogiri
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
- - - "~>"
51
+ - - ">="
38
52
  - !ruby/object:Gem::Version
39
- version: '1.0'
40
- type: :runtime
53
+ version: '0'
54
+ type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
- - - "~>"
58
+ - - ">="
45
59
  - !ruby/object:Gem::Version
46
- version: '1.0'
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
- - - "~>"
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  version: '10.0'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
- - - "~>"
72
+ - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: '10.0'
61
75
  - !ruby/object:Gem::Dependency
@@ -99,7 +113,7 @@ homepage: https://github.com/sorentwo/carrierwave-aws
99
113
  licenses:
100
114
  - MIT
101
115
  metadata: {}
102
- post_install_message:
116
+ post_install_message:
103
117
  rdoc_options: []
104
118
  require_paths:
105
119
  - lib
@@ -107,15 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 2.5.0
111
125
  required_rubygems_version: !ruby/object:Gem::Requirement
112
126
  requirements:
113
127
  - - ">="
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  requirements: []
117
- rubygems_version: 3.0.1
118
- signing_key:
131
+ rubygems_version: 3.3.7
132
+ signing_key:
119
133
  specification_version: 4
120
134
  summary: Native aws-sdk support for S3 in CarrierWave
121
135
  test_files: