uploadcare-ruby 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43321c39c759dc538fc1df9c0383a7ed2c06bc94155202e861b65de39bfe18d1
|
4
|
+
data.tar.gz: 8b53ed1028a7fec8509be9d9b867c033f3dbb274b5235f4ef614cb879668e9b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a717971ee20ecf1b346303477d80fbf1c30e455a27d7fbb1bbc875f6037b64b924bc1ceb318e8b90bba7ef4a4ea9835ae801c878770933f42e2cfbb87c895251
|
7
|
+
data.tar.gz: cdb74b1395ddac124cbd49f7b3b9a268cf4badfbc84792d818dd3fc9193f24b6be41ba9349eaf4cf14804f73b632341c634e5a16e801f34aead70e3ee7784e1a
|
data/CHANGELOG.md
CHANGED
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::URLGenerators::AmakaiGenerator` (or create your generator implementation):
|
669
|
+
```ruby
|
670
|
+
generator = Uploadcare::URLGenerators::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)
|
@@ -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
|
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.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stepan Redka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-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:
|