mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-14 15:26:13 +10:00
修正授权凭证算法和相关测试用例。
This commit is contained in:
+4
-2
@@ -10,11 +10,13 @@ module Qiniu
|
||||
include Utils
|
||||
|
||||
def call_with_signature(url, data, retry_times = 0, options = {})
|
||||
http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data)})
|
||||
code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
|
||||
[code, data]
|
||||
end
|
||||
|
||||
def request(url, data = nil, options = {})
|
||||
Auth.call_with_signature(url, data, 0, options)
|
||||
code, data = Auth.call_with_signature(url, data, 0, options)
|
||||
[code, data]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ module Qiniu
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
execs << "op=/#{command}/#{encoded_uri}"
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" }
|
||||
end # batch
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
@@ -101,6 +101,14 @@ module Qiniu
|
||||
target_encoded_entry_uri = encode_entry_uri(target_bucket, target_key)
|
||||
%Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
|
||||
end # _generate_cp_or_mv_opstr
|
||||
|
||||
def _batch_cp_or_mv(command, *op_args)
|
||||
execs = []
|
||||
op_args.each do |e|
|
||||
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" }
|
||||
end # _batch_cp_or_mv
|
||||
end
|
||||
end # module Storage
|
||||
end # module Qiniu
|
||||
|
||||
+4
-1
@@ -126,7 +126,7 @@ module Qiniu
|
||||
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
|
||||
end
|
||||
|
||||
def generate_qbox_signature(url, params)
|
||||
def generate_qbox_signature(url, params, mime = nil)
|
||||
access_key = Config.settings[:access_key]
|
||||
secret_key = Config.settings[:secret_key]
|
||||
uri = URI.parse(url)
|
||||
@@ -138,6 +138,9 @@ module Qiniu
|
||||
params_string = generate_query_string(params)
|
||||
signature += params_string
|
||||
end
|
||||
if mime.is_a?(String) && mime == "application/x-www-form-urlencoded" && params.is_a?(String)
|
||||
signature += params
|
||||
end
|
||||
hmac = HMAC::SHA1.new(secret_key)
|
||||
hmac.update(signature)
|
||||
encoded_digest = urlsafe_base64_encode(hmac.digest)
|
||||
|
||||
@@ -82,22 +82,25 @@ module Qiniu
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
code, data = Storage.batch_copy @bucket, @key, @bucket, @key2
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
|
||||
code, data = Storage.delete @bucket, @key2
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.batch_move [@bucket, @key, @bucket, @key2]
|
||||
code, data = Storage.batch_move @bucket, @key, @bucket, @key2
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
@@ -105,12 +108,11 @@ module Qiniu
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu.batch_move [@bucket, @key2, @bucket, @key]
|
||||
code3, data3 = Storage.batch_move @bucket, @key2, @bucket, @key
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".publish" do
|
||||
|
||||
Reference in New Issue
Block a user