Class: Leeloo::PrivateLocalFileSystemKeystore

Inherits:
Keystore
  • Object
show all
Defined in:
lib/leeloo/keystore.rb

Direct Known Subclasses

GpgPrivateLocalFileSystemKeystore

Instance Attribute Summary collapse

Attributes inherited from Keystore

#name

Instance Method Summary collapse

Methods inherited from Keystore

#footprint, #init, #sync

Constructor Details

#initialize(name, path) ⇒ PrivateLocalFileSystemKeystore

Returns a new instance of PrivateLocalFileSystemKeystore.



72
73
74
75
76
# File 'lib/leeloo/keystore.rb', line 72

def initialize name, path
  super name
  @path = path
  FileUtils.mkdir_p "#{@path}/secrets"
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



70
71
72
# File 'lib/leeloo/keystore.rb', line 70

def path
  @path
end

Instance Method Details

#==(keystore) ⇒ Object



95
96
97
# File 'lib/leeloo/keystore.rb', line 95

def == keystore
  self.name == keystore.name && self.path == keystore.path
end

#find_secrets(path) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/leeloo/keystore.rb', line 86

def find_secrets path
  elements = []
  Dir.glob("#{path}/**") do |element|
    elements << secret_of(element) unless Dir.exist? element
    elements << find_secrets(element) if Dir.exist? element
  end
  return elements.flatten
end

#footprint_of(name) ⇒ Object



108
109
110
111
# File 'lib/leeloo/keystore.rb', line 108

def footprint_of name
  secret = secret_from_name name
  { "footprint" => secret.footprint, "keystore" => self.name, "secret" => secret.name }
end

#keysObject



82
83
84
# File 'lib/leeloo/keystore.rb', line 82

def keys
  []
end

#secret_from_footprint(footprint) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/leeloo/keystore.rb', line 113

def secret_from_footprint footprint
  secret = secret_from_name footprint["secret"]
  unless secret.footprint == footprint["footprint"]
    raise "footprint is not valid"
  end
  secret
end

#secret_from_name(name) ⇒ Object



104
105
106
# File 'lib/leeloo/keystore.rb', line 104

def secret_from_name name
  secret_of "#{path}/secrets/#{name}"
end

#secret_of(path) ⇒ Object



99
100
101
102
# File 'lib/leeloo/keystore.rb', line 99

def secret_of path
  name = path.gsub("#{@path}/secrets/", "")
  LocalFileSystemSecret.new path, name
end

#secretsObject



78
79
80
# File 'lib/leeloo/keystore.rb', line 78

def secrets
  find_secrets "#{@path}/secrets"
end