Class: Omnivault::AppleKeychain
- Inherits:
-
AbstractVault
- Object
- AbstractVault
- Omnivault::AppleKeychain
- Defined in:
- lib/omnivault/apple_keychain.rb
Instance Attribute Summary collapse
-
#keychain ⇒ Object
Returns the value of attribute keychain.
Instance Method Summary collapse
- #entries ⇒ Object
-
#initialize(name = 'default') ⇒ AppleKeychain
constructor
A new instance of AppleKeychain.
- #remove(key) ⇒ Object
- #store(key, value) ⇒ Object
Methods inherited from AbstractVault
#configure_aws!, #fetch, for_platform, from_env
Constructor Details
#initialize(name = 'default') ⇒ AppleKeychain
Returns a new instance of AppleKeychain.
5 6 7 8 9 10 11 |
# File 'lib/omnivault/apple_keychain.rb', line 5 def initialize(name = 'default') # Need to require within initializer, to avoid LoadError on # non-Apple platforms require 'keychain' @keychain = open_or_create_keychain(name) end |
Instance Attribute Details
#keychain ⇒ Object
Returns the value of attribute keychain.
3 4 5 |
# File 'lib/omnivault/apple_keychain.rb', line 3 def keychain @keychain end |
Instance Method Details
#entries ⇒ Object
13 14 15 16 17 |
# File 'lib/omnivault/apple_keychain.rb', line 13 def entries Hash[keychain.generic_passwords.all.map do |item| [item.label, item.password] end] end |
#remove(key) ⇒ Object
32 33 34 35 |
# File 'lib/omnivault/apple_keychain.rb', line 32 def remove(key) entry = keychain.generic_passwords.where(label: key).all.first entry.delete end |
#store(key, value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/omnivault/apple_keychain.rb', line 19 def store(key, value) if (entry = keychain.generic_passwords.where(label: key).all.first) entry.password = value entry.save! else keychain.generic_passwords.create( service: key, label: key, password: value ) end end |