Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/puppet/functions/hiera_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,38 @@ def return_answer(result, key, options)
#
dig_path = dig_key.split(/\./).map { |p| parse_tags(key, p) }

key_re = options.has_key?('key_re') ? options['key_re'] : ''

if result.nil?
return :not_found
elsif result.is_a?(Hash)
return dig ? hash_dig(result, dig_path) : result
return dig ? hash_dig(result, dig_path, key_re) : result
else
return result
end

end


def hash_dig(data, dig_path)
def hash_dig(data, dig_path, key_re)
key = dig_path.shift
reg = Regexp.new key_re
if dig_path.empty?
if data.has_key?(key)
return data[key]
elsif data.keys.any? { |k| k.to_s.match(key_re)}
data.each { |ka,v|
if ka.sub(reg,'').eql? key
return v
end
}
return :not_found
else
return :not_found
end
else
return :not_found unless data[key].is_a?(Hash)
return hash_dig(data[key], dig_path)
return hash_dig(data[key], dig_path,key_re)
end
end

Expand All @@ -101,7 +110,7 @@ def parse_tags(key,str)


def http_get(context, options)
uri = URI.parse(options['uri'])
uri = URI.parse(URI.escape(options['uri']))
host, port, path = uri.host, uri.port, URI.escape(context.interpolate(uri.request_uri))

if context.cache_has_key(path)
Expand Down Expand Up @@ -147,6 +156,9 @@ def lookup_supported_params
:use_auth,
:auth_user,
:auth_pass,
:dig,
:dig_key,
:key_re
]
end
end
Expand Down