Class: Itamae::Secrets::Keychain

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/secrets/keychain.rb

Defined Under Namespace

Classes: KeyNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Keychain

Returns a new instance of Keychain.



9
10
11
# File 'lib/itamae/secrets/keychain.rb', line 9

def initialize(path)
  @path = Pathname.new(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/itamae/secrets/keychain.rb', line 13

def path
  @path
end

Instance Method Details

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/itamae/secrets/keychain.rb', line 15

def exist?(name)
  @path.join(name).exist?
end

#load(name) ⇒ Object



19
20
21
22
23
# File 'lib/itamae/secrets/keychain.rb', line 19

def load(name)
  AesKey.load_json @path.join(name).read
rescue File::ENOENT
  raise KeyNotFound, "Couldn't find key #{name.inspect}"
end

#save(key) ⇒ Object



25
26
27
28
29
# File 'lib/itamae/secrets/keychain.rb', line 25

def save(key)
  open(@path.join(key.name), 'w', 0600) do |io|
    io.puts key.to_json
  end
end