From 9421451a542e7f71b4d740119daae62069059b41 Mon Sep 17 00:00:00 2001 From: Dimonyga Date: Tue, 6 Nov 2018 09:28:07 +0000 Subject: [PATCH 1/2] add key_re options --- lib/puppet/functions/hiera_http.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/puppet/functions/hiera_http.rb b/lib/puppet/functions/hiera_http.rb index fab4bf2..12795bb 100644 --- a/lib/puppet/functions/hiera_http.rb +++ b/lib/puppet/functions/hiera_http.rb @@ -53,11 +53,12 @@ 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 @@ -65,17 +66,25 @@ def return_answer(result, key, options) 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 @@ -147,6 +156,9 @@ def lookup_supported_params :use_auth, :auth_user, :auth_pass, + :dig, + :dig_key, + :key_re ] end end From f9bbfdfcae83851a33797a96282f74dafd15e43b Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Tue, 20 Nov 2018 14:40:18 +0300 Subject: [PATCH 2/2] fix uri --- lib/puppet/functions/hiera_http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/functions/hiera_http.rb b/lib/puppet/functions/hiera_http.rb index 12795bb..8e8c506 100644 --- a/lib/puppet/functions/hiera_http.rb +++ b/lib/puppet/functions/hiera_http.rb @@ -110,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)