Class: AWS::Core::DefaultSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/default_signer.rb

Overview

Computes signatures using credentials that are stored in memory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, session_token = nil) ⇒ DefaultSigner

Returns a new instance of DefaultSigner.

Parameters:

  • access_key_id (String)

    The Access Key ID used to sign requests.

  • secret_access_key (String)

    The Secret Access Key used to sign requests.

  • session_token (String) (defaults to: nil)

    The Session Token used to sign requests. You can get credentials that include a session token using the STS class.



41
42
43
44
45
46
47
48
49
# File 'lib/aws/core/default_signer.rb', line 41

def initialize(access_key_id, secret_access_key, session_token = nil)

  @access_key_id = access_key_id
  @secret_access_key = secret_access_key
  @session_token = session_token

  raise "Missing credentials" unless access_key_id and secret_access_key

end

Instance Attribute Details

#access_key_idString (readonly)

Returns The Access Key ID used to sign requests.

Returns:

  • (String)

    The Access Key ID used to sign requests.



24
25
26
# File 'lib/aws/core/default_signer.rb', line 24

def access_key_id
  @access_key_id
end

#secret_access_keyString (readonly)

Returns The Secret Access Key used to sign requests.

Returns:

  • (String)

    The Secret Access Key used to sign requests.



27
28
29
# File 'lib/aws/core/default_signer.rb', line 27

def secret_access_key
  @secret_access_key
end

#session_tokenString (readonly)

Returns The Session Token used to sign requests.

Returns:

  • (String)

    The Session Token used to sign requests.



30
31
32
# File 'lib/aws/core/default_signer.rb', line 30

def session_token
  @session_token
end

Instance Method Details

#sign(string_to_sign, digest_method = 'sha256') ⇒ Object

Signs a string using the credentials stored in memory.

Parameters:

  • string_to_sign (String)

    The string to sign.

  • digest_method (String) (defaults to: 'sha256')

    The digest method to use when computing the HMAC digest.



57
58
59
60
61
62
63
# File 'lib/aws/core/default_signer.rb', line 57

def sign(string_to_sign, digest_method = 'sha256')
  Base64.encode64(
    OpenSSL::HMAC.digest(
      OpenSSL::Digest::Digest.new(digest_method),
      secret_access_key, 
      string_to_sign)).strip
end