Class: Hiera::Backend::Osxkeychain_backend

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

Defined Under Namespace

Classes: Keychain

Instance Method Summary collapse

Constructor Details

#initializeOsxkeychain_backend

Returns a new instance of Osxkeychain_backend.



93
94
95
96
# File 'lib/hiera/backend/osxkeychain_backend.rb', line 93

def initialize
  @config = Config[:osxkeychain]
  Hiera.debug("osxkeychain_backend initialized config: #{@config}")
end

Instance Method Details

#lookup(key, scope, order_override, resolution_type, *args) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/hiera/backend/osxkeychain_backend.rb', line 98

def lookup(key, scope, order_override, resolution_type, *args)
  # Ignore order_override since it doesn't not have hierarchy.
  # Ignore scope since no need to interpolate values in anyways.

  # Use key for account to lookup generic password.
  result = keychain.lookup(:account => key)

  # Hiera 2 and later, which has 5th argument, require to throw `:no_such_key`
  # when no key found, but Hiera 1 requires to return `nil`.
  if !result && !args.empty?
    throw(:no_such_key)
  end

  case resolution_type
  when :array
    if result
      [result]
    else
      []
    end
  when :hash
    Hiera.warn("Unexpected resolution type.")
    result
  else
    result
  end
end