qcloud-cos 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/lib/qcloud_cos/http.rb +5 -3
- data/lib/qcloud_cos/object_manager.rb +23 -9
- data/lib/qcloud_cos/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd9db0f6abcec37392902c6ccfcd9847e4b08a5e947c7adc0dd3b3f23a8f28a8
|
4
|
+
data.tar.gz: 7140757a257df3a2c838d15291bcec19cd9aa655fdb2d8d8278c820e1060067c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9e065e41b93e2fa6cc48da025662ab02e3418016c5e790ae2120576f7dba7cb53995f794db4ae09ad0bb8243bcc2221422c19dad8784c22a8d4f30ff35c012d
|
7
|
+
data.tar.gz: ab2e6be546bfa548f4a3ee9ef919f58297dcaeb574cedab27b1258fdb1c47c1e699f59c72e9e6889d38bb611d01cb089ac66f1abd39291fdf8b19227eb8169a8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/qcloud_cos/http.rb
CHANGED
@@ -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,
|
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, :
|
5
|
-
def initialize(bucket: nil, region: nil, access_id: nil, access_key: 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
|
-
@
|
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,
|
15
|
-
|
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
|
-
|
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://#{
|
42
|
+
URI.join("https://#{host}", path).to_s
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
data/lib/qcloud_cos/version.rb
CHANGED
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.
|
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:
|
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
|
-
|
117
|
-
|
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: []
|