qinium 0.1.1 → 0.2.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: 97006dadb420603b659536192b0d996ddb925d6ec024fc5553970b437b45553e
4
- data.tar.gz: 2de51b37c7a5e8c314724c2594525885e086ea5d764888b922d6f91cec2e1c66
3
+ metadata.gz: 1882ca15da2a4be5ef0fd71015e167d3e5c1803bd8be620aebf092407604fc14
4
+ data.tar.gz: 5ba5f38fdde0eeede9f67cad0405b5cf4cc92a5d457b45c73194e3c569369869
5
5
  SHA512:
6
- metadata.gz: 5f907d3494a958568d0aeabfc978133b1eabd46f04da4e55e536da7b8611e0bec2dc0f1a92772c4e588ad5c9f5f6f46c6abb6d5e9842abc79f091de5f4b5553e
7
- data.tar.gz: ddc54d441f0dca3e48a6f7a14762f7b5d37624e10100a2561b1ef06bd8541c3156c5ed6d72fec2b194b5d307cb55803be874f67028349c848254a4c3127eb174
6
+ metadata.gz: eab9765b2a129823cdf304e3848b6137119bc04b866fa2dd3a3269ba28659d3d8e47ff9bde86488defe2fc2f5b719d18ef71429cd8af3c88f58774802bf40e98
7
+ data.tar.gz: f74c6321970f164702754a4ba9a512898c83da2528824d487644c5536aebbeaa6e010a709d5069beb43814a419fe3035e07e41d1fb5bb921d69bf3b6a3624cd9
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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qinium (0.1.1)
4
+ qinium (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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/client.rb CHANGED
@@ -73,7 +73,7 @@ class Qinium
73
73
  end
74
74
 
75
75
  logger.debug "POST #{uri}"
76
- logger.debug " body: #{req_body[0, 50]}"
76
+ logger.debug " body: #{req_body[0, 50]}" if req_body.is_a?(String)
77
77
  logger.debug " headers: #{opts.to_json}"
78
78
 
79
79
  req = Net::HTTP::Post.new(uri)
@@ -123,16 +123,5 @@ class Qinium
123
123
  def success?(http_code)
124
124
  self.class.success?(http_code)
125
125
  end
126
-
127
- def self.to_query(params)
128
- if params.is_a?(Hash)
129
- total_param = params.map do |key, value|
130
- %(#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s).gsub("+", "%20")})
131
- end
132
- return total_param.join("&")
133
- end
134
-
135
- params
136
- end
137
126
  end
138
127
  end
data/lib/qinium/config.rb CHANGED
@@ -35,7 +35,7 @@ class Qinium
35
35
  enable_debug: true,
36
36
  tmpdir: Dir.tmpdir + File::SEPARATOR + "QiniuRuby",
37
37
  multi_region: false,
38
- bucket_private: false
38
+ public: true
39
39
  }.freeze
40
40
  end
41
41
 
@@ -64,7 +64,7 @@ class Qinium
64
64
  raise Error, "bucket is missing" if Utils.blank?(bucket)
65
65
 
66
66
  cache.read(access_key, bucket) do
67
- query = Client.to_query(ak: access_key, bucket: bucket)
67
+ query = Utils.to_query_string(ak: access_key, bucket: bucket)
68
68
  url = "#{config.uc_host}/v1/query?#{query}"
69
69
  http = Client.new(config)
70
70
  code, body, headers = http.get(url)
data/lib/qinium/utils.rb CHANGED
@@ -31,7 +31,7 @@ class Qinium
31
31
  value = hash[key]
32
32
  next if value.nil?
33
33
 
34
- args.push("#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}")
34
+ args.push("#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s).gsub("+", "%20")}")
35
35
  end
36
36
  args.join("&")
37
37
  end
@@ -1,3 +1,3 @@
1
1
  class Qinium
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.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.1
4
+ version: 0.2.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-10 00:00:00.000000000 Z
11
+ date: 2024-05-09 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