class Keylime::FileKeychainSegment
Stub segment for if keylime is running on a non-Mac
Public Class Methods
new(keychain)
click to toggle source
# File lib/keylime/credential.rb, line 82 def initialize(keychain) @keychain = keychain || '~/.keylime' end
Public Instance Methods
create(fields = {})
click to toggle source
# File lib/keylime/credential.rb, line 93 def create(fields = {}) raise('No fields given') if fields.empty? fields = stringify(fields) fields['ref'] = self new = FileKeychainObject.new(fields) write_file! entries + [new] new end
delete(fields = {})
click to toggle source
# File lib/keylime/credential.rb, line 102 def delete(fields = {}) raise('No fields given') if fields.empty? fields = stringify(fields) new = entries.select do |x| fields.any? { |k, v| x.fields[k] != v } end write_file! new end
where(fields = {})
click to toggle source
# File lib/keylime/credential.rb, line 86 def where(fields = {}) fields = stringify(fields) entries.select do |x| fields.all? { |k, v| x.fields[k] == v } end end
Private Instance Methods
create_file!()
click to toggle source
# File lib/keylime/credential.rb, line 121 def create_file! write_file!([]) end
entries()
click to toggle source
# File lib/keylime/credential.rb, line 113 def entries create_file! unless File.exist? file YAML.safe_load(File.read(file))['credentials'].map do |x| x['ref'] = self FileKeychainObject.new(x) end end
file()
click to toggle source
# File lib/keylime/credential.rb, line 131 def file @file ||= File.expand_path @keychain end
stringify(fields)
click to toggle source
# File lib/keylime/credential.rb, line 135 def stringify(fields) fields.map { |k, v| [k.to_s, v] }.to_h end
write_file!(entries)
click to toggle source
# File lib/keylime/credential.rb, line 125 def write_file!(entries) File.open(file, 'w') do |fh| fh << YAML.dump('credentials' => entries.map(&:fields)) end end