qinium 0.1.2 → 0.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: 271f6fc00f432d27ac6c9437440fc7e6406d3fcbea3130a717e4f3de8ec9f271
4
- data.tar.gz: 3228755d7601c622c4320658a0db8893f882754ff8956babf6ca8ae6939c7ad2
3
+ metadata.gz: 548c73431631f012020ed8e4c94c83017bfdec9454d26b009549f04d8a5204a9
4
+ data.tar.gz: 1c45033d1fd635870afe11150b871c471898a52c234f8b8c99c9462298d2024d
5
5
  SHA512:
6
- metadata.gz: dc78e9d948f1602c55cae937ea98f1df63ec8ff2b5a555514fb030c82f23928b999512c529d339bf4fda672b37ba7bed02274a1c1729bf5feff180df53760cd7
7
- data.tar.gz: 60b091e1a00504f25539fb6c890782d45cc4a72312952590408fa9880cdc950c30e042b85ba1fd04b708602356e94c6405d335cee71e5ce49bc73ac150e91722
6
+ metadata.gz: bf283cf247ef4fbe2482370f844bbeb50a09f06e82920bfdd1646aca372438b1c6d53820063f39ef80f9f6cf8bc2550907dab667e1675ec8e38f3739ba6fa06a
7
+ data.tar.gz: 971575d161e4fbf23253b8b380115321b671a8740c5f54ec283e8c71dd7bbac9d380d1657e4e94386c239aba4228183bcf6663b38888d9f6c3bfb5f45c25e2da
data/CHANGELOG.md CHANGED
@@ -3,3 +3,8 @@
3
3
  ## [0.1.0] - 2022-08-10
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.2.0] - 2024-05-09
8
+
9
+ - Rename config.bucket_private to config.public
10
+ - Support private download url
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Qinium
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/qinium`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Qiniu Cloud Storage SDK for Ruby, support multiple configure for SaaS product.
6
4
 
7
5
  ## Installation
8
6
 
data/lib/qinium/auth.rb CHANGED
@@ -32,5 +32,50 @@ class Qinium
32
32
  sign = calculate_hmac_sha1_digest(secret_key, signing_str)
33
33
  Utils.urlsafe_base64_encode(sign)
34
34
  end
35
+
36
+ def authorize_download_url(domain, key, access_key, secret_key, args = {})
37
+ url_encoded_key = CGI::escape(key)
38
+ schema = args[:schema] || "http"
39
+ port = args[:port]
40
+
41
+ if port.nil? then
42
+ download_url = "#{schema}://#{domain}/#{url_encoded_key}"
43
+ else
44
+ download_url = "#{schema}://#{domain}:#{port}/#{url_encoded_key}"
45
+ end
46
+
47
+ ### URL变换:追加FOP指令
48
+ if args[:fop].is_a?(String) && args[:fop] != '' then
49
+ if download_url.include?('?')
50
+ # 已有参数
51
+ download_url = "#{download_url}&#{args[:fop]}"
52
+ else
53
+ # 尚无参数
54
+ download_url = "#{download_url}?#{args[:fop]}"
55
+ end
56
+ end
57
+
58
+ ### 授权期计算
59
+ e = Time.now.to_i + args[:expires_in]
60
+
61
+ ### URL变换:追加授权期参数
62
+ if download_url.include?('?')
63
+ # 已有参数
64
+ download_url = "#{download_url}&e=#{e}"
65
+ else
66
+ # 尚无参数
67
+ download_url = "#{download_url}?e=#{e}"
68
+ end
69
+
70
+ ### 生成数字签名
71
+ sign = calculate_hmac_sha1_digest(secret_key, download_url)
72
+ encoded_sign = Utils.urlsafe_base64_encode(sign)
73
+
74
+ ### 生成下载授权凭证
75
+ dntoken = "#{access_key}:#{encoded_sign}"
76
+
77
+ ### 返回下载授权URL
78
+ "#{download_url}&token=#{dntoken}"
79
+ end
35
80
  end
36
81
  end
data/lib/qinium/config.rb CHANGED
@@ -14,6 +14,10 @@ class Qinium
14
14
  HostManager.new(self).up_host(bucket)
15
15
  end
16
16
 
17
+ def fetch_host(bucket = self.bucket, opts = {})
18
+ self[:fetch_host] || HostManager.new(self).fetch_host(bucket, opts)
19
+ end
20
+
17
21
  def put_policy_options
18
22
  @put_policy_options ||= self[:put_policy_options] || Configurable.new
19
23
  end
@@ -35,7 +39,7 @@ class Qinium
35
39
  enable_debug: true,
36
40
  tmpdir: Dir.tmpdir + File::SEPARATOR + "QiniuRuby",
37
41
  multi_region: false,
38
- bucket_private: false
42
+ public: true
39
43
  }.freeze
40
44
  end
41
45
 
@@ -59,6 +59,11 @@ class Qinium
59
59
  hosts[extract_protocol(opts)]["up"]
60
60
  end
61
61
 
62
+ def fetch_host(bucket, opts = {})
63
+ hosts = hosts(bucket)
64
+ hosts[extract_protocol(opts)]["io"][0]
65
+ end
66
+
62
67
  def hosts(bucket)
63
68
  raise Error, "access_key is missing" if Utils.blank?(access_key)
64
69
  raise Error, "bucket is missing" if Utils.blank?(bucket)
data/lib/qinium/object.rb CHANGED
@@ -41,6 +41,12 @@ class Qinium
41
41
  ))
42
42
  end
43
43
 
44
+ def fetch(target_url, key, bucket: self.bucket)
45
+ client.management_post(config.fetch_host(bucket) + '/fetch/' + urlsafe_base64_encode(target_url) + '/to/' + Utils.encode_entry_uri(
46
+ bucket, key
47
+ ))
48
+ end
49
+
44
50
  def list(bucket: self.bucket, marker: "", limit: 1000, prefix: "", delimiter: "")
45
51
  query_string = to_query_string(bucket: bucket, marker: marker, limit: limit, prefix: prefix,
46
52
  delimiter: delimiter)
@@ -1,3 +1,3 @@
1
1
  class Qinium
2
- VERSION = "0.1.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qinium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-16 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Qiniu Cloud Storage SDK for multi-tenant system, can call API with multiple
14
14
  accounts
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.3.7
64
+ rubygems_version: 3.4.19
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Qiniu Cloud Storage SDK for multi-tenant system