better_ross 0.0.3 → 0.0.4
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 +4 -4
- data/lib/ross/client.rb +38 -9
- data/ross.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f1d2390671663b426392fce34c982614ce9110
|
4
|
+
data.tar.gz: a94351861b7ed3b6bd668f02a35ac03e35f2d39c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e04beaec8462b1ade61b1b7ccbfb7cdfd58863ab3ce5d68df70cdd66b1f6120f6f6997e5dbf7641da28d387b2e2e1931f8747afdf269d67be61b5bc067a5d8b
|
7
|
+
data.tar.gz: 73b092e5b364abba6aeb95b0a205655465a5273b8cff0bb4588eec4eea278034d37b1b4d3cb91df59f619f1a784351c8fcc0a627794b304ac406693aa692eb52
|
data/lib/ross/client.rb
CHANGED
@@ -16,21 +16,42 @@ module ROSS
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def put(path, content, options={})
|
19
|
+
def put(path, content, options={}, xoss = {})
|
20
20
|
# content_md5 = Digest::MD5.hexdigest(content)
|
21
|
-
content_type = options[:content_type]
|
21
|
+
content_type = options.has_key?(:content_type) ? options[:content_type] : "application/octet-stream"
|
22
22
|
date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
23
|
-
auth_sign = sign("PUT", path, date, content_type) #, content_md5)
|
24
23
|
headers = {
|
25
|
-
"Authorization" =>
|
24
|
+
"Authorization" => auth_sign("PUT", path, date, content_type, nil, xoss),
|
26
25
|
"Content-Type" => content_type,
|
27
|
-
"Content-Length" => content.length,
|
28
26
|
"Date" => date,
|
29
|
-
"Host" => @aliyun_host
|
27
|
+
"Host" => @aliyun_host
|
30
28
|
}
|
29
|
+
headers["Content-Length"] = content.length unless content.nil? # content can be nil
|
30
|
+
xoss.each_pair{|k,v| headers["x-oss-#{k}"] = v }
|
31
31
|
response = RestClient.put(request_url(path), content, headers)
|
32
32
|
end
|
33
33
|
|
34
|
+
def delete(path)
|
35
|
+
date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
36
|
+
content_type = nil
|
37
|
+
headers = {
|
38
|
+
"Authorization" => auth_sign("DELETE", path, date, content_type),
|
39
|
+
"Content-Type" => content_type,
|
40
|
+
"Date" => date,
|
41
|
+
"Host" => @aliyun_host
|
42
|
+
}
|
43
|
+
RestClient.delete(request_url(path), headers)
|
44
|
+
end
|
45
|
+
|
46
|
+
def copy(sour_path, dest_path)
|
47
|
+
put(dest_path, nil, {content_type: nil}, {'copy-source' => bucket_path(sour_path)})
|
48
|
+
end
|
49
|
+
|
50
|
+
def rename(sour_path, dest_path)
|
51
|
+
copy(sour_path, dest_path)
|
52
|
+
delete(path)
|
53
|
+
end
|
54
|
+
|
34
55
|
def put_file(path, file, options = {})
|
35
56
|
put(path, File.read(file), options)
|
36
57
|
end
|
@@ -52,15 +73,23 @@ module ROSS
|
|
52
73
|
end
|
53
74
|
|
54
75
|
private
|
55
|
-
def sign(verb, path, date, content_type = nil, content_md5 = nil)
|
56
|
-
canonicalized_oss_headers =
|
57
|
-
canonicalized_resource =
|
76
|
+
def sign(verb, path, date, content_type = nil, content_md5 = nil, xoss = {})
|
77
|
+
canonicalized_oss_headers = xoss.sort.map{|k,v| "x-oss-#{k}:".downcase + v + "\n"}.join
|
78
|
+
canonicalized_resource = bucket_path(path)
|
58
79
|
string_to_sign = "#{verb}\n\n#{content_type}\n#{date}\n#{canonicalized_oss_headers}#{canonicalized_resource}"
|
59
80
|
digest = OpenSSL::Digest.new('sha1')
|
60
81
|
h = OpenSSL::HMAC.digest(digest, @appkey, string_to_sign)
|
61
82
|
Base64.encode64(h).strip
|
62
83
|
end
|
63
84
|
|
85
|
+
def auth_sign(verb, path, date, content_type = nil, content_md5 = nil, xoss = {})
|
86
|
+
"OSS #{@appid}:#{sign(verb, path, date, content_type, content_md5, xoss)}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def bucket_path(path)
|
90
|
+
"/#{@bucket_name}/#{path.gsub(/^\//, '')}"
|
91
|
+
end
|
92
|
+
|
64
93
|
def request_url(path)
|
65
94
|
"http://#{@aliyun_host}/#{@bucket_name}/#{URI.encode(path)}"
|
66
95
|
end
|
data/ross.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_ross
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fizz Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|