carrierwave_direct 0.0.17 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -9
- data/Changelog.md +3 -4
- data/README.md +6 -2
- data/gemfiles/{3.2.gemfile → 4.2.gemfile} +2 -2
- data/gemfiles/{4.0.gemfile → 5.1.gemfile} +2 -2
- data/lib/carrierwave_direct/form_builder.rb +4 -2
- data/lib/carrierwave_direct/uploader.rb +41 -7
- data/lib/carrierwave_direct/version.rb +1 -1
- data/spec/form_builder_spec.rb +13 -7
- data/spec/orm/activerecord_spec.rb +6 -2
- data/spec/orm/indirect_activerecord_spec.rb +7 -1
- data/spec/uploader_spec.rb +16 -4
- metadata +3 -4
- data/gemfiles/4.1.gemfile +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b64419d902b8c1afba920fafe9a7029dd4c3d94a
|
4
|
+
data.tar.gz: 5dfbb28ea14db2c7ae9bd665192c009534cbef90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f39ac6ced22656b3a96821356d92333f9ca141f215bb66125b3d2a8fa282718341adb133b0baa33308f9268cf1ef2014e59e3e21bb1f7949a389f170b4c1be
|
7
|
+
data.tar.gz: b2e2fe378dfed399fc011fb4ebcb8a94d5d4ffe4cb4c982ed71b918aa53fa7767a1b1c6d226e6fda5ad2169af24af2a43c83b80b300650367ad49aa0e6faa9d6
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
install:
|
6
|
-
- 'travis_retry bundle install'
|
2
|
+
- 2.3.0
|
3
|
+
- 2.4.0
|
4
|
+
- 2.5.0
|
7
5
|
script: 'bundle exec rspec spec'
|
8
6
|
gemfile:
|
9
7
|
- Gemfile
|
10
|
-
- gemfiles/
|
11
|
-
- gemfiles/
|
12
|
-
- gemfiles/4.1.gemfile
|
8
|
+
- gemfiles/4.2.gemfile
|
9
|
+
- gemfiles/5.1.gemfile
|
13
10
|
# Move to containerized travis, see http://docs.travis-ci.com/user/migrating-from-legacy
|
14
11
|
sudo: false
|
15
12
|
cache: bundler
|
16
|
-
|
data/Changelog.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
### 0.0
|
1
|
+
### 1.0.0
|
2
2
|
|
3
|
-
|
4
|
-
*
|
3
|
+
Features:
|
4
|
+
* Upgraded signing algorithm to use [AWS V4 POST authentication](http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html). This is a breaking change if you are constructing your own upload forms or submitting your own POST requests. See the Sinatra section of the README for a summary of the new fields required in your V4 POST request. (Fran Worley @fran-worley)
|
5
5
|
|
6
6
|
### 0.0.16
|
7
7
|
|
@@ -127,4 +127,3 @@ Misc:
|
|
127
127
|
### 0.0.1
|
128
128
|
|
129
129
|
[Full Changes](https://github.com/dwilkie/carrierwave_direct/compare/e68498587a4e4209d121512dbb0df529e15e9282...v0.0.1)
|
130
|
-
|
data/README.md
CHANGED
@@ -113,15 +113,19 @@ end
|
|
113
113
|
```
|
114
114
|
```haml
|
115
115
|
# index.haml
|
116
|
+
# Now using AWS POST authentication V4
|
117
|
+
# See http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html for more information
|
116
118
|
|
117
119
|
%form{:action => @uploader.direct_fog_url, :method => "post", :enctype => "multipart/form-data"}
|
118
120
|
%input{:name => "utf8", :type => "hidden"}
|
119
121
|
%input{:type => "hidden", :name => "key", :value => @uploader.key}
|
120
|
-
%input{:type => "hidden", :name => "AWSAccessKeyId", :value => @uploader.aws_access_key_id}
|
121
122
|
%input{:type => "hidden", :name => "acl", :value => @uploader.acl}
|
122
123
|
%input{:type => "hidden", :name => "success_action_redirect", :value => @uploader.success_action_redirect}
|
123
124
|
%input{:type => "hidden", :name => "policy", :value => @uploader.policy}
|
124
|
-
%input{:type => "hidden", :name => "
|
125
|
+
%input{:type => "hidden", :name => "x-amz-algorithm", :value => @uploader.algorithm}
|
126
|
+
%input{:type => "hidden", :name => "x-amz-credential", :value => @uploader.credential}
|
127
|
+
%input{:type => "hidden", :name => "x-amz-date", :value => @uploader.date}
|
128
|
+
%input{:type => "hidden", :name => "x-amz-signature", :value => @uploader.signature}
|
125
129
|
%input{:name => "file", :type => "file"}
|
126
130
|
%input{:type => "submit", :value => "Upload to S3"}
|
127
131
|
```
|
@@ -4,9 +4,9 @@ gem "carrierwave", "~>0.11"
|
|
4
4
|
gem "fog-aws"
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem "rspec", '3.0
|
7
|
+
gem "rspec", '~> 3.0'
|
8
8
|
gem "timecop"
|
9
|
-
gem "rails", "~>
|
9
|
+
gem "rails", "~>4.2.0"
|
10
10
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
11
11
|
gem "capybara"
|
12
12
|
# gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
@@ -4,9 +4,9 @@ gem "carrierwave", "~>0.11"
|
|
4
4
|
gem "fog-aws"
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem "rspec", '3.0
|
7
|
+
gem "rspec", '~> 3.0'
|
8
8
|
gem "timecop"
|
9
|
-
gem "rails", "~>
|
9
|
+
gem "rails", "~>5.1.0"
|
10
10
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
11
11
|
gem "capybara"
|
12
12
|
# gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
@@ -31,10 +31,12 @@ module CarrierWaveDirect
|
|
31
31
|
|
32
32
|
def required_base_fields
|
33
33
|
hidden_field(:key, :name => "key") <<
|
34
|
-
hidden_field(:aws_access_key_id, :name => "AWSAccessKeyId") <<
|
35
34
|
hidden_field(:acl, :name => "acl") <<
|
36
35
|
hidden_field(:policy, :name => "policy") <<
|
37
|
-
hidden_field(:signature, :name => "
|
36
|
+
hidden_field(:signature, :name => "X-Amz-Signature") <<
|
37
|
+
hidden_field(:credential, :name => "X-Amz-Credential") <<
|
38
|
+
hidden_field(:algorithm, :name => "X-Amz-Algorithm") <<
|
39
|
+
hidden_field(:date, :name => "X-Amz-Date")
|
38
40
|
end
|
39
41
|
|
40
42
|
def content_type_field(options)
|
@@ -26,6 +26,11 @@ module CarrierWaveDirect
|
|
26
26
|
include CarrierWaveDirect::Uploader::ContentType
|
27
27
|
include CarrierWaveDirect::Uploader::DirectUrl
|
28
28
|
|
29
|
+
#ensure that region returns something. Since sig v4 it is required in the signing key & credentials
|
30
|
+
def region
|
31
|
+
defined?(super) ? super : "us-east-1"
|
32
|
+
end
|
33
|
+
|
29
34
|
def acl
|
30
35
|
fog_public ? 'public-read' : 'private'
|
31
36
|
end
|
@@ -35,20 +40,36 @@ module CarrierWaveDirect
|
|
35
40
|
options[:min_file_size] ||= min_file_size
|
36
41
|
options[:max_file_size] ||= max_file_size
|
37
42
|
|
43
|
+
@date ||= Time.now.utc.strftime("%Y%m%d")
|
44
|
+
@timestamp ||= Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
|
38
45
|
@policy ||= generate_policy(options, &block)
|
39
46
|
end
|
40
47
|
|
48
|
+
def date
|
49
|
+
@timestamp ||= Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
|
50
|
+
end
|
51
|
+
|
52
|
+
def algorithm
|
53
|
+
'AWS4-HMAC-SHA256'
|
54
|
+
end
|
55
|
+
|
56
|
+
def credential
|
57
|
+
@date ||= Time.now.utc.strftime("%Y%m%d")
|
58
|
+
"#{aws_access_key_id}/#{@date}/#{region}/s3/aws4_request"
|
59
|
+
end
|
60
|
+
|
41
61
|
def clear_policy!
|
42
62
|
@policy = nil
|
63
|
+
@date = nil
|
64
|
+
@timestamp = nil
|
43
65
|
end
|
44
66
|
|
45
67
|
def signature
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
).gsub("\n","")
|
68
|
+
OpenSSL::HMAC.hexdigest(
|
69
|
+
'sha256',
|
70
|
+
signing_key,
|
71
|
+
policy
|
72
|
+
)
|
52
73
|
end
|
53
74
|
|
54
75
|
def url_scheme_white_list
|
@@ -139,7 +160,9 @@ module CarrierWaveDirect
|
|
139
160
|
|
140
161
|
conditions << ["starts-with", "$utf8", ""] if options[:enforce_utf8]
|
141
162
|
conditions << ["starts-with", "$key", key.sub(/#{Regexp.escape(FILENAME_WILDCARD)}\z/, "")]
|
142
|
-
|
163
|
+
conditions << {'X-Amz-Algorithm' => algorithm}
|
164
|
+
conditions << {'X-Amz-Credential' => credential}
|
165
|
+
conditions << {'X-Amz-Date' => date}
|
143
166
|
conditions << ["starts-with", "$Content-Type", ""] if will_include_content_type
|
144
167
|
conditions << {"bucket" => fog_directory}
|
145
168
|
conditions << {"acl" => acl}
|
@@ -161,5 +184,16 @@ module CarrierWaveDirect
|
|
161
184
|
}.to_json
|
162
185
|
).gsub("\n","")
|
163
186
|
end
|
187
|
+
|
188
|
+
def signing_key(options = {})
|
189
|
+
@date ||= Time.now.utc.strftime("%Y%m%d")
|
190
|
+
#AWS Signature Version 4
|
191
|
+
kDate = OpenSSL::HMAC.digest('sha256', "AWS4" + aws_secret_access_key, @date)
|
192
|
+
kRegion = OpenSSL::HMAC.digest('sha256', kDate, region)
|
193
|
+
kService = OpenSSL::HMAC.digest('sha256', kRegion, 's3')
|
194
|
+
kSigning = OpenSSL::HMAC.digest('sha256', kService, "aws4_request")
|
195
|
+
|
196
|
+
kSigning
|
197
|
+
end
|
164
198
|
end
|
165
199
|
end
|
data/spec/form_builder_spec.rb
CHANGED
@@ -12,11 +12,13 @@ end
|
|
12
12
|
shared_examples_for 'hidden values form' do
|
13
13
|
hidden_fields = [
|
14
14
|
:key,
|
15
|
-
{:
|
15
|
+
{:credential => "X-Amz-Credential"},
|
16
|
+
{:algorithm => "X-Amz-Algorithm"},
|
17
|
+
{:date => "X-Amz-Date"},
|
18
|
+
{:signature => "X-Amz-Signature"},
|
16
19
|
:acl,
|
17
20
|
:success_action_redirect,
|
18
|
-
:policy
|
19
|
-
:signature
|
21
|
+
:policy
|
20
22
|
]
|
21
23
|
|
22
24
|
hidden_fields.each do |input|
|
@@ -60,19 +62,23 @@ describe CarrierWaveDirect::FormBuilder do
|
|
60
62
|
|
61
63
|
default_hidden_fields = [
|
62
64
|
:key,
|
63
|
-
{:
|
65
|
+
{:credential => "X-Amz-Credential"},
|
66
|
+
{:algorithm => "X-Amz-Algorithm"},
|
67
|
+
{:date => "X-Amz-Date"},
|
68
|
+
{:signature => "X-Amz-Signature"},
|
64
69
|
:acl,
|
65
70
|
:success_action_redirect,
|
66
71
|
:policy,
|
67
|
-
:signature
|
68
72
|
]
|
69
73
|
status_hidden_fields = [
|
70
74
|
:key,
|
71
|
-
{:
|
75
|
+
{:credential => "X-Amz-Credential"},
|
76
|
+
{:algorithm => "X-Amz-Algorithm"},
|
77
|
+
{:date => "X-Amz-Date"},
|
78
|
+
{:signature => "X-Amz-Signature"},
|
72
79
|
:acl,
|
73
80
|
:success_action_status,
|
74
81
|
:policy,
|
75
|
-
:signature
|
76
82
|
]
|
77
83
|
|
78
84
|
# http://aws.amazon.com/articles/1434?_encoding=UTF8
|
@@ -9,8 +9,12 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
9
9
|
:adapter => 'sqlite3',
|
10
10
|
:database => ':memory:'
|
11
11
|
}
|
12
|
-
|
13
|
-
|
12
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
13
|
+
migration_class = ::ActiveRecord::Migration[5.0]
|
14
|
+
else
|
15
|
+
migration_class = ::ActiveRecord::Migration
|
16
|
+
end
|
17
|
+
class TestMigration < migration_class
|
14
18
|
def self.up
|
15
19
|
create_table :parties, :force => true do |t|
|
16
20
|
t.column :video, :string
|
@@ -10,7 +10,13 @@ describe CarrierWave::ActiveRecord do
|
|
10
10
|
:database => ':memory:'
|
11
11
|
}
|
12
12
|
|
13
|
-
|
13
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
14
|
+
migration_class = ::ActiveRecord::Migration[5.0]
|
15
|
+
else
|
16
|
+
migration_class = ::ActiveRecord::Migration
|
17
|
+
end
|
18
|
+
|
19
|
+
class OtherTestMigration < migration_class
|
14
20
|
def self.up
|
15
21
|
create_table :other_parties, :force => true do |t|
|
16
22
|
t.column :video, :string
|
data/spec/uploader_spec.rb
CHANGED
@@ -275,6 +275,7 @@ describe CarrierWaveDirect::Uploader do
|
|
275
275
|
end
|
276
276
|
|
277
277
|
# http://aws.amazon.com/articles/1434?_encoding=UTF8
|
278
|
+
#http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
|
278
279
|
describe "#policy" do
|
279
280
|
|
280
281
|
|
@@ -478,13 +479,24 @@ describe CarrierWaveDirect::Uploader do
|
|
478
479
|
expect(subject.signature).to_not include("\n")
|
479
480
|
end
|
480
481
|
|
481
|
-
it "should return a
|
482
|
-
expect(
|
483
|
-
OpenSSL::Digest.new('
|
484
|
-
subject.
|
482
|
+
it "should return a HMAC hexdigest encoded 'sha256' hash of the secret key and policy document" do
|
483
|
+
expect(subject.signature).to eq OpenSSL::HMAC.hexdigest(
|
484
|
+
OpenSSL::Digest.new('sha256'),
|
485
|
+
subject.send(:signing_key), subject.policy
|
485
486
|
)
|
486
487
|
end
|
487
488
|
end
|
489
|
+
#http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
|
490
|
+
describe "#signature_key" do
|
491
|
+
it "should include correct signature_key elements" do
|
492
|
+
kDate = OpenSSL::HMAC.digest('sha256', "AWS4" + subject.aws_secret_access_key, Time.now.utc.strftime("%Y%m%d"))
|
493
|
+
kRegion = OpenSSL::HMAC.digest('sha256', kDate, subject.region)
|
494
|
+
kService = OpenSSL::HMAC.digest('sha256', kRegion, 's3')
|
495
|
+
kSigning = OpenSSL::HMAC.digest('sha256', kService, "aws4_request")
|
496
|
+
|
497
|
+
expect(subject.send(:signing_key)).to eq (kSigning)
|
498
|
+
end
|
499
|
+
end
|
488
500
|
|
489
501
|
|
490
502
|
# note that 'video' is hardcoded into the MountedClass support file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Wilkie
|
@@ -123,9 +123,8 @@ files:
|
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- carrierwave_direct.gemspec
|
126
|
-
- gemfiles/
|
127
|
-
- gemfiles/
|
128
|
-
- gemfiles/4.1.gemfile
|
126
|
+
- gemfiles/4.2.gemfile
|
127
|
+
- gemfiles/5.1.gemfile
|
129
128
|
- lib/carrierwave_direct.rb
|
130
129
|
- lib/carrierwave_direct/action_view_extensions/form_helper.rb
|
131
130
|
- lib/carrierwave_direct/form_builder.rb
|
data/gemfiles/4.1.gemfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "carrierwave", "~>0.11"
|
4
|
-
gem "fog-aws"
|
5
|
-
|
6
|
-
group :test do
|
7
|
-
gem "rspec", '3.0.0'
|
8
|
-
gem "timecop"
|
9
|
-
gem "rails", "~>4.1.0"
|
10
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
11
|
-
gem "capybara"
|
12
|
-
# gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
13
|
-
end
|