Class: Hiera::Backend::Osxkeychain_backend::Keychain
- Inherits:
-
Object
- Object
- Hiera::Backend::Osxkeychain_backend::Keychain
- Defined in:
- lib/hiera/backend/osxkeychain_backend.rb
Constant Summary collapse
- SECURITY_PATH =
"/usr/bin/security"
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service = nil) ⇒ Keychain
constructor
A new instance of Keychain.
- #lookup(options = {}) ⇒ Object
Constructor Details
#initialize(service = nil) ⇒ Keychain
Returns a new instance of Keychain.
9 10 11 |
# File 'lib/hiera/backend/osxkeychain_backend.rb', line 9 def initialize(service = nil) @service = service end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
7 8 9 |
# File 'lib/hiera/backend/osxkeychain_backend.rb', line 7 def service @service end |
Instance Method Details
#lookup(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hiera/backend/osxkeychain_backend.rb', line 13 def lookup( = {}) # See security(1) for these arguments. args = ["-w"] if service args += ["-s", service] end account = [:account] if account args += ["-a", account] end label = [:label] if label args += ["-l", label] end command = [SECURITY_PATH, "find-generic-password"] + args status, out, error = run(*command) if status.success? out.chomp else Hiera.warn("Fail to lookup #{}: #{error.chomp}") nil end end |