class AliyunSlsSdk::Util

Public Class Methods

cal_md5(content) click to toggle source
# File lib/aliyun_sls_sdk/util.rb, line 13
def self.cal_md5(content)
  Digest::MD5.hexdigest(content).upcase
end
canonicalized_log_headers(headers) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/aliyun_sls_sdk/util.rb, line 48
def self.get_request_authorization(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) click to toggle source
# 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) click to toggle source
# File lib/aliyun_sls_sdk/util.rb, line 33
def self.url_encode(params)
  # todo
end