Class: Hiera::Backend::Osxkeychain_backend::Keychain

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/osxkeychain_backend.rb

Constant Summary collapse

SECURITY_PATH =
"/usr/bin/security"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#serviceObject (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(options = {})
  # See security(1) for these arguments.
  args = ["-w"]

  if service
    args += ["-s", service]
  end

   = options[:account]
  if 
    args += ["-a", ]
  end

  label = options[: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 #{options}: #{error.chomp}")
    nil
  end
end