Class: AWS::Creds::Store

Inherits:
Hash
  • Object
show all
Defined in:
lib/aws/creds/store.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Store

Returns a new instance of Store.



19
20
21
22
23
24
25
26
27
# File 'lib/aws/creds/store.rb', line 19

def initialize opts={}
  # :keytab => false to disable autoloading
  keytab = opts[:keytab] || '~/.awscreds'
  import_keytab keytab if keytab

  @default = opts[:default]
  @default ||= ENV['AWS_IDENTITY'] unless opts[:ignore_environment]
  @default ||= 'default'
end

Instance Method Details

#[](name) ⇒ Object



37
38
39
# File 'lib/aws/creds/store.rb', line 37

def [] name
  super name.to_s
end

#credentialsObject



33
34
35
# File 'lib/aws/creds/store.rb', line 33

def credentials
  values
end

#default?(name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/aws/creds/store.rb', line 45

def default? name
  name == @default
end

#default_keypairObject



41
42
43
# File 'lib/aws/creds/store.rb', line 41

def default_keypair
  self[@default]
end

#identitiesObject



29
30
31
# File 'lib/aws/creds/store.rb', line 29

def identities
  keys
end

#import_keytab(path) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/aws/creds/store.rb', line 49

def import_keytab path
  read_config(path).lines.each do |line, idx|
    fields = line.chomp.split ':'
    raise InvalidKeyTab.new path, "missing fields line #{idx}" unless fields.length >= 3
    self[fields[0]] = KeyPair.new fields[1], fields[2]
  end
  self
end

#read_config(path) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/aws/creds/store.rb', line 58

def read_config path
  path = File.expand_path path

  raise MissingKeyTab.new path, 'does not exist' unless File.exists? path

  mode = File.stat(path).mode & 07777

  unless mode & 07077 == 0
    raise UnsafePerms.new path, "unsafe permissions (#{sprintf '%#04o', mode}); please chmod go= #{File.expand_path path}"
  end

  File.read path
end