uploadcare-ruby 3.2.0 → 3.3.2

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: f1c9e31f806af7e05c558fac2f5474b1b79bbe6585437049a2ecca5cc7011b46
4
- data.tar.gz: 3da125b462b72f76f1cc52b3d9654354399d4864eba72b34e474c5d9a05ca22b
3
+ metadata.gz: d3c7c464a8d89a9451f4205ba7f82b3c270d2431eb2b9cf9e31f64fc0542e032
4
+ data.tar.gz: 5ee0ef07f9194986eaf3742a5a80d01be38cd69a7e951551b791bcf479cf17f0
5
5
  SHA512:
6
- metadata.gz: '06814335c0ac2733f7a71ad0a9f04af2c9e3160d59de4d3d88231403a6e02366a10bb8db9405762d6a2ed70c82fb0185e5e11e59763cc2f04f79a67c89f52718'
7
- data.tar.gz: 9c9d034e9d510c0d1839f5b13164a810ee26c58eb75cdcff3aaf6e54aeb6a5f2a0a9c20f2d75d0b6c6f5856eba7a8ccb2b42b7cb4b7ea45f74f5242120bf5534
6
+ metadata.gz: 6accbd5a9c9c593c252a370947f42756a477cb47d6d1261a54a17df6f7026f9dd5e49ded174718ce159e6f3da9638744c4520673cfc0c81dcac381f129de2016
7
+ data.tar.gz: c383653917bab7dbc417eeccd16b800066ee07cf3741f3734361b8ae9da2935e369442711071a0ab0453860321b21a7a979265fa2a7f19daaaefb9fd4c5add20
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.3.2 - 2022-07-18
4
+
5
+ - Fixes dry-configurable deprecation warnings
6
+
7
+ ## 3.3.1 - 2022-04-19
8
+
9
+ - Fixed README: `Uploadcare::URLGenerators::AmakaiGenerator` > `Uploadcare::SignedUrlGenerators::AmakaiGenerator`
10
+ - Autoload generators constants
11
+
12
+ ## 3.3.0 — 2022-04-08
13
+
14
+ - Added `Uploadcare::URLGenerators::AmakaiGenerator`. Use custom domain and CDN provider to deliver files with authenticated URLs
15
+
3
16
  ## 3.2.0 — 2021-11-16
4
17
 
5
18
  - Added option `signing_secret` to the `Uploadcare::Webhook`
@@ -28,6 +41,7 @@
28
41
  - Added CI
29
42
 
30
43
  ## 3.0.3-dev — 2020-03-13
44
+
31
45
  - Added better pagination and iterators for `GroupList` & `FileList`
32
46
 
33
47
  ## 3.0.2-dev — 2020-03-11
@@ -46,6 +60,7 @@
46
60
  ## 3.0.0-dev — 2020-02-18
47
61
 
48
62
  ### Changed
63
+
49
64
  - Rewrote gem from scratch
50
65
 
51
66
  ### Added
data/README.md CHANGED
@@ -119,6 +119,8 @@ Uploadcare supports multiple ways to upload files:
119
119
 
120
120
  ```ruby
121
121
  # Smart upload - detects type of passed object and picks appropriate upload method
122
+ # If you have a large file (more than 100Mb / 10485760 bytes), the uploader will automatically process it with a multipart upload
123
+
122
124
  Uploadcare::Uploader.upload("https://placekitten.com/96/139")
123
125
  ```
124
126
 
@@ -659,13 +661,27 @@ Params in the response:
659
661
 
660
662
  More examples and options can be found [here](https://uploadcare.com/docs/transformations/document-conversion/#document-conversion)
661
663
 
664
+ ## Secure delivery
665
+
666
+ You can use custom domain and CDN provider to deliver files with authenticated URLs (see [original documentation](https://uploadcare.com/docs/security/secure_delivery/)).
667
+
668
+ To generate authenticated URL from the library, you should choose `Uploadcare::SignedUrlGenerators::AmakaiGenerator` (or create your generator implementation):
669
+ ```ruby
670
+ generator = Uploadcare::SignedUrlGenerators::AmakaiGenerator.new(cdn_host: 'example.com', secret_key: 'secret_key'). Optional parameters: ttl: 300, algorithm: 'sha256'
671
+ generator.generate_url(uuid, acl = optional)
672
+
673
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3") ->
674
+ https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/a7d5645e-5cd7-4046-819f-a6a2933bafe3/~hmac=a989cae5342f17013677f5a0e6577fc5594cc4e238fb4c95eda36634eb47018b
675
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3", '/*/') ->
676
+ https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/*/~hmac=3ce1152c6af8864b36d4dc721f08ca3cf0b3a20278d7f849e82c6c930d48ccc1
677
+ ```
662
678
  ## Useful links
663
679
 
664
680
  * [Development](https://github.com/uploadcare/uploadcare-ruby/blob/main/DEVELOPMENT.md)
665
- * [Uploadcare documentation](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
666
- * [Upload API reference](https://uploadcare.com/api-refs/upload-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
667
- * [REST API reference](https://uploadcare.com/api-refs/rest-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
668
- * [Changelog](./CHANGELOG.md)
669
- * [Contributing guide](https://github.com/uploadcare/.github/blob/master/CONTRIBUTING.md)
670
- * [Security policy](https://github.com/uploadcare/uploadcare-ruby/security/policy)
671
- * [Support](https://github.com/uploadcare/.github/blob/master/SUPPORT.md)
681
+ * [Uploadcare documentation](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
682
+ * [Upload API reference](https://uploadcare.com/api-refs/upload-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
683
+ * [REST API reference](https://uploadcare.com/api-refs/rest-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
684
+ * [Changelog](./CHANGELOG.md)
685
+ * [Contributing guide](https://github.com/uploadcare/.github/blob/master/CONTRIBUTING.md)
686
+ * [Security policy](https://github.com/uploadcare/uploadcare-ruby/security/policy)
687
+ * [Support](https://github.com/uploadcare/.github/blob/master/SUPPORT.md)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploadcare
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.2'
5
5
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_generator'
4
+
5
+ module Uploadcare
6
+ module SignedUrlGenerators
7
+ class AmakaiGenerator < Uploadcare::SignedUrlGenerators::BaseGenerator
8
+ UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}'
9
+ TEMPLATE = 'https://{cdn_host}/{uuid}/?token=exp={expiration}{delimiter}acl={acl}{delimiter}hmac={token}'
10
+
11
+ def generate_url(uuid, acl = uuid)
12
+ raise ArgumentError, 'Must contain valid UUID' unless valid?(uuid)
13
+
14
+ expire = build_expire
15
+ signature = build_signature(expire, acl)
16
+
17
+ TEMPLATE.gsub('{delimiter}', delimiter)
18
+ .sub('{cdn_host}', sanitized_string(cdn_host))
19
+ .sub('{uuid}', sanitized_string(uuid))
20
+ .sub('{acl}', "/#{sanitized_string(acl)}/")
21
+ .sub('{expiration}', expire)
22
+ .sub('{token}', signature)
23
+ end
24
+
25
+ private
26
+
27
+ def valid?(uuid)
28
+ uuid.match(UUID_REGEX)
29
+ end
30
+
31
+ def delimiter
32
+ '~'
33
+ end
34
+
35
+ def build_expire
36
+ (Time.now.to_i + ttl).to_s
37
+ end
38
+
39
+ def build_signature(expire, acl)
40
+ signature = ["exp=#{expire}", "acl=/#{sanitized_string(acl)}/"].join(delimiter)
41
+ OpenSSL::HMAC.hexdigest(algorithm, secret_key, signature)
42
+ end
43
+
44
+ # rubocop:disable Style/SlicingWithRange
45
+ def sanitized_string(string)
46
+ string = string[1..-1] if string[0] == '/'
47
+ string = string[0...-1] if string[-1] == '/'
48
+ string.strip
49
+ end
50
+ # rubocop:enable Style/SlicingWithRange
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uploadcare
4
+ module SignedUrlGenerators
5
+ class BaseGenerator
6
+ attr_accessor :cdn_host, :ttl, :algorithm
7
+ attr_reader :secret_key
8
+
9
+ def initialize(cdn_host:, secret_key:, ttl: 300, algorithm: 'sha256')
10
+ @ttl = ttl
11
+ @algorithm = algorithm
12
+ @cdn_host = cdn_host
13
+ @secret_key = secret_key
14
+ end
15
+
16
+ def generate_url
17
+ raise NotImplementedError, "#{__method__} method not present"
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/uploadcare.rb CHANGED
@@ -23,23 +23,40 @@ require 'param/webhook_signature_verifier'
23
23
  # General api
24
24
  require 'api/api'
25
25
 
26
+ # SignedUrlGenerators
27
+ require 'signed_url_generators/amakai_generator'
28
+ require 'signed_url_generators/base_generator'
29
+
26
30
  # Ruby wrapper for Uploadcare API
27
31
  #
28
32
  # @see https://uploadcare.com/docs/api_reference
29
33
  module Uploadcare
30
34
  extend Dry::Configurable
31
- setting :public_key, ENV.fetch('UPLOADCARE_PUBLIC_KEY')
32
- setting :secret_key, ENV.fetch('UPLOADCARE_SECRET_KEY')
33
- setting :auth_type, 'Uploadcare'
34
- setting :multipart_size_threshold, 100 * 1024 * 1024
35
- setting :rest_api_root, 'https://api.uploadcare.com'
36
- setting :upload_api_root, 'https://upload.uploadcare.com'
37
- setting :max_request_tries, 100
38
- setting :base_request_sleep, 1 # seconds
39
- setting :max_request_sleep, 60.0 # seconds
40
- setting :sign_uploads, false
41
- setting :upload_signature_lifetime, 30 * 60 # seconds
42
- setting :max_throttle_attempts, 5
43
- setting :upload_threads, 2 # used for multiupload only ATM
44
- setting :framework_data, ''
35
+
36
+ # NOTE: The dry-configurable gem has introduced the `default` keyword argument
37
+ # and deprecated the positional default argument in v0.13.0, which requires
38
+ # Ruby >= 2.6.0. In order to provide backwards compatibility and not disable
39
+ # deprecation warnings, we override the dry-configurable's `setting` DSL method.
40
+ def self.setting(name, default:, **options, &block)
41
+ if RUBY_VERSION < '2.6'
42
+ super name, default, &block
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ setting :public_key, default: ENV.fetch('UPLOADCARE_PUBLIC_KEY')
49
+ setting :secret_key, default: ENV.fetch('UPLOADCARE_SECRET_KEY')
50
+ setting :auth_type, default: 'Uploadcare'
51
+ setting :multipart_size_threshold, default: 100 * 1024 * 1024
52
+ setting :rest_api_root, default: 'https://api.uploadcare.com'
53
+ setting :upload_api_root, default: 'https://upload.uploadcare.com'
54
+ setting :max_request_tries, default: 100
55
+ setting :base_request_sleep, default: 1 # seconds
56
+ setting :max_request_sleep, default: 60.0 # seconds
57
+ setting :sign_uploads, default: false
58
+ setting :upload_signature_lifetime, default: 30 * 60 # seconds
59
+ setting :max_throttle_attempts, default: 5
60
+ setting :upload_threads, default: 2 # used for multiupload only ATM
61
+ setting :framework_data, default: ''
45
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan Redka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_struct
@@ -216,6 +216,8 @@ files:
216
216
  - lib/uploadcare/param/user_agent.rb
217
217
  - lib/uploadcare/param/webhook_signature_verifier.rb
218
218
  - lib/uploadcare/ruby/version.rb
219
+ - lib/uploadcare/signed_url_generators/amakai_generator.rb
220
+ - lib/uploadcare/signed_url_generators/base_generator.rb
219
221
  - uploadcare-ruby.gemspec
220
222
  homepage: https://github.com/uploadcare/uploadcare-ruby
221
223
  licenses: