Class: Security::Keychain

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

Constant Summary collapse

DOMAINS =
[:user, :system, :common, :dynamic]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Keychain

Returns a new instance of Keychain.


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

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename


7
8
9
# File 'lib/security/keychain.rb', line 7

def filename
  @filename
end

Class Method Details

.create(filename, password) ⇒ Object

Raises:

  • (NotImplementedError)

30
31
32
# File 'lib/security/keychain.rb', line 30

def create(filename, password)
  raise NotImplementedError
end

.default_keychainObject


48
49
50
# File 'lib/security/keychain.rb', line 48

def default_keychain
  keychains_from_output(`security default-keychain`).first
end

.list(domain = :user) ⇒ Object


34
35
36
37
38
# File 'lib/security/keychain.rb', line 34

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

.lockObject


40
41
42
# File 'lib/security/keychain.rb', line 40

def lock
  system %{security lock-keychain -a}
end

.login_keychainObject


52
53
54
# File 'lib/security/keychain.rb', line 52

def 
  keychains_from_output(`security login-keychain`).first
end

.unlock(password) ⇒ Object


44
45
46
# File 'lib/security/keychain.rb', line 44

def unlock(password)
  system %{security unlock-keychain -p #{password.shellescape}}
end

Instance Method Details

#deleteObject


25
26
27
# File 'lib/security/keychain.rb', line 25

def delete
  system %{security delete-keychain #{@filename.shellescape}}
end

#infoObject


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

def info
  system %{security show-keychain-info #{@filename.shellescape}}
end

#lockObject


17
18
19
# File 'lib/security/keychain.rb', line 17

def lock
  system %{security lock-keychain #{@filename.shellescape}}
end

#unlock(password) ⇒ Object


21
22
23
# File 'lib/security/keychain.rb', line 21

def unlock(password)
  system %{security unlock-keychain -p #{password.shellescape} #{@filename.shellescape}}
end