Class: Jedlik::SecurityTokenService

Inherits:
Object
  • Object
show all
Defined in:
lib/jedlik/security_token_service.rb

Overview

SecurityTokenService automatically manages the creation and renewal of temporary AWS credentials.

Usage:

credentials = SecurityTokenService.new "id", "secret key"
credentials.access_key_id     # => String
credentials.secret_access_key # => String
credentials.session_token     # => String

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key) ⇒ SecurityTokenService

A SecurityTokenService is initialized for a single AWS user using his credentials.



19
20
21
22
# File 'lib/jedlik/security_token_service.rb', line 19

def initialize access_key_id, secret_access_key
  @_access_key_id = access_key_id
  @_secret_access_key = secret_access_key
end

Instance Method Details

#access_key_idObject

Get a temporary access key id from STS or from cache.



25
26
27
28
# File 'lib/jedlik/security_token_service.rb', line 25

def access_key_id
  obtain_credentials
  @access_key_id
end

#secret_access_keyObject

Get a temporary secret access key from STS or from cache.



31
32
33
34
# File 'lib/jedlik/security_token_service.rb', line 31

def secret_access_key
  obtain_credentials
  @secret_access_key
end

#session_tokenObject

Get a temporary session token from STS or from cache.



37
38
39
40
# File 'lib/jedlik/security_token_service.rb', line 37

def session_token
  obtain_credentials
  @session_token
end

#signatureObject



42
43
44
# File 'lib/jedlik/security_token_service.rb', line 42

def signature
  sign string_to_sign
end

#string_to_signObject



46
47
48
49
50
51
52
53
# File 'lib/jedlik/security_token_service.rb', line 46

def string_to_sign
  [
    "GET",
    "sts.amazonaws.com",
    "/",
    "AWSAccessKeyId=#{@_access_key_id}&Action=GetSessionToken&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=#{CGI.escape authorization_params[:Timestamp]}&Version=2011-06-15"
  ].join("\n")
end