Class: AliyunSlsSdk::Util
- Inherits:
-
Object
- Object
- AliyunSlsSdk::Util
- Defined in:
- lib/aliyun_sls_sdk/util.rb
Class Method Summary collapse
- .cal_md5(content) ⇒ Object
- .canonicalized_log_headers(headers) ⇒ Object
- .canonicalized_resource(resource, params) ⇒ Object
- .compress_data(data) ⇒ Object
- .get_request_authorization(method, resource, key, params, headers) ⇒ Object
- .hmac_sha1(content, key) ⇒ Object
- .url_encode(params) ⇒ Object
Class Method Details
.cal_md5(content) ⇒ Object
13 14 15 |
# File 'lib/aliyun_sls_sdk/util.rb', line 13 def self.cal_md5(content) Digest::MD5.hexdigest(content).upcase end |
.canonicalized_log_headers(headers) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aliyun_sls_sdk/util.rb', line 21 def self.canonicalized_log_headers(headers) h = {} headers.each { |k, v| if k =~ /x-log-.*/ or k =~ /x-acs-.*/ h[k.downcase] = v end } h.keys.sort.map { |e| "#{e}:#{h[e].gsub(/^\s+/, '')}" }.join($/) + $/ end |
.canonicalized_resource(resource, params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aliyun_sls_sdk/util.rb', line 37 def self.canonicalized_resource(resource, params) if not params.empty? urlString = params.keys.sort.map { |k| "#{k}=#{params[k]}" }.join('&') return resource+"?"+urlString else return resource end end |
.compress_data(data) ⇒ Object
9 10 11 |
# File 'lib/aliyun_sls_sdk/util.rb', line 9 def self.compress_data(data) Zlib::Deflate.deflate(data, 6) end |
.get_request_authorization(method, resource, key, params, headers) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/aliyun_sls_sdk/util.rb', line 48 def self.(method, resource, key, params, headers) if not key return '' end content = method + "\n" if headers['Content-MD5'] content += headers['Content-MD5'] end content += "\n" if headers['Content-Type'] content += headers['Content-Type'] end content += "\n" content += headers['Date']+"\n" content += Util.canonicalized_log_headers(headers) content += Util.canonicalized_resource(resource, params) return Util.hmac_sha1(content, key) end |
.hmac_sha1(content, key) ⇒ Object
17 18 19 |
# File 'lib/aliyun_sls_sdk/util.rb', line 17 def self.hmac_sha1(content, key) Base64.encode64((HMAC::SHA1.new(key) << content).digest).rstrip() end |
.url_encode(params) ⇒ Object
33 34 35 |
# File 'lib/aliyun_sls_sdk/util.rb', line 33 def self.url_encode(params) # todo end |