Class: Cipherpipe::Vault::EC2Token

Inherits:
Object
  • Object
show all
Defined in:
lib/cipherpipe/vault/ec2_token.rb

Constant Summary collapse

ConnectionError =
Class.new Cipherpipe::Error
URL =
URI.parse(
  "http://169.254.169.254/latest/dynamic/instance-identity/pkcs7"
)
NONCE_FILE =
File.expand_path "~/.cipherpipe-nonce"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(external_source) ⇒ EC2Token

Returns a new instance of EC2Token.



17
18
19
# File 'lib/cipherpipe/vault/ec2_token.rb', line 17

def initialize(external_source)
  @external_source = external_source
end

Class Method Details

.call(external_source) ⇒ Object



13
14
15
# File 'lib/cipherpipe/vault/ec2_token.rb', line 13

def self.call(external_source)
  new(external_source).call
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
# File 'lib/cipherpipe/vault/ec2_token.rb', line 21

def call
  response = ::Vault.auth.aws_ec2 external_source.ec2_role, signature, nonce

  if response.auth.[:nonce]
    File.write NONCE_FILE, response.auth.[:nonce]
  end

  response.auth.client_token
end