carrierwave_direct 0.0.16 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +14 -9
  3. data/Changelog.md +45 -1
  4. data/README.md +37 -23
  5. data/carrierwave_direct.gemspec +4 -3
  6. data/gemfiles/{3.2.gemfile → 5.1.gemfile} +3 -3
  7. data/gemfiles/{4.0.gemfile → 5.2.gemfile} +3 -3
  8. data/gemfiles/{4.1.gemfile → 6.0.gemfile} +3 -3
  9. data/gemfiles/6.1.gemfile +13 -0
  10. data/lib/carrierwave_direct/action_view_extensions/form_helper.rb +1 -1
  11. data/lib/carrierwave_direct/form_builder.rb +30 -12
  12. data/lib/carrierwave_direct/mount.rb +1 -11
  13. data/lib/carrierwave_direct/policies/aws4_hmac_sha256.rb +93 -0
  14. data/lib/carrierwave_direct/policies/aws_base64_sha1.rb +57 -0
  15. data/lib/carrierwave_direct/policies/base.rb +21 -0
  16. data/lib/carrierwave_direct/test/capybara_helpers.rb +3 -3
  17. data/lib/carrierwave_direct/test/helpers.rb +1 -1
  18. data/lib/carrierwave_direct/uploader.rb +55 -56
  19. data/lib/carrierwave_direct/validations/active_model.rb +2 -2
  20. data/lib/carrierwave_direct/version.rb +1 -1
  21. data/spec/form_builder_spec.rb +24 -15
  22. data/spec/mount_spec.rb +2 -2
  23. data/spec/orm/activerecord_spec.rb +11 -7
  24. data/spec/orm/indirect_activerecord_spec.rb +7 -1
  25. data/spec/policies/aws4_hmac_sha256_spec.rb +243 -0
  26. data/spec/policies/aws_base64_sha1_spec.rb +229 -0
  27. data/spec/spec_helper.rb +5 -0
  28. data/spec/support/carrier_wave_config.rb +1 -0
  29. data/spec/test/capybara_helpers_spec.rb +4 -4
  30. data/spec/test/helpers_spec.rb +3 -3
  31. data/spec/uploader_spec.rb +20 -26
  32. metadata +36 -18
  33. data/lib/carrierwave_direct/uploader/direct_url.rb +0 -15
  34. data/spec/uploader/direct_url_spec.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c51cb71409e58177ac38cc749d3f596766f0ab8e
4
- data.tar.gz: 98aeee5a704ec4221825bad26fe3a379c2b65049
2
+ SHA256:
3
+ metadata.gz: bf462a9da6254f9a1b404f03443be9d9c21800aa378cbab7135da3ab08e2d1a5
4
+ data.tar.gz: 36e88bdcdc5f8e904109845546c47928eaf24dac894ba15a47820a131efd9576
5
5
  SHA512:
6
- metadata.gz: 42a18d958215b315f02c644842750bef8466cfefa9410c5fd72011350e09035bc22bf86b20672c3fa5273fd6989bdbf8c090a217982b1257d60b37eed6633fdb
7
- data.tar.gz: 419fb4c392fa4eb322e1105bf1c6ca815c85fb7c4b3841ef96f10b2a03760ec2322ba1df82ae565671fdba338e23062dd520b5248411afe032b74b042414212b
6
+ metadata.gz: 3472e79f169583c76665f9c6a18cebe4b1f8b842e94d57dc4cfadba365382124d358243c229dd5bfcde36e23f9748cf278863f2b9283897e0f8c901b69866ef7
7
+ data.tar.gz: 180ef968f4d13946a93108e782f029b3c2de25509e7f321933a5203b3d06599e739b999ef1254da69b7153fe02205c72ea0679a4147251f572bdd4967d5cded1
data/.travis.yml CHANGED
@@ -1,14 +1,19 @@
1
1
  rvm:
2
- - 2.0.0
3
- - 2.1.0
4
- - 2.2.0
5
- install:
6
- - 'travis_retry bundle install'
2
+ - 2.6
3
+ - 2.7
4
+
7
5
  script: 'bundle exec rspec spec'
8
6
  gemfile:
9
- - Gemfile
10
- - gemfiles/3.2.gemfile
11
- - gemfiles/4.0.gemfile
12
- - gemfiles/4.1.gemfile
7
+ - gemfiles/5.1.gemfile
8
+ - gemfiles/5.2.gemfile
9
+ - gemfiles/6.0.gemfile
10
+ - gemfiles/6.1.gemfile
11
+
12
+ matrix:
13
+ exclude:
14
+ - rvm: 2.4
15
+ gemfile: gemfiles/6.0.gemfile
16
+
13
17
  # Move to containerized travis, see http://docs.travis-ci.com/user/migrating-from-legacy
14
18
  sudo: false
19
+ cache: bundler
data/Changelog.md CHANGED
@@ -1,4 +1,46 @@
1
- ### Unreleased changes
1
+ ### Unreleased
2
+
3
+ ### 3.0.0
4
+ * Fixed Ruby 3 deprecation warnings
5
+ * [BREAKING CHANGE] Drop support for Carrierwave < 2.2.1 which renamed
6
+ extension_whitelist to extension_allowlist.
7
+
8
+ ### 2.1.0
9
+
10
+ Features:
11
+ * Refactor policies to seperate classes and add back the old policy for
12
+ backwards compatibility.
13
+ * Added `direct_fog_hash` method that can be used for returning json
14
+
15
+ Misc:
16
+ * Removed deprecated `key` methods.
17
+ * Removed deprecated `:with_path` option for `direct_fog_url`
18
+
19
+ ### 2.0.0
20
+
21
+ Features:
22
+ * [BREAKING CHANGE] Add support for Carrierwave 1.x. Drops support for Carrierwave < 1.0 (Kevin Reintjes @kreintjes).
23
+
24
+ Misc:
25
+ * Dropped support for ruby 2.0 and 2.1, they have [reached their end of life](https://www.ruby-lang.org/en/news/2017/04/01/support-of-ruby-2-1-has-ended/)
26
+ * Update Ruby and Rails versions for Travis so builds succeed once again (Kevin Reintjes @kreintjes)
27
+
28
+ ### 1.1.0
29
+
30
+ Deprecations:
31
+ * Calling `direct_fog_url` with `:with_path` is deprecated, please use `url` instead.
32
+
33
+ ### 1.0.0
34
+
35
+ Features:
36
+ * 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)
37
+
38
+ ### 0.0.17
39
+
40
+ Misc:
41
+ * Pin carrierwave to 0.11
42
+
43
+ ### 0.0.16
2
44
 
3
45
  Bug Fixes:
4
46
  * Allow uploader columns to be named `file` (Diego Plentz @plentz and Moisés Viloria @mois3x)
@@ -7,6 +49,8 @@ Bug Fixes:
7
49
  Misc:
8
50
  * Dropped support for ruby 1.9, it has [reached its end of life](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)
9
51
  * Add 2.2.0 support to travis.
52
+ * Compatible with Capybara 2.7
53
+ * Replaced fog dependency with fog-aws; significantly reduces gem footprint
10
54
 
11
55
  ### 0.0.15
12
56
 
data/README.md CHANGED
@@ -20,7 +20,9 @@ Please be aware that this gem (and S3 in general) only support single file uploa
20
20
 
21
21
  Install the latest release:
22
22
 
23
- gem install carrierwave_direct
23
+ ```bash
24
+ gem install carrierwave_direct
25
+ ```
24
26
 
25
27
  In Rails, add it to your Gemfile:
26
28
 
@@ -52,11 +54,15 @@ end
52
54
 
53
55
  If you haven't already done so generate an uploader
54
56
 
55
- rails generate uploader Avatar
57
+ ```bash
58
+ rails generate uploader Avatar
59
+ ```
56
60
 
57
61
  this should give you a file in:
58
62
 
59
- app/uploaders/avatar_uploader.rb
63
+ ```bash
64
+ app/uploaders/avatar_uploader.rb
65
+ ```
60
66
 
61
67
  Check out this file for some hints on how you can customize your uploader. It should look something like this:
62
68
 
@@ -111,17 +117,17 @@ class UploaderTest < Sinatra::Base
111
117
  end
112
118
  end
113
119
  ```
120
+
114
121
  ```haml
115
122
  # index.haml
123
+ # Now using AWS POST authentication V4
124
+ # See http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html for more information
116
125
 
117
126
  %form{:action => @uploader.direct_fog_url, :method => "post", :enctype => "multipart/form-data"}
118
- %input{:name => "utf8", :type => "hidden"}
119
- %input{:type => "hidden", :name => "key", :value => @uploader.key}
120
- %input{:type => "hidden", :name => "AWSAccessKeyId", :value => @uploader.aws_access_key_id}
121
- %input{:type => "hidden", :name => "acl", :value => @uploader.acl}
127
+ - @uploader.direct_fog_hash.each do |key, value|
128
+ - if key != :uri
129
+ %input{:type => "hidden", :name => key, :value => value}
122
130
  %input{:type => "hidden", :name => "success_action_redirect", :value => @uploader.success_action_redirect}
123
- %input{:type => "hidden", :name => "policy", :value => @uploader.policy}
124
- %input{:type => "hidden", :name => "signature", :value => @uploader.signature}
125
131
  %input{:name => "file", :type => "file"}
126
132
  %input{:type => "submit", :value => "Upload to S3"}
127
133
  ```
@@ -276,7 +282,7 @@ If your upload was successful then you will be redirected to the `success_action
276
282
 
277
283
  The `key` is the most important piece of information as we can use it for validating the file extension, downloading the file from S3, processing it and re-uploading it.
278
284
 
279
- If you're using ActiveRecord, CarrierWaveDirect will by default validate the file extension based off your `extension_white_list` in your uploader. See the [CarrierWave readme](https://github.com/jnicklas/carrierwave) for more info. You can then use the helper `filename_valid?` to check if the filename is valid. e.g.
285
+ If you're using ActiveRecord, CarrierWaveDirect will by default validate the file extension based off your `extension_allowlist` in your uploader. See the [CarrierWave readme](https://github.com/jnicklas/carrierwave) for more info. You can then use the helper `filename_valid?` to check if the filename is valid. e.g.
280
286
 
281
287
  ```ruby
282
288
  class UsersController < ApplicationController
@@ -300,6 +306,7 @@ CarrierWaveDirect automatically gives you an accessible `key` attribute in your
300
306
  <%= f.submit %>
301
307
  <% end %>
302
308
  ```
309
+
303
310
  then in your controller you can do something like this:
304
311
 
305
312
  ```ruby
@@ -322,7 +329,7 @@ Now that the basic building blocks are in place you can process and save your av
322
329
  class User < ActiveRecord::Base
323
330
  def save_and_process_avatar(options = {})
324
331
  if options[:now]
325
- self.remote_avatar_url = avatar.direct_fog_url(:with_path => true)
332
+ self.remote_avatar_url = avatar.url
326
333
  save
327
334
  else
328
335
  Resque.enqueue(AvatarProcessor, attributes)
@@ -355,11 +362,12 @@ Your users may find it convenient to upload a file from a location on the Intern
355
362
  <%= f.submit %>
356
363
  <% end %>
357
364
  ```
365
+
358
366
  ```ruby
359
367
  class User < ActiveRecord::Base
360
368
  def save_and_process_avatar(options = {})
361
369
  if options[:now]
362
- self.remote_avatar_url = has_remote_avatar_net_url? ? remote_avatar_net_url : avatar.direct_fog_url(:with_path => true)
370
+ self.remote_avatar_url = has_remote_avatar_net_url? ? remote_avatar_net_url : avatar.url
363
371
  save
364
372
  else
365
373
  Resque.enqueue(AvatarProcessor, attributes)
@@ -367,6 +375,7 @@ class User < ActiveRecord::Base
367
375
  end
368
376
  end
369
377
  ```
378
+
370
379
  The methods `has_avatar_upload?`, `remote_avatar_net_url` and `has_remote_avatar_net_url?` are automatically added to your mounted model
371
380
 
372
381
  ## Validations
@@ -395,13 +404,13 @@ Validates that the filename in the database is unique. Turned *on* by default
395
404
  validates :avatar, :filename_format => true
396
405
  ```
397
406
 
398
- Validates that the uploaded filename is valid. As well as validating the extension against the `extension_white_list` it also validates that the `upload_dir` is correct. Turned *on* by default
407
+ Validates that the uploaded filename is valid. As well as validating the extension against the `extension_allowlist` it also validates that the `upload_dir` is correct. Turned *on* by default
399
408
 
400
409
  ```ruby
401
410
  validates :avatar, :remote_net_url_format => true
402
411
  ```
403
412
 
404
- Validates that the remote net url is valid. As well as validating the extension against the `extension_white_list` it also validates that url is valid and has only the schemes specified in the `url_scheme_whitelist`. Turned *on* by default
413
+ Validates that the remote net url is valid. As well as validating the extension against the `extension_allowlist` it also validates that url is valid and has only the schemes specified in the `url_scheme_whitelist`. Turned *on* by default
405
414
 
406
415
  ## Configuration
407
416
 
@@ -422,10 +431,11 @@ CarrierWave.configure do |config|
422
431
  # on s3, but you must include an input field named
423
432
  # Content-Type on every direct upload form
424
433
 
425
- config.use_action_status = true # defaults to false; if true you must set in your uploader
426
- # 'uploader.success_action_status = 201' and set
427
- # 'f.file_field :avatar, use_action_status: true' to works
428
- # properly
434
+ config.use_action_status = true # defaults to false; if true, you must set
435
+ # success_action_status in your uploader:
436
+ # uploader.success_action_status = "201"
437
+ # and add use_action_status to the file field:
438
+ # f.file_field :avatar, use_action_status: true'
429
439
  end
430
440
  ```
431
441
 
@@ -517,7 +527,7 @@ Factory.define :user |f|
517
527
  end
518
528
  ```
519
529
 
520
- This will return a valid key based off your `upload_dir` and your `extension_white_list`
530
+ This will return a valid key based off your `upload_dir` and your `extension_allowlist`
521
531
 
522
532
  ### Faking a background download
523
533
 
@@ -530,7 +540,7 @@ upload_path = find_upload_path
530
540
  redirect_key = sample_key(:base => find_key, :filename => File.basename(upload_path))
531
541
 
532
542
  uploader.key = redirect_key
533
- download_url = uploader.direct_fog_url(:with_path => true)
543
+ download_url = uploader.url
534
544
 
535
545
  # Register the download url and return the uploaded file in the body
536
546
  FakeWeb.register_uri(:get, download_url, :body => File.open(upload_path))
@@ -560,12 +570,16 @@ If you're Rails app was newly generated *after* version 3.2.3 and your testing t
560
570
 
561
571
  Pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested. Pull requests without tests *will not* be accepted.
562
572
 
563
- gem install bundler
564
- bundle install
573
+ ```bash
574
+ gem install bundler
575
+ bundle install
576
+ ```
565
577
 
566
578
  You should now be able to run the tests
567
579
 
568
- bundle exec rake
580
+ ```bash
581
+ bundle exec rake
582
+ ```
569
583
 
570
584
  ### Using the Sample Application
571
585
 
@@ -14,14 +14,15 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "carrierwave_direct"
16
16
 
17
- s.add_dependency "carrierwave"
17
+ s.add_dependency "carrierwave", '>= 2.2.0'
18
18
  s.add_dependency "fog-aws"
19
19
 
20
- s.add_development_dependency "rspec"
20
+ s.add_development_dependency "rspec", '~> 3.0'
21
21
  s.add_development_dependency "timecop"
22
- s.add_development_dependency "rails", ">= 3.2.12"
22
+ s.add_development_dependency "rails", ">= 5.1.0"
23
23
  s.add_development_dependency "sqlite3"
24
24
  s.add_development_dependency "capybara"
25
+ s.add_development_dependency "byebug"
25
26
 
26
27
  s.files = `git ls-files`.split("\n")
27
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,12 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave"
4
- gem "fog"
4
+ gem "fog-aws"
5
5
 
6
6
  group :test do
7
- gem "rspec", '3.0.0'
7
+ gem "rspec", '~> 3.0'
8
8
  gem "timecop"
9
- gem "rails", "~>3.2.12"
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
@@ -1,12 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave"
4
- gem "fog"
4
+ gem "fog-aws"
5
5
 
6
6
  group :test do
7
- gem "rspec", '3.0.0'
7
+ gem "rspec", '~> 3.0'
8
8
  gem "timecop"
9
- gem "rails", "~>4.0.0"
9
+ gem "rails", "~>5.2.0"
10
10
  gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
11
11
  gem "capybara"
12
12
  # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
@@ -1,12 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave"
4
- gem "fog"
4
+ gem "fog-aws"
5
5
 
6
6
  group :test do
7
- gem "rspec", '3.0.0'
7
+ gem "rspec", '~> 3.0'
8
8
  gem "timecop"
9
- gem "rails", "~>4.1.0"
9
+ gem "rails", "~>6.0.0"
10
10
  gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
11
11
  gem "capybara"
12
12
  # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave"
4
+ gem "fog-aws"
5
+
6
+ group :test do
7
+ gem "rspec", '~> 3.0'
8
+ gem "timecop"
9
+ gem "rails", "~>6.1.0"
10
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
11
+ gem "capybara"
12
+ # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
13
+ end
@@ -18,7 +18,7 @@ module CarrierWaveDirect
18
18
  options = args.extract_options!
19
19
 
20
20
  html_options = {
21
- :multipart => true
21
+ :multipart => true
22
22
  }.update(options[:html] || {})
23
23
 
24
24
  form_for(
@@ -5,19 +5,21 @@ module CarrierWaveDirect
5
5
  def file_field(method, options = {})
6
6
  @object.policy(enforce_utf8: true)
7
7
 
8
- options.merge!(:name => "file")
9
-
10
- fields = required_base_fields
11
-
12
- fields << content_type_field(options)
13
-
14
- fields << success_action_field(options)
8
+ fields = hidden_fields(options)
15
9
 
16
10
  # The file field must be the last element in the form.
17
11
  # Any element after this will be ignored by Amazon.
12
+ options.merge!(:name => "file")
13
+
18
14
  fields << super
19
15
  end
20
16
 
17
+ def fields_except_file_field(options = {})
18
+ @object.policy(enforce_utf8: true)
19
+
20
+ hidden_fields(options)
21
+ end
22
+
21
23
  def content_type_label(content=nil)
22
24
  content ||= 'Content Type'
23
25
  @template.label_tag('Content-Type', content)
@@ -29,12 +31,28 @@ module CarrierWaveDirect
29
31
 
30
32
  private
31
33
 
34
+ def hidden_fields(options)
35
+ fields = required_base_fields
36
+ fields << content_type_field(options)
37
+ fields << success_action_field(options)
38
+ fields
39
+ end
40
+
32
41
  def required_base_fields
33
- hidden_field(:key, :name => "key") <<
34
- hidden_field(:aws_access_key_id, :name => "AWSAccessKeyId") <<
35
- hidden_field(:acl, :name => "acl") <<
36
- hidden_field(:policy, :name => "policy") <<
37
- hidden_field(:signature, :name => "signature")
42
+ fields = ''.html_safe
43
+ @object.direct_fog_hash(enforce_utf8: true).each do |key, value|
44
+ normalized_keys = {
45
+ 'X-Amz-Signature': 'signature',
46
+ 'X-Amz-Credential': 'credential',
47
+ 'X-Amz-Algorithm': 'algorithm',
48
+ 'X-Amz-Date': 'date'
49
+ }
50
+ id = "#{@template.dom_class(@object)}_#{normalized_keys[key] || key}"
51
+ if key != :uri
52
+ fields << @template.hidden_field_tag(key, value, id: id, required: false)
53
+ end
54
+ end
55
+ fields
38
56
  end
39
57
 
40
58
  def content_type_field(options)
@@ -14,7 +14,7 @@ module CarrierWaveDirect
14
14
  def #{column}; self; end
15
15
  RUBY
16
16
  end
17
-
17
+
18
18
  self.instance_eval <<-RUBY, __FILE__, __LINE__+1
19
19
  attr_accessor :remote_#{column}_net_url
20
20
  RUBY
@@ -23,16 +23,6 @@ module CarrierWaveDirect
23
23
  include mod
24
24
  mod.class_eval <<-RUBY, __FILE__, __LINE__+1
25
25
 
26
- def key
27
- warn "key method is deprecated, please use column_key method instead."
28
- send(:#{column}).key
29
- end
30
-
31
- def key=(k)
32
- warn "key= method is deprecated, please use column_key= method instead."
33
- send(:#{column}).key = k
34
- end
35
-
36
26
  def #{column}_key
37
27
  send(:#{column}).key
38
28
  end