qcloud-cos 0.0.3 → 0.0.5

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: 031e03e9ed5b011e41422461d2b8a40c6d1365751f7eff03a51a732fc3714a25
4
- data.tar.gz: facfc40f4432c5d0b77a1b988a5ab04bc1ef760523a282733188a228e9156b31
3
+ metadata.gz: dd9db0f6abcec37392902c6ccfcd9847e4b08a5e947c7adc0dd3b3f23a8f28a8
4
+ data.tar.gz: 7140757a257df3a2c838d15291bcec19cd9aa655fdb2d8d8278c820e1060067c
5
5
  SHA512:
6
- metadata.gz: d7033bc2f3c3fba54d5d60875c8442059e7dea626b4df46000d0646f6a0d6df85785bc01b29008bd4f14f897bbb0668df2d21c060479911d93167b2bb2093ef6
7
- data.tar.gz: df46f0b7aed195986bf2a6419735df6b2f772224b74576d8a7a5d7407484c8668a38a1e00b8b7d043d9115569c001933ac3ef8356216176816bf378b587ecd4b
6
+ metadata.gz: d9e065e41b93e2fa6cc48da025662ab02e3418016c5e790ae2120576f7dba7cb53995f794db4ae09ad0bb8243bcc2221422c19dad8784c22a8d4f30ff35c012d
7
+ data.tar.gz: ab2e6be546bfa548f4a3ee9ef919f58297dcaeb574cedab27b1258fdb1c47c1e699f59c72e9e6889d38bb611d01cb089ac66f1abd39291fdf8b19227eb8169a8
data/CHANGELOG.md CHANGED
@@ -4,4 +4,8 @@
4
4
 
5
5
  ### 新增
6
6
  * 上传Object
7
- * 复制Object
7
+ * 复制Object
8
+
9
+ ## 0.0.4
10
+ * ObjectManager的put_object支持file或bin_data
11
+ * ObjectManager增加了临时token支持
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qcloud-cos (0.0.3)
4
+ qcloud-cos (0.0.4)
5
5
  activesupport
6
6
  multi_xml
7
7
 
@@ -5,11 +5,12 @@ require 'digest'
5
5
  require 'net/http'
6
6
  module QcloudCos
7
7
  class Http
8
- attr_accessor :access_id, :access_key
8
+ attr_accessor :access_id, :access_key, :token
9
9
 
10
- def initialize(access_id, access_key)
10
+ def initialize(access_id, access_key, token: nil)
11
11
  @access_id = access_id
12
12
  @access_key = access_key
13
+ @token = token
13
14
  end
14
15
 
15
16
  def post(url, body = nil, headers = {})
@@ -30,6 +31,7 @@ module QcloudCos
30
31
 
31
32
  def request(request_klass, url, body = nil, headers = {})
32
33
  uri = URI.parse(url)
34
+ headers["x-cos-security-token"] = token if token
33
35
  headers["Authorization"] = compute_auth(request_klass::METHOD, uri.request_uri, headers)
34
36
  response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
35
37
  request = request_klass.new(uri, headers)
@@ -50,7 +52,7 @@ module QcloudCos
50
52
  q_url_params = query_string.to_s.split("&").map { |s| s.split("=").first }.compact.map(&:downcase).sort.join(";")
51
53
 
52
54
  sign_key = OpenSSL::HMAC.hexdigest("SHA1", access_key, q_sign_time)
53
- http_parameters = query_string.to_s.split("&").map { |s| s.split("=") }.map { |field, value| [field.downcase, value]}.sort_by { |field, value| field}.map { |field, value| [field, value].compact.join("=") }.join("&")
55
+ http_parameters = query_string.to_s.split("&").map { |s| s.split("=") }.map { |field, value| [field.downcase, value] }.sort_by { |field, _| field.to_s }.map { |field, value| [field, value].compact.join("=") }.join("&")
54
56
  http_headers = headers.map { |h, v| [h.downcase, CGI.escape(v)].join("=") }.join("&")
55
57
  http_string = "#{method.downcase}\n#{path}\n#{http_parameters}\n#{http_headers}\n"
56
58
  string_to_sign = "sha1\n#{q_sign_time}\n#{Digest::SHA1.hexdigest(http_string)}\n"
@@ -1,22 +1,24 @@
1
1
  require 'uri'
2
2
  module QcloudCos
3
3
  class ObjectManager
4
- attr_accessor :bucket, :region, :access_id, :access_key, :app_id, :http
5
- def initialize(bucket: nil, region: nil, access_id: nil, access_key: nil, app_id: nil)
4
+ attr_accessor :bucket, :region, :access_id, :access_key, :http, :token
5
+ def initialize(bucket: nil, region: nil, access_id: nil, access_key: nil, token: nil)
6
6
  @bucket = bucket
7
7
  @region = region
8
8
  @access_id = access_id
9
9
  @access_key = access_key
10
- @app_id = app_id
11
- @http = QcloudCos::Http.new(access_id, access_key)
10
+ @token = token
11
+ @http = QcloudCos::Http.new(access_id, access_key, token: token)
12
12
  end
13
13
 
14
- def put_object(path, file, headers = {})
15
- http.put(compute_url(path), file.read, headers)
14
+ def put_object(path, file_or_bin, headers = {})
15
+ data = file_or_bin.respond_to?(:read) ? IO.binread(file_or_bin) : file_or_bin
16
+ http.put(compute_url(path), data, headers)
16
17
  end
17
18
 
18
- def copy_object(path, copy_source)
19
- body = http.put(compute_url(path), nil, 'x-cos-copy-source' => copy_source).body
19
+ def copy_object(path, copy_source, headers = {})
20
+ headers['x-cos-copy-source'] = copy_source
21
+ body = http.put(compute_url(path), nil, headers).body
20
22
  ActiveSupport::HashWithIndifferentAccess.new(ActiveSupport::XmlMini.parse(body))
21
23
  end
22
24
 
@@ -24,8 +26,20 @@ module QcloudCos
24
26
  http.delete(compute_url(path))
25
27
  end
26
28
 
29
+ def delete_objects(pathes, quiet = false)
30
+ data = {
31
+ "Quiet" => quiet,
32
+ "Object" => pathes.map { |p| { "Key" => p } },
33
+ }
34
+ http.post(compute_url("/?delete"), data.to_xml(root: "Delete", skip_instruct: true, skip_types: false), "Content-Type" => "application/xml")
35
+ end
36
+
37
+ def host
38
+ "#{bucket}.cos.#{region}.myqcloud.com"
39
+ end
40
+
27
41
  def compute_url(path)
28
- URI.join("https://#{bucket}.cos.#{region}.myqcloud.com", path).to_s
42
+ URI.join("https://#{host}", path).to_s
29
43
  end
30
44
  end
31
45
  end
@@ -1,3 +1,3 @@
1
1
  module QcloudCos
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qcloud-cos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xuxiangyang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_xml
@@ -98,7 +98,7 @@ metadata:
98
98
  homepage_uri: http://github.com/xuxiangyang/qcloud-cos
99
99
  source_code_uri: http://github.com/xuxiangyang/qcloud-cos
100
100
  changelog_uri: http://github.com/xuxiangyang/qcloud-cos/CHANGELOG.md
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.7
118
- signing_key:
116
+ rubygems_version: 3.4.10
117
+ signing_key:
119
118
  specification_version: 4
120
119
  summary: qcloud cos ruby sdk
121
120
  test_files: []