From 8cbad72c7808123e36391550dfb8a9cea69d0569 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Thu, 25 Jul 2013 12:55:27 -0400 Subject: [PATCH 01/28] Add path_base config, ensure all paths go through parse_string --- lib/hiera/backend/http_backend.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 4c79473..5faa47c 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -10,6 +10,7 @@ def initialize @http = Net::HTTP.new(@config[:host], @config[:port]) @http.read_timeout = @config[:http_read_timeout] || 10 @http.open_timeout = @config[:http_connect_timeout] || 10 + @path_base = @config[:path_base] || '' if @config[:use_ssl] @http.use_ssl = true @@ -31,9 +32,9 @@ def lookup(key, scope, order_override, resolution_type) answer = nil - paths = @config[:paths].map { |p| Backend.parse_string(p, scope, { 'key' => key }) } + paths = @config[:paths].clone paths.insert(0, order_override) if order_override - + paths.map! { |p| Backend.parse_string(@path_base + p, scope, { 'key' => key }) } paths.each do |path| From 8a0a64da6e9819ae6ec623a30df4b4e74192aa1e Mon Sep 17 00:00:00 2001 From: floomby Date: Tue, 1 Apr 2014 13:49:27 -0600 Subject: [PATCH 02/28] update Rakefile --- Rakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 3bc84c1..d21cdca 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ require 'rubygems' -require 'rake/gempackagetask' +require 'rubygems/package_task' spec = Gem::Specification.new do |gem| gem.name = "hiera-http" @@ -14,7 +14,7 @@ spec = Gem::Specification.new do |gem| gem.add_dependency('json', '>=1.1.1') end -Rake::GemPackageTask.new(spec) do |pkg| +Gem::PackageTask.new(spec) do |pkg| pkg.need_tar = true + pkg.gem_spec = spec end - From 567ed7d94e8db10cffa4b86be91c02c9b427bac2 Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Thu, 24 Apr 2014 14:47:09 +0100 Subject: [PATCH 03/28] * Added ignore_404 option Gives the ability to disable failure: graceful in order to bomb out on errors, but still ignore 404's which might be an expected result of a hiera lookup that should pass through to the next level in the hierarchy and may not actually be an error --- lib/hiera/backend/http_backend.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 5faa47c..077af5a 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -52,7 +52,9 @@ def lookup(key, scope, order_override, resolution_type) unless httpres.kind_of?(Net::HTTPSuccess) Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}") Hiera.debug("HTTP response code was #{httpres.code}") - raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' + unless ( httpres.code == '404' && @config[:ignore_404] == true ) + raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' + end next end From 6b7d93c4dcb3d0c078b5141b4f0ff34fc474738d Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Thu, 24 Apr 2014 14:50:45 +0100 Subject: [PATCH 04/28] added ignore_404 to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0a494d1..098c31b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ The following are optional configuration parameters `:failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances +`:ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors. + The `:paths:` parameter can also parse the lookup key, eg: :paths: From 3cd2ef57ae7c8dafce909ab696aa722aaf00b33c Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Thu, 24 Apr 2014 15:04:16 +0100 Subject: [PATCH 05/28] prepared 1.0.0 forge release --- Modulefile | 10 ++ Rakefile | 2 +- pkg/crayfishx-hiera_http-1.0.0.tar.gz | Bin 0 -> 3136 bytes pkg/crayfishx-hiera_http-1.0.0/Modulefile | 10 ++ pkg/crayfishx-hiera_http-1.0.0/README.md | 82 ++++++++++++ pkg/crayfishx-hiera_http-1.0.0/Rakefile | 20 +++ .../lib/hiera/backend/http_backend.rb | 126 ++++++++++++++++++ pkg/crayfishx-hiera_http-1.0.0/metadata.json | 22 +++ pkg/hiera-http-1.0.0.gem | Bin 0 -> 4608 bytes 9 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 Modulefile create mode 100644 pkg/crayfishx-hiera_http-1.0.0.tar.gz create mode 100644 pkg/crayfishx-hiera_http-1.0.0/Modulefile create mode 100644 pkg/crayfishx-hiera_http-1.0.0/README.md create mode 100644 pkg/crayfishx-hiera_http-1.0.0/Rakefile create mode 100644 pkg/crayfishx-hiera_http-1.0.0/lib/hiera/backend/http_backend.rb create mode 100644 pkg/crayfishx-hiera_http-1.0.0/metadata.json create mode 100644 pkg/hiera-http-1.0.0.gem diff --git a/Modulefile b/Modulefile new file mode 100644 index 0000000..4206d82 --- /dev/null +++ b/Modulefile @@ -0,0 +1,10 @@ +name 'crayfishx-hiera_http' +version '1.0.0' +source 'http://github.com/crayfishx/hiera-http' +author 'Craig Dunn' +license 'Apache License, Version 2.0' +summary 'HTTP/REST API back end for Hiera' +description 'Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.' +project_page 'http://github.com/crayfishx/hiera-http' + + diff --git a/Rakefile b/Rakefile index d21cdca..12033a9 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rubygems/package_task' spec = Gem::Specification.new do |gem| gem.name = "hiera-http" - gem.version = "0.1.0" + gem.version = "1.0.0" gem.summary = "HTTP backend for Hiera" gem.email = "craig@craigdunn.org" gem.author = "Craig Dunn" diff --git a/pkg/crayfishx-hiera_http-1.0.0.tar.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QEWrQ^R)F7evJtvWE-J*Nq6LMdmQtZ>+Q__N*daO@*AdU)LPhRbGE>g-@B{;i znInofHu(ip3;0w^W_oFo<@3XiP~l(}{H&vwYI#eyD;@BRMfhH)i1uZ&^v|`(_^jn81_sv zUD$+e0PO|RiJkP~UjOT2sm+Q*^ir5#w>8j7@Zs%YGg%Gyp|DedgL7}fIbnl7om5fcm1*6>|337$Shxd|> zxJ@ZbI-Cif;da_RWiS*>I;BR;`@1w^^{Hr1U2PO9sGx!hDyX1>3M#0ef(k0Apn?i2 asGx!hDyX1>3M#1Jp5ec +* @crayfishX +* IRC (freenode) crayfishx +* http://www.craigdunn.org + +### Credits + +* SSL components contributed from Ben Ford + + +### Change Log + +#### 0.1.0 +* Stable +* Puppet Forge release + +#### 0.0.2 +* Added SSL support + +#### 0.0.1 +* Initial release + + diff --git a/pkg/crayfishx-hiera_http-1.0.0/Rakefile b/pkg/crayfishx-hiera_http-1.0.0/Rakefile new file mode 100644 index 0000000..12033a9 --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.0.0/Rakefile @@ -0,0 +1,20 @@ +require 'rubygems' +require 'rubygems/package_task' + +spec = Gem::Specification.new do |gem| + gem.name = "hiera-http" + gem.version = "1.0.0" + gem.summary = "HTTP backend for Hiera" + gem.email = "craig@craigdunn.org" + gem.author = "Craig Dunn" + gem.homepage = "http://github.com/crayfishx/hiera-http" + gem.description = "Hiera backend for looking up data over HTTP APIs" + gem.require_path = "lib" + gem.files = FileList["lib/**/*"].to_a + gem.add_dependency('json', '>=1.1.1') +end + +Gem::PackageTask.new(spec) do |pkg| + pkg.need_tar = true + pkg.gem_spec = spec +end diff --git a/pkg/crayfishx-hiera_http-1.0.0/lib/hiera/backend/http_backend.rb b/pkg/crayfishx-hiera_http-1.0.0/lib/hiera/backend/http_backend.rb new file mode 100644 index 0000000..4c79473 --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.0.0/lib/hiera/backend/http_backend.rb @@ -0,0 +1,126 @@ +class Hiera + module Backend + class Http_backend + + def initialize + require 'net/http' + require 'net/https' + @config = Config[:http] + + @http = Net::HTTP.new(@config[:host], @config[:port]) + @http.read_timeout = @config[:http_read_timeout] || 10 + @http.open_timeout = @config[:http_connect_timeout] || 10 + + if @config[:use_ssl] + @http.use_ssl = true + if @config[:ssl_cert] + @http.verify_mode = OpenSSL::SSL::VERIFY_PEER + store = OpenSSL::X509::Store.new + store.add_cert(OpenSSL::X509::Certificate.new(File.read(@config[:ssl_ca_cert]))) + @http.cert_store = store + + @http.key = OpenSSL::PKey::RSA.new(File.read(@config[:ssl_cert])) + @http.cert = OpenSSL::X509::Certificate.new(File.read(@config[:ssl_key])) + end + else + @http.use_ssl = false + end + end + + def lookup(key, scope, order_override, resolution_type) + + answer = nil + + paths = @config[:paths].map { |p| Backend.parse_string(p, scope, { 'key' => key }) } + paths.insert(0, order_override) if order_override + + + paths.each do |path| + + Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") + httpreq = Net::HTTP::Get.new(path) + + begin + httpres = @http.request(httpreq) + rescue Exception => e + Hiera.warn("[hiera-http]: Net::HTTP threw exception #{e.message}") + raise Exception, e.message unless @config[:failure] == 'graceful' + next + end + + unless httpres.kind_of?(Net::HTTPSuccess) + Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}") + Hiera.debug("HTTP response code was #{httpres.code}") + raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' + next + end + + result = self.parse_response(key, httpres.body) + next unless result + + parsed_result = Backend.parse_answer(result, scope) + + case resolution_type + when :array + answer ||= [] + answer << parsed_result + when :hash + answer ||= {} + answer = parsed_result.merge answer + else + answer = parsed_result + break + end + end + answer + end + + + def parse_response(key,answer) + + return nil unless answer + + Hiera.debug("[hiera-http]: Query returned data, parsing response as #{@config[:output] || 'plain'}") + + case @config[:output] + + when 'plain' + # When the output format is configured as plain we assume that if the + # endpoint URL returns an HTTP success then the contents of the response + # body is the value itself, or nil. + # + answer + when 'json' + # If JSON is specified as the output format, assume the output of the + # endpoint URL is a JSON document and return keypart that matched our + # lookup key + self.json_handler(key,answer) + when 'yaml' + # If YAML is specified as the output format, assume the output of the + # endpoint URL is a YAML document and return keypart that matched our + # lookup key + self.yaml_handler(key,answer) + else + answer + end + end + + # Handlers + # Here we define specific handlers to parse the output of the http request + # and return a value. Currently we support YAML and JSON + # + def json_handler(key,answer) + require 'rubygems' + require 'json' + JSON.parse(answer)[key] + end + + def yaml_handler(answer) + require 'yaml' + YAML.parse(answer)[key] + end + + end + end +end + diff --git a/pkg/crayfishx-hiera_http-1.0.0/metadata.json b/pkg/crayfishx-hiera_http-1.0.0/metadata.json new file mode 100644 index 0000000..80e8d33 --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.0.0/metadata.json @@ -0,0 +1,22 @@ +{ + "name": "crayfishx-hiera_http", + "version": "1.0.0", + "source": "http://github.com/crayfishx/hiera-http", + "author": "Craig Dunn", + "license": "Apache License, Version 2.0", + "summary": "HTTP/REST API back end for Hiera", + "description": "Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.", + "project_page": "http://github.com/crayfishx/hiera-http", + "dependencies": [ + + ], + "types": [ + + ], + "checksums": { + "Modulefile": "5cf306983a57ea99f9c54a9564a82c39", + "README.md": "013ba51adbb24bccb770f6ade54f6072", + "Rakefile": "da6f9edc81d86a8f3955612016244aa0", + "lib/hiera/backend/http_backend.rb": "101eb5cabd578a440cc36be5bbf8e949" + } +} \ No newline at end of file diff --git a/pkg/hiera-http-1.0.0.gem b/pkg/hiera-http-1.0.0.gem new file mode 100644 index 0000000000000000000000000000000000000000..c82ddc98a95a5b851b3c2f2fed8032136595f0cb GIT binary patch literal 4608 zcmeHJXH*l&7LE{#!lKdyf`T+biV||@WkYil5ye0#Q6wQqM+hKAT5utP(xi8B0kKd5 zgeDy!bSX+Gt}bySHHI3HAUu5Uyj_of_UxXsXZHv9&z+e&cjn%2=G^aM(SB$ZKQvCo zIT-MF$=N+ohd=;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5|>oEHlv3i{fUAUMp-K;ZVq?_)k8%aw;Rb z0~13BTU2Xijxf=fwNm0qb$kM{gwxBkw4;)^>1dgzj!7LMRf^B{$k<)$MauVXF69#K z0wb@`I<yY284f+0IFRbi<`>6%hwnb&5p@^8L@6n1cV+Y;-ib@Hyvt(B z&pEG2*knBY&dfXT@x1PtydSn`KOV9@h8Do%Yk)|`+cK(*S-usvL0C+j8r#yG?`mXV z$7JCLU(idM=9dfY>z}P!=}Hi13$1P^D0tmYf54ABUwr_^o2!Z{0*P=*rUFIaoV6Pp z0ZY>#s~pF9Ui&0M*Ef8g!M0wFN9R`Kl6&h`ON>rFsuwCMjZ@N?zms(hHfU~T3kgs^ zmco&ozA8f!a*w*ZEZ%rLiBwF6LJCfCcUL{LXgw2n1r2H%{H zvud^z9(Q2uyq9wJz-EJ!1whoPtPF{9+QHa0?a+=KH%L9{4K?r5$8E+6u<5$j;w|(+ v{ Date: Thu, 24 Apr 2014 15:08:09 +0100 Subject: [PATCH 06/28] 1.0.1 --- Modulefile | 2 +- Rakefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modulefile b/Modulefile index 4206d82..a0cac28 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'crayfishx-hiera_http' -version '1.0.0' +version '1.0.1' source 'http://github.com/crayfishx/hiera-http' author 'Craig Dunn' license 'Apache License, Version 2.0' diff --git a/Rakefile b/Rakefile index 12033a9..408d93e 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rubygems/package_task' spec = Gem::Specification.new do |gem| gem.name = "hiera-http" - gem.version = "1.0.0" + gem.version = "1.0.1" gem.summary = "HTTP backend for Hiera" gem.email = "craig@craigdunn.org" gem.author = "Craig Dunn" From c393460324d0e17f47c4975daead191f70a99f57 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Wed, 21 May 2014 16:41:45 -0400 Subject: [PATCH 07/28] Fix spelling typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 098c31b..5aca14b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The following are optional configuration parameters The `:paths:` parameter can also parse the lookup key, eg: :paths: - /configuraiton.php?lookup=%{key} + /configuration.php?lookup=%{key} `:use_ssl:`: When set to true, enable SSL (default: false) From 0dc187f26a4f272682810742e7a696dcb9ed53a6 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 24 Jun 2014 11:30:09 -0600 Subject: [PATCH 08/28] Add basic auth support --- README.md | 6 ++++++ lib/hiera/backend/http_backend.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 5aca14b..eb71644 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ The `:paths:` parameter can also parse the lookup key, eg: `:ssl_key`: Specify location of SSL key +`:use_auth:`: When set to true, enable basic auth (default: false) + +`:auth_user:`: The user for basic auth + +`:auth_pass:`: The password for basic auth + ### TODO Theres a few things still on my list that I'm going to be adding, including diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 077af5a..9455b20 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -41,6 +41,10 @@ def lookup(key, scope, order_override, resolution_type) Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") httpreq = Net::HTTP::Get.new(path) + if @config[:use_auth] + httpreq.basic_auth @config[:auth_user], @config[:auth_pass] + end + begin httpres = @http.request(httpreq) rescue Exception => e From 80535f5f538d3774adb714a5bc334ca4f8a7b0a4 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 24 Jun 2014 16:03:23 -0600 Subject: [PATCH 09/28] Add SSL verification option --- README.md | 1 + lib/hiera/backend/http_backend.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb71644..647971b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ The `:paths:` parameter can also parse the lookup key, eg: `:ssl_key`: Specify location of SSL key +`:ssl_verify`: Specify whether to verify SSL certificates (default: true) `:use_auth:`: When set to true, enable basic auth (default: false) `:auth_user:`: The user for basic auth diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 9455b20..fb6c99f 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -14,8 +14,14 @@ def initialize if @config[:use_ssl] @http.use_ssl = true - if @config[:ssl_cert] + + if @config[:ssl_verify] == false + @http.verify_mode = OpenSSL::SSL::VERIFY_NONE + else @http.verify_mode = OpenSSL::SSL::VERIFY_PEER + end + + if @config[:ssl_cert] store = OpenSSL::X509::Store.new store.add_cert(OpenSSL::X509::Certificate.new(File.read(@config[:ssl_ca_cert]))) @http.cert_store = store From 32ac3ecb1c38c40a8e7d59cc56e4292b57202cd2 Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 9 Jul 2014 14:51:14 +0100 Subject: [PATCH 10/28] prepared 1.2.0 --- Modulefile | 2 +- README.md | 14 ++++++++++++-- Rakefile | 2 +- pkg/hiera-http-1.2.0.gem | Bin 0 -> 4608 bytes 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 pkg/hiera-http-1.2.0.gem diff --git a/Modulefile b/Modulefile index a0cac28..4813ce7 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'crayfishx-hiera_http' -version '1.0.1' +version '1.2.0' source 'http://github.com/crayfishx/hiera-http' author 'Craig Dunn' license 'Apache License, Version 2.0' diff --git a/README.md b/README.md index 647971b..d43f603 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,23 @@ Theres a few things still on my list that I'm going to be adding, including * IRC (freenode) crayfishx * http://www.craigdunn.org -### Credits +### Contributors * SSL components contributed from Ben Ford - +* Louis Jencka ### Change Log +#### 1.2.0 + +* Support for SSL verify options +* Support for HTTP auth + +#### 1.0.1 + +* 1.0 release +* Support for ignoring 404's when failure is not set to graceful + #### 0.1.0 * Stable * Puppet Forge release diff --git a/Rakefile b/Rakefile index 408d93e..b55991e 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rubygems/package_task' spec = Gem::Specification.new do |gem| gem.name = "hiera-http" - gem.version = "1.0.1" + gem.version = "1.2.0" gem.summary = "HTTP backend for Hiera" gem.email = "craig@craigdunn.org" gem.author = "Craig Dunn" diff --git a/pkg/hiera-http-1.2.0.gem b/pkg/hiera-http-1.2.0.gem new file mode 100644 index 0000000000000000000000000000000000000000..25cc5d258aec3a3c31babd727cb381ed183d4524 GIT binary patch literal 4608 zcmeHJS5y;P7L5>*DoPB!DuRF_gkCKuT|^-eKzc$Cp(Z@?Ktq=%5FCnh69`362q+~q z1*C{b6H!25=)nM?gE+n^Yh2F9e9U_9%?JDE+viG&n26B0$rKmIVxz2My4FS{Uo z-GP@JP+9vr#qf3@W#rplB0-qoC3(HxiI+R{DRFv?Hm*0ylKUyw_Z0OYA~G#qcgxjq zW_s=H3A~1VBNJIzSU3}9{e%|Y((+gj{HC8%SV;R#S9*m&{9<@rLA zv3wu~)#*ZumNRnJjyx0OA}kw~={V@lyRL!EE#NE^{Y22MxtncYqX*yC5{<|JR{?`$t`Q-|o7>4En} z9f{(h%6*TfrxkceQg~#0w0`I6DT9YBocj-sg`*52C6=zCAji(fvYS?%rN_Hz&Wf4o zR&HfUx8;C}x)|gK>4sGHJevR} z5dCmrsYFe8lA4*qLQRTTe3)AIB&)?vN#^w{y%9B*EIB6FUy#kd`sG8 zAuIQaZu4~JA-(J^i8mL?>}*Mq3Na8!gq@}L(e(R#*HonnDfK+Fz_0D>Wnx+BaxLRv zK5`Tc?jO84HyAu`+C#9W*}4lY)qArliM}z$%yUFvG|f=&qkgr$QRv^zsziTOrpqp2 zyw>NV2-!s%hqVelj!GXmDK|Pc2Fh9^R~5I5*JRbx*iuU@OE4kgHBT?A9`HJqFX_7W z=U!1BWRvJe6P8H#GFk2bhDEWKygj!Jm9JkS5R!Zs=08Sff?^f(i`sY6R|zNFqP#HD zuo&Ou04?&VOC@8;Qb)RdfN7cu?N<9C70UY!%sNx^DBmDY0*f`Im0$&aqr;5gDEc$tt zk6mxvtDJ}TV}ivv5|gywIHQ*=;WRFnq|#Us!a_}&DpPpZOwy%oO`WD;06sk zpy_pN9cbSNh^x^PGv(pEzig&v05x1c{3XjeRPr+eRP1($1C;NAm}jD=`bHW|5>R3mC`W7C7DeI<1LIUd z{)P99p27yzlWShZv|hD28>f~MGaFk?iq?D9qmU!Ly+I|cn?|>zi^-rHY*s{qj$?^9 zoT+$oEPN12;OJ);fn5#9$&6ul`-WMV?|9GELQR!{ce~2KI7|8cpo3j=&m^^|fb2?P z6cEw0N*V9;jsf5xY$6D;POc2%EvS~cRcat2+`FgFSJb_L=S5CM?#*Up zVW+MZXPkccLFyS_`XaM(S|)$reL&T9L4c-AMBa+H(Gx@NTJ3n`Ulr@iGY!Z2OjIN& z2VxguJN;t)YiCqyCXQO;wOoSFjzk``J^flhLpT(9H_ei7=H@lK=-uV-Z~D5`v0P{S zd5dGEaS8NOp}_-eyUFg!y7PhtXC%?% z@f|dZdy4qVtHdE~g&{4&x0jsW?xYt&_>)oK#6`J^O9OeEXuC z%>br2ZjDokVJZdw`ku!h30Gq@0bJ*%UL-o3Ow0Qwmk(rdWUmM~V~;zENa#-R3pjzc z9U?tG2M?;B7l^y0i*P?JZ48 zJE{ds5RgYVz7pzs7gxf@=P79Voen#XY2JG4LHbep5W1|VZw+V&8u Date: Wed, 9 Jul 2014 15:10:44 +0100 Subject: [PATCH 11/28] migrated to metadata.json --- Modulefile | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 Modulefile diff --git a/Modulefile b/Modulefile deleted file mode 100644 index 4813ce7..0000000 --- a/Modulefile +++ /dev/null @@ -1,10 +0,0 @@ -name 'crayfishx-hiera_http' -version '1.2.0' -source 'http://github.com/crayfishx/hiera-http' -author 'Craig Dunn' -license 'Apache License, Version 2.0' -summary 'HTTP/REST API back end for Hiera' -description 'Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.' -project_page 'http://github.com/crayfishx/hiera-http' - - From be1f68bfddb213cfa2416f7bf886c26a5649249b Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 9 Jul 2014 15:11:07 +0100 Subject: [PATCH 12/28] Forge release 1.2.0 --- pkg/crayfishx-hiera_http-1.2.0.tar.gz | Bin 0 -> 3459 bytes pkg/crayfishx-hiera_http-1.2.0/README.md | 102 +++++++++++++ pkg/crayfishx-hiera_http-1.2.0/Rakefile | 20 +++ pkg/crayfishx-hiera_http-1.2.0/checksums.json | 6 + .../lib/hiera/backend/http_backend.rb | 138 ++++++++++++++++++ pkg/crayfishx-hiera_http-1.2.0/metadata.json | 13 ++ 6 files changed, 279 insertions(+) create mode 100644 pkg/crayfishx-hiera_http-1.2.0.tar.gz create mode 100644 pkg/crayfishx-hiera_http-1.2.0/README.md create mode 100644 pkg/crayfishx-hiera_http-1.2.0/Rakefile create mode 100644 pkg/crayfishx-hiera_http-1.2.0/checksums.json create mode 100644 pkg/crayfishx-hiera_http-1.2.0/lib/hiera/backend/http_backend.rb create mode 100644 pkg/crayfishx-hiera_http-1.2.0/metadata.json diff --git a/pkg/crayfishx-hiera_http-1.2.0.tar.gz b/pkg/crayfishx-hiera_http-1.2.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..5adc2c100ed101b74ae449ec29442fb21ca12aff GIT binary patch literal 3459 zcmV-}4Sez+iwFR0O}$e91MOOSbK5o&@89|q7<*bt8Hd(eu_jLAIBuJso8)ZYwH=Q} z21!t2Opz=>M$y^+?zg)DU$U$?kGl6Dl8H!Scd;-0fCXYjeCfDy_Tll&6%n7z;y8TV zHabRY_nWWPTCLWw-)HnYP`|BCPyOn~+MRBH*y#=W{T^$z2klnx8`l478f<8ZjClmA zSP^%p8|Z+{aW?d8JF?&Zl4ji*VO*iYQaG+Bh~r7yeA4Bu9z<=pXZH8nomO9n?x44~*L%|HD-O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*IS2CvO6liMUMKmYrZ{8|~Re6UETj|(nAc&a~sT9u$pY_K8`ISi|2_T6{6 zJM&{v@+huwthth)x1v*j!B-A&>z@;+A{u@?ZZH&{WCQXG&(YA64zKVpwbl&mWzhyY zzSR0DDMh&?$)055%iyLUvY~o4!j)#Y1$F-_#1^{gfMUcW*wUA5)zEu=z0c0a>w2C( zEo*j5=8VhPT_Ue;*7fX{CBhWLlMmIoX~VIey+mTd;&*x1LRWY$4MqVjtYvFrs^|+2 z*Oxi4V5Je&A~T8&GxhIu3#mj1n@-7hXjD8<%I_j%aqg-MCfYgH>4K?_vn?Bq!oNzK zcT=b|U%@@w>cF*d+2sV$oYT!}dY%mmf+obu7O0g>=0cr!x^#M9k_WyF1J{q)KTeLd zg>=D5vs5ZXQ+F9SC>{~gSz&g^rfe^X#A!rVy+H7udjJe>jB}5!%^(0qk-G4_l2FP8 z^#5H-;$J!H$_+-4>OU+gi*Gq)C%1j&Zt!jo&;>Y&PcQrEhC^o$WES0mkTYQfYeqMT zQAu8Y_fYsu*n_rA^nq|GOUowXZSpOX>ALaHGnvHy2_~a08%ycBre?}!%+HQw|ozr@)yAAqd{Nu zzxHl*m1hBtq?Vb67Iuym!}^VWDFSznUCueQ=^g{9=-|Kf>90Qis9M#kR<){Ct!h=P lTGgsnwW?LEYE`RR)v8vts#UFORr{Z7{|4&ik@)~n002MJ#iIZK literal 0 HcmV?d00001 diff --git a/pkg/crayfishx-hiera_http-1.2.0/README.md b/pkg/crayfishx-hiera_http-1.2.0/README.md new file mode 100644 index 0000000..d2a7ae3 --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.2.0/README.md @@ -0,0 +1,102 @@ +## hiera_http : a HTTP back end for Hiera + + +### Description + +This is a back end plugin for Hiera that allows lookup to be sourced from HTTP queries. The intent is to make this backend adaptable to allow you to query any data stored in systems with a RESTful API such as CouchDB or even a custom store with a web front-end + +### Configuration + +The following is an example hiera.yaml configuration for use with hiera-http + + :backends: + - http + + :http: + :host: 127.0.0.1 + :port: 5984 + :output: json + :failure: graceful + :paths: + - /configuration/%{fqdn} + - /configuration/%{env} + - /configuration/common + + +The following are optional configuration parameters + +`:output: ` : Specify what handler to use for the output of the request. Currently supported outputs are plain, which will just return the whole document, or YAML and JSON which parse the data and try to look up the key + +`:http_connect_timeout: ` : Timeout in seconds for the HTTP connect (default 10) + +`:http_read_timeout: ` : Timeout in seconds for waiting for a HTTP response (default 10) + +`:failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances + +`:ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors. + +The `:paths:` parameter can also parse the lookup key, eg: + + :paths: + /configuration.php?lookup=%{key} + +`:use_ssl:`: When set to true, enable SSL (default: false) + +`:ssl_ca_cert`: Specify a CA cert for use with SSL + +`:ssl_cert`: Specify location of SSL certificate + +`:ssl_key`: Specify location of SSL key + +`:ssl_verify`: Specify whether to verify SSL certificates (default: true) + +`:use_auth:`: When set to true, enable basic auth (default: false) + +`:auth_user:`: The user for basic auth + +`:auth_pass:`: The password for basic auth + +### TODO + +Theres a few things still on my list that I'm going to be adding, including + +* Add HTTP basic auth support +* Add proxy support +* Add further handlers (eg: XML) + + +### Author + +* Craig Dunn +* @crayfishX +* IRC (freenode) crayfishx +* http://www.craigdunn.org + +### Contributors + +* SSL components contributed from Ben Ford +* Louis Jencka + +### Change Log + +#### 1.2.0 + +* Support for SSL verify options +* Support for HTTP auth + +#### 1.0.1 + +* 1.0 release +* Support for ignoring 404's when failure is not set to graceful + +#### 0.1.0 +* Stable +* Puppet Forge release + +#### 0.0.2 +* Added SSL support + +#### 0.0.1 +* Initial release + + diff --git a/pkg/crayfishx-hiera_http-1.2.0/Rakefile b/pkg/crayfishx-hiera_http-1.2.0/Rakefile new file mode 100644 index 0000000..b55991e --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.2.0/Rakefile @@ -0,0 +1,20 @@ +require 'rubygems' +require 'rubygems/package_task' + +spec = Gem::Specification.new do |gem| + gem.name = "hiera-http" + gem.version = "1.2.0" + gem.summary = "HTTP backend for Hiera" + gem.email = "craig@craigdunn.org" + gem.author = "Craig Dunn" + gem.homepage = "http://github.com/crayfishx/hiera-http" + gem.description = "Hiera backend for looking up data over HTTP APIs" + gem.require_path = "lib" + gem.files = FileList["lib/**/*"].to_a + gem.add_dependency('json', '>=1.1.1') +end + +Gem::PackageTask.new(spec) do |pkg| + pkg.need_tar = true + pkg.gem_spec = spec +end diff --git a/pkg/crayfishx-hiera_http-1.2.0/checksums.json b/pkg/crayfishx-hiera_http-1.2.0/checksums.json new file mode 100644 index 0000000..fc37c0d --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.2.0/checksums.json @@ -0,0 +1,6 @@ +{ + "README.md": "f056722b33745154fd6e5d26f7a72c62", + "Rakefile": "f81b83a0476379b591205ee364994805", + "lib/hiera/backend/http_backend.rb": "fcb2bbba21f94db829969aa1ffb6c152", + "metadata.json": "f36cdae2700eefedd2282d3f9776a25a" +} \ No newline at end of file diff --git a/pkg/crayfishx-hiera_http-1.2.0/lib/hiera/backend/http_backend.rb b/pkg/crayfishx-hiera_http-1.2.0/lib/hiera/backend/http_backend.rb new file mode 100644 index 0000000..0e61ec6 --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.2.0/lib/hiera/backend/http_backend.rb @@ -0,0 +1,138 @@ +class Hiera + module Backend + class Http_backend + + def initialize + require 'net/http' + require 'net/https' + @config = Config[:http] + + @http = Net::HTTP.new(@config[:host], @config[:port]) + @http.read_timeout = @config[:http_read_timeout] || 10 + @http.open_timeout = @config[:http_connect_timeout] || 10 + + if @config[:use_ssl] + @http.use_ssl = true + + if @config[:ssl_verify] == false + @http.verify_mode = OpenSSL::SSL::VERIFY_NONE + else + @http.verify_mode = OpenSSL::SSL::VERIFY_PEER + end + + if @config[:ssl_cert] + store = OpenSSL::X509::Store.new + store.add_cert(OpenSSL::X509::Certificate.new(File.read(@config[:ssl_ca_cert]))) + @http.cert_store = store + + @http.key = OpenSSL::PKey::RSA.new(File.read(@config[:ssl_cert])) + @http.cert = OpenSSL::X509::Certificate.new(File.read(@config[:ssl_key])) + end + else + @http.use_ssl = false + end + end + + def lookup(key, scope, order_override, resolution_type) + + answer = nil + + paths = @config[:paths].map { |p| Backend.parse_string(p, scope, { 'key' => key }) } + paths.insert(0, order_override) if order_override + + + paths.each do |path| + + Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") + httpreq = Net::HTTP::Get.new(path) + + if @config[:use_auth] + httpreq.basic_auth @config[:auth_user], @config[:auth_pass] + end + + begin + httpres = @http.request(httpreq) + rescue Exception => e + Hiera.warn("[hiera-http]: Net::HTTP threw exception #{e.message}") + raise Exception, e.message unless @config[:failure] == 'graceful' + next + end + + unless httpres.kind_of?(Net::HTTPSuccess) + Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}") + Hiera.debug("HTTP response code was #{httpres.code}") + unless ( httpres.code == '404' && @config[:ignore_404] == true ) + raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' + end + next + end + + result = self.parse_response(key, httpres.body) + next unless result + + parsed_result = Backend.parse_answer(result, scope) + + case resolution_type + when :array + answer ||= [] + answer << parsed_result + when :hash + answer ||= {} + answer = parsed_result.merge answer + else + answer = parsed_result + break + end + end + answer + end + + + def parse_response(key,answer) + + return nil unless answer + + Hiera.debug("[hiera-http]: Query returned data, parsing response as #{@config[:output] || 'plain'}") + + case @config[:output] + + when 'plain' + # When the output format is configured as plain we assume that if the + # endpoint URL returns an HTTP success then the contents of the response + # body is the value itself, or nil. + # + answer + when 'json' + # If JSON is specified as the output format, assume the output of the + # endpoint URL is a JSON document and return keypart that matched our + # lookup key + self.json_handler(key,answer) + when 'yaml' + # If YAML is specified as the output format, assume the output of the + # endpoint URL is a YAML document and return keypart that matched our + # lookup key + self.yaml_handler(key,answer) + else + answer + end + end + + # Handlers + # Here we define specific handlers to parse the output of the http request + # and return a value. Currently we support YAML and JSON + # + def json_handler(key,answer) + require 'rubygems' + require 'json' + JSON.parse(answer)[key] + end + + def yaml_handler(answer) + require 'yaml' + YAML.parse(answer)[key] + end + + end + end +end + diff --git a/pkg/crayfishx-hiera_http-1.2.0/metadata.json b/pkg/crayfishx-hiera_http-1.2.0/metadata.json new file mode 100644 index 0000000..917bc5f --- /dev/null +++ b/pkg/crayfishx-hiera_http-1.2.0/metadata.json @@ -0,0 +1,13 @@ +{ + "name": "crayfishx-hiera_http", + "version": "1.2.0", + "author": "Craig Dunn", + "summary": "Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.", + "license": "Apache 2.0", + "source": "http://github.com/crayfishx/hiera-http", + "project_page": "https://github.com/crayfishx/hiera-http", + "issues_url": "https://github.com/crayfishx/hiera-http/issues", + "dependencies": [ + + ] +} From 8e37f86a47719693959e3afcf7b3eba63412ba79 Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Fri, 18 Jul 2014 11:03:49 +0100 Subject: [PATCH 13/28] metadata --- metadata.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 metadata.json diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..62d5332 --- /dev/null +++ b/metadata.json @@ -0,0 +1,13 @@ +{ + "name": "crayfishx-hiera_http", + "version": "1.2.0", + "author": "Craig Dunn", + "summary": "Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.", + "license": "Apache 2.0", + "source": "http://github.com/crayfishx/hiera-http", + "project_page": "https://github.com/crayfishx/hiera-http", + "issues_url": "https://github.com/crayfishx/hiera-http/issues", + "dependencies": [ + ] +} + From b4103f974308b314675ba8f47d749d9e1f3a518f Mon Sep 17 00:00:00 2001 From: Ronald Moesbergen Date: Thu, 31 Jul 2014 12:53:28 +0200 Subject: [PATCH 14/28] Use hiera backend merge function to support deep_merge --- lib/hiera/backend/http_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index fb6c99f..706c544 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -79,7 +79,7 @@ def lookup(key, scope, order_override, resolution_type) answer << parsed_result when :hash answer ||= {} - answer = parsed_result.merge answer + answer = Backend.merge_answer(parsed_result, answer) else answer = parsed_result break From 56845c914405af8eb9e197f309b69e54328103aa Mon Sep 17 00:00:00 2001 From: nemski Date: Wed, 29 Oct 2014 15:09:31 +1100 Subject: [PATCH 15/28] Return false values Fix for a bug where retrieving false values returns nil --- lib/hiera/backend/http_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 706c544..d07e584 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -69,7 +69,7 @@ def lookup(key, scope, order_override, resolution_type) end result = self.parse_response(key, httpres.body) - next unless result + next if result.nil? parsed_result = Backend.parse_answer(result, scope) From ffbb161445efcbd2c696f8aa2282e71e3716ec85 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Wed, 11 Feb 2015 10:30:42 +0800 Subject: [PATCH 16/28] Cache parsed HTTP responses --- README.md | 3 + lib/hiera/backend/http_backend.rb | 93 ++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index d43f603..fb13c06 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ The following is an example hiera.yaml configuration for use with hiera-http :host: 127.0.0.1 :port: 5984 :output: json + :cache_timeout: 10 :failure: graceful :paths: - /configuration/%{fqdn} @@ -31,6 +32,8 @@ The following are optional configuration parameters `:http_read_timeout: ` : Timeout in seconds for waiting for a HTTP response (default 10) +`:cache_timeout: ` : Timeout in seconds for HTTP requests to a same path (default 10) + `:failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances `:ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors. diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index d07e584..31fe50f 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -10,7 +10,10 @@ def initialize @http = Net::HTTP.new(@config[:host], @config[:port]) @http.read_timeout = @config[:http_read_timeout] || 10 @http.open_timeout = @config[:http_connect_timeout] || 10 + + @cache = {} @path_base = @config[:path_base] || '' + @cache_timeout = @config[:cache_timeout] || 10 if @config[:use_ssl] @http.use_ssl = true @@ -35,7 +38,6 @@ def initialize end def lookup(key, scope, order_override, resolution_type) - answer = nil paths = @config[:paths].clone @@ -47,15 +49,10 @@ def lookup(key, scope, order_override, resolution_type) Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") httpreq = Net::HTTP::Get.new(path) - if @config[:use_auth] - httpreq.basic_auth @config[:auth_user], @config[:auth_pass] - end - - begin - httpres = @http.request(httpreq) - rescue Exception => e - Hiera.warn("[hiera-http]: Net::HTTP threw exception #{e.message}") + result = http_get_and_parse_with_cache(path) + result = result[key] if result.is_a?(Hash) raise Exception, e.message unless @config[:failure] == 'graceful' + next unless result next end @@ -89,30 +86,19 @@ def lookup(key, scope, order_override, resolution_type) end - def parse_response(key,answer) - - return nil unless answer + private - Hiera.debug("[hiera-http]: Query returned data, parsing response as #{@config[:output] || 'plain'}") + def parse_response(answer) + return unless answer - case @config[:output] + format = @config[:output] || 'plain' + Hiera.debug("[hiera-http]: Query returned data, parsing response as #{format}") - when 'plain' - # When the output format is configured as plain we assume that if the - # endpoint URL returns an HTTP success then the contents of the response - # body is the value itself, or nil. - # - answer + case format when 'json' - # If JSON is specified as the output format, assume the output of the - # endpoint URL is a JSON document and return keypart that matched our - # lookup key - self.json_handler(key,answer) + parse_json answer when 'yaml' - # If YAML is specified as the output format, assume the output of the - # endpoint URL is a YAML document and return keypart that matched our - # lookup key - self.yaml_handler(key,answer) + parse_yaml answer else answer end @@ -120,17 +106,58 @@ def parse_response(key,answer) # Handlers # Here we define specific handlers to parse the output of the http request - # and return a value. Currently we support YAML and JSON + # and return its structured representation. Currently we support YAML and JSON # - def json_handler(key,answer) + def parse_json(answer) require 'rubygems' require 'json' - JSON.parse(answer)[key] + JSON.parse(answer) end - def yaml_handler(answer) + def parse_yaml(answer) require 'yaml' - YAML.parse(answer)[key] + YAML.parse(answer) + end + + def http_get_and_parse_with_cache(path) + return http_get(path) if @cache_timeout <= 0 + + now = Time.now.to_i + expired_at = now + @cache_timeout + unless @cache[path] && @cache[path][:created_at] < expired_at + @cache[path] = { + :created_at => now, + :result => http_get_and_parse(path) + } + end + @cache[path][:result] + end + + def http_get_and_parse(path) + httpreq = Net::HTTP::Get.new(path) + + if @config[:use_auth] + httpreq.basic_auth @config[:auth_user], @config[:auth_pass] + end + + begin + httpres = @http.request(httpreq) + rescue Exception => e + Hiera.warn("[hiera-http]: Net::HTTP threw exception #{e.message}") + raise Exception, e.message unless @config[:failure] == 'graceful' + return + end + + unless httpres.kind_of?(Net::HTTPSuccess) + Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}") + Hiera.debug("HTTP response code was #{httpres.code}") + unless httpres.code == '404' && @config[:ignore_404] + raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' + end + return + end + + parse_response httpres.body end end From fc1e9f516ce91d0301ef330370d844185f6e27c0 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Thu, 12 Mar 2015 20:38:57 +0800 Subject: [PATCH 17/28] Periodically clean cache Evict all stale entries from the cache periodically, to avoid the situation where entries sit in the cache forever. --- lib/hiera/backend/http_backend.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 31fe50f..6009d7b 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -124,6 +124,11 @@ def http_get_and_parse_with_cache(path) now = Time.now.to_i expired_at = now + @cache_timeout + + # Deleting all stale cache entries can be expensive. Do not do it every time + periodically_clean_cache(now, expired_at) + + # Just refresh the entry being requested for performance unless @cache[path] && @cache[path][:created_at] < expired_at @cache[path] = { :created_at => now, @@ -160,6 +165,16 @@ def http_get_and_parse(path) parse_response httpres.body end + CLEAN_CACHE_INTERVAL = 3600 + + def periodically_clean_cache(now, expired_at) + return if now < @clean_cache_at.to_i + + @clean_cache_at = now + CLEAN_CACHE_INTERVAL + @cache.select! do |_, entry| + entry[:created_at] < expired_at + end + end end end end From 1702f1ccf91f737e0bf2ff6f80f958664a65ba2c Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 18 Mar 2015 11:46:05 +0100 Subject: [PATCH 18/28] made cache_clean_interval a configurable option --- README.md | 2 ++ lib/hiera/backend/http_backend.rb | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fb13c06..b568d17 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ The following are optional configuration parameters `:cache_timeout: ` : Timeout in seconds for HTTP requests to a same path (default 10) +`:cache_clean_interval: ` : Interval (in secs) to clean the cache (default 3600), set to 0 to disable cache cleaning + `:failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances `:ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors. diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 6009d7b..1087473 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -14,6 +14,7 @@ def initialize @cache = {} @path_base = @config[:path_base] || '' @cache_timeout = @config[:cache_timeout] || 10 + @cache_clean_interval = @config[:cache_clean_interval] || 3600 if @config[:use_ssl] @http.use_ssl = true @@ -126,7 +127,7 @@ def http_get_and_parse_with_cache(path) expired_at = now + @cache_timeout # Deleting all stale cache entries can be expensive. Do not do it every time - periodically_clean_cache(now, expired_at) + periodically_clean_cache(now, expired_at) unless @cache_clean_interval == 0 # Just refresh the entry being requested for performance unless @cache[path] && @cache[path][:created_at] < expired_at @@ -165,12 +166,11 @@ def http_get_and_parse(path) parse_response httpres.body end - CLEAN_CACHE_INTERVAL = 3600 def periodically_clean_cache(now, expired_at) return if now < @clean_cache_at.to_i - @clean_cache_at = now + CLEAN_CACHE_INTERVAL + @clean_cache_at = now + @cache_clean_interval @cache.select! do |_, entry| entry[:created_at] < expired_at end From d7012fe5c9b2bd034c72eb73be44ad72d89692a9 Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 18 Mar 2015 12:00:19 +0100 Subject: [PATCH 19/28] prepare 1.3.0 notes --- README.md | 6 ++++++ metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b568d17..d775c32 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,15 @@ Theres a few things still on my list that I'm going to be adding, including * SSL components contributed from Ben Ford * Louis Jencka +* Jun Wu + ### Change Log +#### 1.3.0 + +* Added lookup caching features + #### 1.2.0 * Support for SSL verify options diff --git a/metadata.json b/metadata.json index 62d5332..203104c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "crayfishx-hiera_http", - "version": "1.2.0", + "version": "1.3.0", "author": "Craig Dunn", "summary": "Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.", "license": "Apache 2.0", From 0273656cdf57fcf40a5cc87b8d838d2b526825f4 Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 18 Mar 2015 12:09:51 +0100 Subject: [PATCH 20/28] Added apache 2.0 license --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c05ac68 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 Craig Dunn + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From cd01d3d042729e565d1bda4e08ee0638f9bd278b Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 18 Mar 2015 12:11:46 +0100 Subject: [PATCH 21/28] bumped gem version --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index b55991e..8b65489 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rubygems/package_task' spec = Gem::Specification.new do |gem| gem.name = "hiera-http" - gem.version = "1.2.0" + gem.version = "1.3.0" gem.summary = "HTTP backend for Hiera" gem.email = "craig@craigdunn.org" gem.author = "Craig Dunn" From b82c76e1c94e4d808ad34db0ae3bf416305d3abb Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 18 Mar 2015 12:23:54 +0100 Subject: [PATCH 22/28] added os to metadata.json --- metadata.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/metadata.json b/metadata.json index 203104c..6dafef5 100644 --- a/metadata.json +++ b/metadata.json @@ -7,6 +7,30 @@ "source": "http://github.com/crayfishx/hiera-http", "project_page": "https://github.com/crayfishx/hiera-http", "issues_url": "https://github.com/crayfishx/hiera-http/issues", + "operatingsystem_support": [ + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "12.04", + "14.04" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + } + ], "dependencies": [ ] } From e8eccb5ced740dcd367f64e61c7ad81aacf97381 Mon Sep 17 00:00:00 2001 From: nemski Date: Wed, 25 Mar 2015 15:04:13 +1100 Subject: [PATCH 23/28] Fix to support ruby 1.8.7 --- lib/hiera/backend/http_backend.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 1087473..7c12a52 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -171,8 +171,8 @@ def periodically_clean_cache(now, expired_at) return if now < @clean_cache_at.to_i @clean_cache_at = now + @cache_clean_interval - @cache.select! do |_, entry| - entry[:created_at] < expired_at + @cache.delete_if do |_, entry| + entry[:created_at] > expired_at end end end From a50898a553ba6791eb155e1c8245f22d4cac72ea Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Wed, 25 Mar 2015 04:18:25 -0400 Subject: [PATCH 24/28] 1.3.1 bugfix release --- README.md | 4 ++++ metadata.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d775c32..e8db8ac 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,10 @@ Theres a few things still on my list that I'm going to be adding, including ### Change Log +#### 1.3.1 + +* Bugfix release for ruby 1.8.7 support + #### 1.3.0 * Added lookup caching features diff --git a/metadata.json b/metadata.json index 6dafef5..9667efc 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "crayfishx-hiera_http", - "version": "1.3.0", + "version": "1.3.1", "author": "Craig Dunn", "summary": "Back end plugin for Hiera that allows lookup to be sourced from HTTP queries.", "license": "Apache 2.0", From 276e0748b09898f27486717d68d482d203b9c2a8 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Thu, 25 Jul 2013 12:55:27 -0400 Subject: [PATCH 25/28] Add path_base config, ensure all paths go through parse_string --- lib/hiera/backend/http_backend.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 7c12a52..2daf526 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -10,6 +10,7 @@ def initialize @http = Net::HTTP.new(@config[:host], @config[:port]) @http.read_timeout = @config[:http_read_timeout] || 10 @http.open_timeout = @config[:http_connect_timeout] || 10 + @path_base = @config[:path_base] || '' @cache = {} @path_base = @config[:path_base] || '' From 73ed83b8eed49e72eb2cbfc3004b2725c98821a0 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Sat, 28 Mar 2015 09:15:28 -0400 Subject: [PATCH 26/28] add path_suffix as well --- lib/hiera/backend/http_backend.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 2daf526..81cf037 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -11,6 +11,7 @@ def initialize @http.read_timeout = @config[:http_read_timeout] || 10 @http.open_timeout = @config[:http_connect_timeout] || 10 @path_base = @config[:path_base] || '' + @path_suffix = @config[:path_suffix] || '' @cache = {} @path_base = @config[:path_base] || '' @@ -44,7 +45,7 @@ def lookup(key, scope, order_override, resolution_type) paths = @config[:paths].clone paths.insert(0, order_override) if order_override - paths.map! { |p| Backend.parse_string(@path_base + p, scope, { 'key' => key }) } + paths.map! { |p| Backend.parse_string(@path_base + p + @path_suffix, scope, { 'key' => key }) } paths.each do |path| @@ -122,7 +123,7 @@ def parse_yaml(answer) end def http_get_and_parse_with_cache(path) - return http_get(path) if @cache_timeout <= 0 + return http_get_and_parse(path) if @cache_timeout <= 0 now = Time.now.to_i expired_at = now + @cache_timeout @@ -179,4 +180,3 @@ def periodically_clean_cache(now, expired_at) end end end - From d50024b58f94431fafb62d9ca84cf842159ef5ef Mon Sep 17 00:00:00 2001 From: David Blacka Date: Sun, 29 Mar 2015 10:54:50 -0400 Subject: [PATCH 27/28] fix rebase errors --- README.md | 1 + lib/hiera/backend/http_backend.rb | 17 ----------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/README.md b/README.md index e8db8ac..deba6f0 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ The `:paths:` parameter can also parse the lookup key, eg: `:ssl_key`: Specify location of SSL key `:ssl_verify`: Specify whether to verify SSL certificates (default: true) + `:use_auth:`: When set to true, enable basic auth (default: false) `:auth_user:`: The user for basic auth diff --git a/lib/hiera/backend/http_backend.rb b/lib/hiera/backend/http_backend.rb index 81cf037..a1c2455 100644 --- a/lib/hiera/backend/http_backend.rb +++ b/lib/hiera/backend/http_backend.rb @@ -14,7 +14,6 @@ def initialize @path_suffix = @config[:path_suffix] || '' @cache = {} - @path_base = @config[:path_base] || '' @cache_timeout = @config[:cache_timeout] || 10 @cache_clean_interval = @config[:cache_clean_interval] || 3600 @@ -50,25 +49,9 @@ def lookup(key, scope, order_override, resolution_type) paths.each do |path| Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") - httpreq = Net::HTTP::Get.new(path) result = http_get_and_parse_with_cache(path) result = result[key] if result.is_a?(Hash) - raise Exception, e.message unless @config[:failure] == 'graceful' - next unless result - next - end - - unless httpres.kind_of?(Net::HTTPSuccess) - Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}") - Hiera.debug("HTTP response code was #{httpres.code}") - unless ( httpres.code == '404' && @config[:ignore_404] == true ) - raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful' - end - next - end - - result = self.parse_response(key, httpres.body) next if result.nil? parsed_result = Backend.parse_answer(result, scope) From b14986998d806daf5f0a99fa130f93047e348a73 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Sun, 29 Mar 2015 10:59:34 -0400 Subject: [PATCH 28/28] add path_base and path_suffix config items to README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index deba6f0..fa027b7 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ The `:paths:` parameter can also parse the lookup key, eg: :paths: /configuration.php?lookup=%{key} +`:path_base:`: This string will be prepended to every path. + +`:path_suffix:`: This string will be appended to every path. + `:use_ssl:`: When set to true, enable SSL (default: false) `:ssl_ca_cert`: Specify a CA cert for use with SSL