Merge branch 'release/v2.1.0'

This commit is contained in:
404
2012-07-02 18:08:08 +08:00
7 changed files with 38 additions and 10 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
qiniu-rs (2.0.5)
qiniu-rs (2.1.0)
json (~> 1.7.3)
mime-types (~> 1.19)
rest-client (~> 1.6.7)
+4
View File
@@ -115,6 +115,10 @@ module Qiniu
Image.preivew_url(url, spec)
end
def generate_upload_token(scope, expires_in, callback_url = nil, return_url = nil)
Utils.generate_upload_token(scope, expires_in, callback_url, return_url)
end
end
end
+1 -1
View File
@@ -59,7 +59,7 @@ module Qiniu
end
def call_with_signature(url, data, retry_times = 0)
code, data = http_request url, data, {:signature_auth => true}
code, data = http_request url, data, {:qbox_signature_token => generate_qbox_signature(url, data)}
[code, data]
end
-2
View File
@@ -21,9 +21,7 @@ module Qiniu
:content_type => 'application/x-www-form-urlencoded',
:auth_url => "https://acc.qbox.me/oauth2/token",
:rs_host => "http://rs.qbox.me:10100",
#:rs_host => "http://localhost:10100",
:io_host => "http://iovip.qbox.me",
#:io_host => "http://localhost:10200",
:client_id => "a75604760c4da4caaa456c0c5895c061c3065c5a",
:client_secret => "75df554a39f58accb7eb293b550fa59618674b7d",
:access_key => "",
+23 -5
View File
@@ -38,12 +38,15 @@ module Qiniu
:accept => :json,
:user_agent => Config.settings[:user_agent]
}
if options[:signature_auth] && options[:signature_auth] == true
signature_token = generate_qbox_signature(Config.settings[:access_key], Config.settings[:secret_key], url, data)
header_options.merge!('Authorization' => "QBox #{signature_token}")
auth_token = nil
if !options[:qbox_signature_token].nil? && !options[:qbox_signature_token].empty?
auth_token = 'QBox ' + options[:qbox_signature_token]
#elsif !options[:upload_signature_token].nil? && !options[:upload_signature_token].empty?
# auth_token = 'UpToken ' + options[:upload_signature_token]
elsif options[:access_token]
header_options.merge!('Authorization' => "Bearer #{options[:access_token]}")
auth_token = 'Bearer ' + options[:access_token]
end
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
case options[:method]
when :get
response = RestClient.get url, header_options
@@ -130,7 +133,9 @@ module Qiniu
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
end
def generate_qbox_signature(access_key, secret_key, url, params)
def generate_qbox_signature(url, params)
access_key = Config.settings[:access_key]
secret_key = Config.settings[:secret_key]
uri = URI.parse(url)
signature = uri.path
query_string = uri.query
@@ -146,6 +151,19 @@ module Qiniu
%Q(#{access_key}:#{encoded_digest})
end
def generate_upload_token(scope, expires_in, callback_url = nil, return_url = nil)
access_key = Config.settings[:access_key]
secret_key = Config.settings[:secret_key]
params = {:scope => scope, :deadline => Time.now.to_i + expires_in}
params[:callbackUrl] = callback_url if !callback_url.nil? && !calback_url.empty?
params[:returnUrl] = return_url if !return_url.nil? && !return_url.empty?
signature = urlsafe_base64_encode(params.to_json)
hmac = HMAC::SHA1.new(secret_key)
hmac.update(signature)
encoded_digest = urlsafe_base64_encode(hmac.digest)
%Q(#{access_key}:#{encoded_digest}:#{signature})
end
end
end
end
+1 -1
View File
@@ -2,6 +2,6 @@
module Qiniu
module RS
VERSION = "2.0.5"
VERSION = "2.1.0"
end
end
+8
View File
@@ -149,5 +149,13 @@ module Qiniu
end
end
context ".generate_upload_token" do
it "should works" do
data = Qiniu::RS.generate_upload_token('test_bucket', 3600)
data.should_not be_empty
puts data.inspect
end
end
end
end