Class: Aliyun::Oss::Authorization
- Inherits:
-
Object
- Object
- Aliyun::Oss::Authorization
- Defined in:
- lib/aliyun/oss/authorization.rb
Constant Summary collapse
- PROVIDER =
'OSS'
- OVERRIDE_RESPONSE_LIST =
%w( response-content-type response-content-language response-cache-control logging response-content-encoding acl uploadId uploads partNumber group link delete website location objectInfo response-expires response-content-disposition cors lifecycle restore qos referer append position)
Class Method Summary collapse
- .concat_content_string(verb, time, options = {}) ⇒ Object
-
.get_authorization(access_key, secret_key, options = {}) ⇒ String
Get authorization key.
-
.get_base64_policy(policy) ⇒ String
Get base64 encoded string, used to fill policy field.
- .get_cononicalized_oss_headers(headers) ⇒ Object
- .get_cononicalized_resource(bucket, key, query) ⇒ Object
-
.get_policy_signature(secret_key, policy) ⇒ String
Get Signature for policy.
-
.get_temporary_signature(secret_key, expire_time, options = {}) ⇒ String
Get temporary Signature.
- .join_values(verb, time, headers, conon_headers, conon_resource) ⇒ Object
- .signature(secret_key, content_string) ⇒ Object
Class Method Details
.concat_content_string(verb, time, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aliyun/oss/authorization.rb', line 83 def self.concat_content_string(verb, time, = {}) headers = .fetch(:headers, {}) conon_headers = get_cononicalized_oss_headers(headers) conon_resource = get_cononicalized_resource( *.values_at(:bucket, :key, :query) ) join_values(verb, time, headers, conon_headers, conon_resource) end |
.get_authorization(access_key, secret_key, options = {}) ⇒ String
Get authorization key
77 78 79 80 81 |
# File 'lib/aliyun/oss/authorization.rb', line 77 def self.(access_key, secret_key, = {}) content_string = concat_content_string([:verb], [:date], ) signature_string = signature(secret_key, content_string) "#{PROVIDER} #{access_key}:#{signature_string.strip}" end |
.get_base64_policy(policy) ⇒ String
Get base64 encoded string, used to fill policy field
44 45 46 |
# File 'lib/aliyun/oss/authorization.rb', line 44 def self.get_base64_policy(policy) Base64.encode64(JSON.generate(policy).force_encoding('utf-8')).delete("\n") end |
.get_cononicalized_oss_headers(headers) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/aliyun/oss/authorization.rb', line 115 def self.get_cononicalized_oss_headers(headers) oss_headers = (headers || {}).select do |key, _| key.to_s.downcase.start_with?('x-oss-') end return if oss_headers.empty? oss_headers.keys.sort.map do |key| "#{key.downcase}:#{oss_headers[key]}" end.join("\n") + "\n" end |
.get_cononicalized_resource(bucket, key, query) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/aliyun/oss/authorization.rb', line 126 def self.get_cononicalized_resource(bucket, key, query) conon_resource = '/' conon_resource += "#{bucket}/" if bucket conon_resource += key if key return conon_resource if query.nil? || query.empty? query_str = query.keys.select { |k| OVERRIDE_RESPONSE_LIST.include?(k) } .sort.map { |k| "#{k}=#{query[k]}" }.join('&') query_str.empty? ? conon_resource : conon_resource + '?' + query_str end |
.get_policy_signature(secret_key, policy) ⇒ String
Get Signature for policy
56 57 58 |
# File 'lib/aliyun/oss/authorization.rb', line 56 def self.get_policy_signature(secret_key, policy) signature(secret_key, get_base64_policy(policy)).strip end |
.get_temporary_signature(secret_key, expire_time, options = {}) ⇒ String
Get temporary Signature
32 33 34 35 |
# File 'lib/aliyun/oss/authorization.rb', line 32 def self.get_temporary_signature(secret_key, expire_time, = {}) content_string = concat_content_string([:verb], expire_time, ) CGI.escape(signature(secret_key, content_string).strip) end |
.join_values(verb, time, headers, conon_headers, conon_resource) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/aliyun/oss/authorization.rb', line 94 def self.join_values(verb, time, headers, conon_headers, conon_resource) [ verb, headers['Content-MD5'].to_s.strip, headers['Content-Type'].to_s.strip, time, conon_headers ].join("\n") + conon_resource end |
.signature(secret_key, content_string) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aliyun/oss/authorization.rb', line 104 def self.signature(secret_key, content_string) utf8_string = content_string.force_encoding('utf-8') Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::SHA1.new, secret_key, utf8_string ) ) end |