class Security::Keychain

Constants

DOMAINS

Attributes

filename[R]

Public Class Methods

create(filename, password) click to toggle source
# File lib/security/keychain.rb, line 33
def create(filename, password)
  raise NotImplementedError
end
default_keychain() click to toggle source
# File lib/security/keychain.rb, line 51
def default_keychain
  keychains_from_output(`security default-keychain`).first
end
list(domain = :user) click to toggle source
# File lib/security/keychain.rb, line 37
def list(domain = :user)
  raise ArgumentError "Invalid domain #{domain}, expected one of: #{DOMAINS}" unless DOMAINS.include?(domain)

  keychains_from_output(`security list-keychains -d #{domain}`)
end
lock() click to toggle source
# File lib/security/keychain.rb, line 43
def lock
  system %(security lock-keychain -a)
end
login_keychain() click to toggle source
# File lib/security/keychain.rb, line 55
def login_keychain
  keychains_from_output(`security login-keychain`).first
end
new(filename) click to toggle source
# File lib/security/keychain.rb, line 12
def initialize(filename)
  @filename = filename
end
unlock(password) click to toggle source
# File lib/security/keychain.rb, line 47
def unlock(password)
  system %(security unlock-keychain -p #{password.shellescape})
end

Private Class Methods

keychains_from_output(output) click to toggle source
# File lib/security/keychain.rb, line 61
def keychains_from_output(output)
  output.split(/\n/).collect { |line| new(line.strip.gsub(/^"|"$/, '')) }
end

Public Instance Methods

delete() click to toggle source
# File lib/security/keychain.rb, line 28
def delete
  system %(security delete-keychain #{@filename.shellescape})
end
info() click to toggle source
# File lib/security/keychain.rb, line 16
def info
  system %(security show-keychain-info #{@filename.shellescape})
end
lock() click to toggle source
# File lib/security/keychain.rb, line 20
def lock
  system %(security lock-keychain #{@filename.shellescape})
end
unlock(password) click to toggle source
# File lib/security/keychain.rb, line 24
def unlock(password)
  system %(security unlock-keychain -p #{password.shellescape} #{@filename.shellescape})
end