Module: AliyunSDK::STS::Util

Extended by:
Common::Logging
Defined in:
lib/aliyun_sdk/sts/util.rb

Overview

Util functions to help generate formatted Date, signatures, etc.

Constant Summary

Constants included from Common::Logging

Common::Logging::DEFAULT_LOG_FILE, Common::Logging::MAX_NUM_LOG, Common::Logging::ROTATE_SIZE

Class Method Summary collapse

Methods included from Common::Logging

logger, set_log_file, set_log_level

Class Method Details

.get_signature(verb, params, key) ⇒ Object

Calculate request signatures



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aliyun_sdk/sts/util.rb', line 22

def get_signature(verb, params, key)
  logger.debug("Sign, verb: #{verb}, params: #{params}")

  cano_query = params.sort.map {
    |k, v| [CGI.escape(k), CGI.escape(v)].join('=') }.join('&')

  string_to_sign =
    verb + '&' + CGI.escape('/') + '&' + CGI.escape(cano_query)

  logger.debug("String to sign: #{string_to_sign}")

  Util.sign(key + '&', string_to_sign)
end

.sign(key, string_to_sign) ⇒ String

Sign a string using HMAC and BASE64

Parameters:

  • key (String)

    the secret key

  • string_to_sign (String)

    the string to sign

Returns:



40
41
42
43
# File 'lib/aliyun_sdk/sts/util.rb', line 40

def sign(key, string_to_sign)
  Base64.strict_encode64(
    OpenSSL::HMAC.digest('sha1', key, string_to_sign))
end