hiera-wrapper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.md +23 -0
- data/README.md +90 -0
- data/Rakefile +9 -0
- data/hiera-wrapper.gemspec +18 -0
- data/hiera.yaml.example +26 -0
- data/lib/hiera/backend/wrapper_backend.rb +152 -0
- data/test/etc/hiera_bl_and_wl.yaml +21 -0
- data/test/etc/hiera_empty_bl_empty_wl.yaml +22 -0
- data/test/etc/hiera_no_bl_no_wl.yaml +18 -0
- data/test/etc/hiera_nolists.yaml +24 -0
- data/test/etc/hieradb/common.json +4 -0
- data/test/etc/hieradb/common.yaml +6 -0
- data/test/test_bl_and_wl.rb +68 -0
- data/test/test_empty_lists.rb +106 -0
- data/test/test_nolists.rb +106 -0
- data/test/test_one.rb +6 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Portions copyright (c) 2010 Andre Arko
|
|
2
|
+
Portions copyright (c) 2009 Engine Yard
|
|
3
|
+
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Introduction
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Hiera is a configuration data store with pluggable back ends; hiera-wrapper is a backend written to allow filters to be applied for requests to backends. Hiera normally performs lookups in each of the backends for each query. With modern classes having quite a few optional parameters, the number of lookups for a catalogue compilaton can grow quite large.
|
|
5
|
+
|
|
6
|
+
Our use case for this backend is that we use ENC-like database which is quite slow to access and should only contain puppet-role and a few other parameters such as server location, puppet-environment, etc.
|
|
7
|
+
|
|
8
|
+
By applying a simple whitelist on the database backend, catalogue compilation times dropped from 60 to 10 seconds.
|
|
9
|
+
|
|
10
|
+
Configuration
|
|
11
|
+
=============
|
|
12
|
+
|
|
13
|
+
See below; specify the wrapper backend in the ':backends:' section. Create a new section ':wrapper:' like below. Each of the elements of the ':backends:' hash is loaded as a backend and optional blacklist and whitelists are applied.
|
|
14
|
+
|
|
15
|
+
Blacklists are applied first; if the lookup key matches any of the elements on the blacklist (regexp) then the query to that backend is considered not to have returned a value.
|
|
16
|
+
|
|
17
|
+
If a whitelist exists then the lookup key must match one of the regexp in order to be passed on to that backend.
|
|
18
|
+
|
|
19
|
+
It probably makes more sense once you play with it a little ;)
|
|
20
|
+
|
|
21
|
+
<pre>
|
|
22
|
+
---
|
|
23
|
+
:backends:
|
|
24
|
+
- wrapper
|
|
25
|
+
|
|
26
|
+
:logger: console
|
|
27
|
+
|
|
28
|
+
:hierarchy:
|
|
29
|
+
- "%{location}"
|
|
30
|
+
- "%{environment}"
|
|
31
|
+
- common
|
|
32
|
+
|
|
33
|
+
:wrapper:
|
|
34
|
+
:backends:
|
|
35
|
+
- :yaml:
|
|
36
|
+
:blacklist:
|
|
37
|
+
- bl
|
|
38
|
+
:whitelist:
|
|
39
|
+
- ^wl$
|
|
40
|
+
- black_and_white
|
|
41
|
+
- :json:
|
|
42
|
+
|
|
43
|
+
:json:
|
|
44
|
+
:datadir: test/etc/hieradb
|
|
45
|
+
:yaml:
|
|
46
|
+
:datadir: test/etc/hieradb
|
|
47
|
+
</pre>
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
========
|
|
51
|
+
<pre>
|
|
52
|
+
$ hiera -c hiera.yaml.example black_and_white
|
|
53
|
+
nil
|
|
54
|
+
$ hiera -c hiera.yaml.example wl
|
|
55
|
+
should_be_allowed
|
|
56
|
+
$ hiera -c hiera.yaml.example bl
|
|
57
|
+
nil
|
|
58
|
+
$ hiera -c hiera.yaml.example json_and_yaml
|
|
59
|
+
json_and_yaml_json_value
|
|
60
|
+
</pre>
|
|
61
|
+
|
|
62
|
+
<pre>$ cat test/etc/hieradb/common.yaml
|
|
63
|
+
---
|
|
64
|
+
yaml_only: yaml_only_value
|
|
65
|
+
json_and_yaml: json_and_yaml_yaml_value
|
|
66
|
+
bl: should_be_blocked
|
|
67
|
+
wl: should_be_allowed
|
|
68
|
+
black_and_white: should_be_blocked
|
|
69
|
+
</pre>
|
|
70
|
+
|
|
71
|
+
<pre>cat test/etc/hieradb/common.json
|
|
72
|
+
{
|
|
73
|
+
"json_only": "json_only_value",
|
|
74
|
+
"json_and_yaml": "json_and_yaml_json_value"
|
|
75
|
+
}
|
|
76
|
+
</pre>
|
|
77
|
+
|
|
78
|
+
Contact
|
|
79
|
+
=======
|
|
80
|
+
|
|
81
|
+
* Author: Frank Ederveen
|
|
82
|
+
* Email: frank@crystalconsulting.eu
|
|
83
|
+
|
|
84
|
+
License
|
|
85
|
+
=======
|
|
86
|
+
|
|
87
|
+
This software is provided "as is". It works for me but it will probably eat your homework and set you house on fire.
|
|
88
|
+
Do whatever you want to do with it but do not come complaining to me.
|
|
89
|
+
|
|
90
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |gem|
|
|
4
|
+
gem.authors = ["Frank Ederveen"]
|
|
5
|
+
gem.email = ["frank@crystalconsulting.eu"]
|
|
6
|
+
gem.description = %q{A simple hiera backend wrapper for existing backends, allowing filtering with black and whitelists}
|
|
7
|
+
gem.summary = %q{Hiera backend wrapper}
|
|
8
|
+
gem.homepage = "https://github.com/senax/hiera-wrapper"
|
|
9
|
+
|
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
13
|
+
gem.name = "hiera-wrapper"
|
|
14
|
+
gem.license = 'MIT'
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = '0.0.1'
|
|
17
|
+
end
|
|
18
|
+
|
data/hiera.yaml.example
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
:backends:
|
|
3
|
+
- wrapper
|
|
4
|
+
|
|
5
|
+
:logger: console
|
|
6
|
+
|
|
7
|
+
:hierarchy:
|
|
8
|
+
- "%{location}"
|
|
9
|
+
- "%{environment}"
|
|
10
|
+
- common
|
|
11
|
+
|
|
12
|
+
:wrapper:
|
|
13
|
+
:backends:
|
|
14
|
+
- :yaml:
|
|
15
|
+
:blacklist:
|
|
16
|
+
- bl
|
|
17
|
+
:whitelist:
|
|
18
|
+
- ^wl$
|
|
19
|
+
- black_and_white
|
|
20
|
+
- :json:
|
|
21
|
+
|
|
22
|
+
:json:
|
|
23
|
+
:datadir: test/etc/hieradb
|
|
24
|
+
:yaml:
|
|
25
|
+
:datadir: test/etc/hieradb
|
|
26
|
+
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
class Hiera
|
|
2
|
+
module Backend
|
|
3
|
+
class Wrapper_backend
|
|
4
|
+
def initialize(cache=nil)
|
|
5
|
+
require 'yaml'
|
|
6
|
+
Hiera.debug("Hiera WRAP backend starting")
|
|
7
|
+
|
|
8
|
+
@cache = cache || Filecache.new
|
|
9
|
+
load_backends
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def load_backends
|
|
13
|
+
Config[:wrapper][:backends].each do |wrap_entry|
|
|
14
|
+
backend=wrap_entry.keys.first.to_s
|
|
15
|
+
begin
|
|
16
|
+
require "hiera/backend/#{backend.to_s.downcase}_backend"
|
|
17
|
+
rescue LoadError => e
|
|
18
|
+
Hiera.warn "Cannot load backend #{backend}: #{e}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# def find_backend(backend_constant)
|
|
24
|
+
# backend = Backend.const_get(backend_constant).new
|
|
25
|
+
# return backend.method(:lookup).arity == 4 ? Backend1xWrapper.new(backend) : backend
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
def check_filters(options,key)
|
|
29
|
+
# if there is a blacklist, make sure the key does not match any of the entries.
|
|
30
|
+
# if there is a whitelist, make sure the key matches at least one of those entries.
|
|
31
|
+
#
|
|
32
|
+
# Hiera.debug("Check_filters: #{options.inspect} #{key.inspect}")
|
|
33
|
+
return if options.nil?
|
|
34
|
+
return unless options.is_a?(Hash)
|
|
35
|
+
if options.has_key?(:blacklist) and options[:blacklist].is_a?(Array) and options[:blacklist].size >0
|
|
36
|
+
options[:blacklist].each do |bl|
|
|
37
|
+
if Regexp.new(bl) =~ key
|
|
38
|
+
Hiera.debug("blacklist reject, found #{key} in #{options[:blacklist].inspect}")
|
|
39
|
+
throw :no_such_key
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
if options.has_key?(:whitelist) and options[:whitelist].is_a?(Array) and options[:whitelist].size >0
|
|
44
|
+
options[:whitelist].each do |wl|
|
|
45
|
+
return if Regexp.new(wl) =~ key
|
|
46
|
+
end
|
|
47
|
+
Hiera.debug("whitelist reject, not found #{key} in #{options[:whitelist].inspect}")
|
|
48
|
+
throw :no_such_key
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def lookup(key, scope, order_override, resolution_type)
|
|
53
|
+
Hiera.debug("WRAP.lookup #{key.inspect}, resolution_type = #{resolution_type.inspect}")
|
|
54
|
+
Hiera.debug("WRAP config: #{Config[:wrapper].inspect}")
|
|
55
|
+
@backends ||= {}
|
|
56
|
+
answer = nil
|
|
57
|
+
|
|
58
|
+
#Config[:backends].each do |backend|
|
|
59
|
+
Config[:wrapper][:backends].each do |wrap_entry|
|
|
60
|
+
backend=wrap_entry.keys.first.to_s
|
|
61
|
+
options=wrap_entry[backend.to_sym]
|
|
62
|
+
if true || constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
|
|
63
|
+
@backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
|
|
64
|
+
new_answer = catch(:no_such_key) do
|
|
65
|
+
check_filters(options,key)
|
|
66
|
+
new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
if not new_answer.nil?
|
|
70
|
+
case resolution_type
|
|
71
|
+
when :array
|
|
72
|
+
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
|
73
|
+
answer ||= []
|
|
74
|
+
answer << new_answer
|
|
75
|
+
when :hash
|
|
76
|
+
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
|
77
|
+
answer ||= {}
|
|
78
|
+
answer = merge_answer(new_answer,answer)
|
|
79
|
+
else
|
|
80
|
+
answer = new_answer
|
|
81
|
+
break
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
answer = Backend.resolve_answer(answer, resolution_type) unless answer.nil?
|
|
88
|
+
return answer
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def lookup3(key, scope, order_override, resolution_type, context)
|
|
92
|
+
Hiera.debug("WRAP.lookup #{key.inspect}, resolution_type = #{resolution_type.inspect}")
|
|
93
|
+
@backends ||= {}
|
|
94
|
+
answer = nil
|
|
95
|
+
found = false
|
|
96
|
+
Hiera.debug("WRAP config: #{Config[:wrapper].inspect}")
|
|
97
|
+
|
|
98
|
+
# order_override is kept as an explicit argument for backwards compatibility, but should be specified
|
|
99
|
+
# in the context for internal handling.
|
|
100
|
+
context ||= {}
|
|
101
|
+
order_override ||= context[:order_override]
|
|
102
|
+
context[:order_override] ||= order_override
|
|
103
|
+
|
|
104
|
+
strategy = resolution_type.is_a?(Hash) ? :hash : resolution_type
|
|
105
|
+
|
|
106
|
+
segments = key.split('.')
|
|
107
|
+
subsegments = nil
|
|
108
|
+
if segments.size > 1
|
|
109
|
+
raise ArgumentError, "Resolution type :#{strategy} is illegal when doing segmented key lookups" unless strategy.nil? || strategy == :priority
|
|
110
|
+
subsegments = segments.drop(1)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
found = false
|
|
114
|
+
Config[:wrapper][:backends].each do |wrap_entry|
|
|
115
|
+
backend=wrap_entry.keys.first.to_s
|
|
116
|
+
options=wrap_entry[backend.to_sym]
|
|
117
|
+
backend_constant = "#{backend.to_s.capitalize}_backend"
|
|
118
|
+
backend = (@backends[backend] ||= find_backend(backend_constant))
|
|
119
|
+
found_in_backend = false
|
|
120
|
+
new_answer = catch(:no_such_key) do
|
|
121
|
+
check_filters(options,key)
|
|
122
|
+
value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
|
|
123
|
+
value = Backend.qualified_lookup(subsegments, value) unless subsegments.nil?
|
|
124
|
+
found_in_backend = true
|
|
125
|
+
value
|
|
126
|
+
end
|
|
127
|
+
next unless found_in_backend
|
|
128
|
+
found = true
|
|
129
|
+
|
|
130
|
+
case strategy
|
|
131
|
+
when :array
|
|
132
|
+
raise Exception, "Hiera type mismatch for key '#{key}': expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
|
133
|
+
answer ||= []
|
|
134
|
+
answer << new_answer
|
|
135
|
+
when :hash
|
|
136
|
+
raise Exception, "Hiera type mismatch for key '#{key}': expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
|
137
|
+
answer ||= {}
|
|
138
|
+
answer = Backend.merge_answer(new_answer, answer, resolution_type)
|
|
139
|
+
else
|
|
140
|
+
answer = new_answer
|
|
141
|
+
break
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
throw :no_such_key unless found
|
|
146
|
+
return answer
|
|
147
|
+
end # lookup3
|
|
148
|
+
|
|
149
|
+
end # Wrapper_backend
|
|
150
|
+
end # backend
|
|
151
|
+
end # class hiera
|
|
152
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
:backends:
|
|
3
|
+
- wrapper
|
|
4
|
+
:logger: console
|
|
5
|
+
:hierarchy:
|
|
6
|
+
- "%{location}"
|
|
7
|
+
- "%{environment}"
|
|
8
|
+
- common
|
|
9
|
+
:wrapper:
|
|
10
|
+
:backends:
|
|
11
|
+
- :yaml:
|
|
12
|
+
:blacklist:
|
|
13
|
+
- bl
|
|
14
|
+
:whitelist:
|
|
15
|
+
- ^wl$
|
|
16
|
+
- black_and_white
|
|
17
|
+
|
|
18
|
+
:yaml:
|
|
19
|
+
:datadir: test/etc/hieradb
|
|
20
|
+
:puppet:
|
|
21
|
+
:datasource: data
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
:backends:
|
|
3
|
+
- wrapper
|
|
4
|
+
:logger: console
|
|
5
|
+
:hierarchy:
|
|
6
|
+
- ! '%{location}'
|
|
7
|
+
- ! '%{environment}'
|
|
8
|
+
- common
|
|
9
|
+
:wrapper:
|
|
10
|
+
:backends:
|
|
11
|
+
- :json:
|
|
12
|
+
:blacklist:
|
|
13
|
+
:whitelist:
|
|
14
|
+
- :yaml:
|
|
15
|
+
:blacklist:
|
|
16
|
+
:whitelist:
|
|
17
|
+
:yaml:
|
|
18
|
+
:datadir: test/etc/hieradb
|
|
19
|
+
:json:
|
|
20
|
+
:datadir: test/etc/hieradb
|
|
21
|
+
:puppet:
|
|
22
|
+
:datasource: data
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
:backends:
|
|
3
|
+
- wrapper
|
|
4
|
+
:logger: console
|
|
5
|
+
:hierarchy:
|
|
6
|
+
- ! '%{location}'
|
|
7
|
+
- ! '%{environment}'
|
|
8
|
+
- common
|
|
9
|
+
:wrapper:
|
|
10
|
+
:backends:
|
|
11
|
+
- :json:
|
|
12
|
+
- :yaml:
|
|
13
|
+
:yaml:
|
|
14
|
+
:datadir: test/etc/hieradb
|
|
15
|
+
:json:
|
|
16
|
+
:datadir: test/etc/hieradb
|
|
17
|
+
:puppet:
|
|
18
|
+
:datasource: data
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
:backends:
|
|
3
|
+
- wrapper
|
|
4
|
+
|
|
5
|
+
:logger: console
|
|
6
|
+
|
|
7
|
+
:hierarchy:
|
|
8
|
+
- "%{location}"
|
|
9
|
+
- "%{environment}"
|
|
10
|
+
- common
|
|
11
|
+
|
|
12
|
+
:wrapper:
|
|
13
|
+
:backends:
|
|
14
|
+
- :json:
|
|
15
|
+
- :yaml:
|
|
16
|
+
|
|
17
|
+
:yaml:
|
|
18
|
+
:datadir: test/etc/hieradb
|
|
19
|
+
|
|
20
|
+
:json:
|
|
21
|
+
:datadir: test/etc/hieradb
|
|
22
|
+
|
|
23
|
+
:puppet:
|
|
24
|
+
:datasource: data
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
gem 'minitest'
|
|
3
|
+
#require 'minitest/autorun'
|
|
4
|
+
require 'minitest/spec'
|
|
5
|
+
require 'hiera'
|
|
6
|
+
require 'hiera/backend/wrapper_backend'
|
|
7
|
+
|
|
8
|
+
class Hiera
|
|
9
|
+
module Backend
|
|
10
|
+
describe Wrapper_backend do
|
|
11
|
+
hiera_config=YAML.load_file("test/etc/hiera_bl_and_wl.yaml")
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
Config.load(hiera_config)
|
|
15
|
+
@new_out,@new_err = capture_subprocess_io do
|
|
16
|
+
@backend=Wrapper_backend.new()
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "Should announce its creation" do
|
|
21
|
+
assert_equal("",@new_out)
|
|
22
|
+
assert_match(/Hiera WRAP backend starting/,@new_err)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "lookup should fail when not found in either backend" do
|
|
26
|
+
result=""
|
|
27
|
+
out,err = capture_subprocess_io do
|
|
28
|
+
result=@backend.lookup("no_such_key",{},nil, :priority)
|
|
29
|
+
end
|
|
30
|
+
assert_equal(nil,result)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# cases:
|
|
34
|
+
# bl, wl, result
|
|
35
|
+
# 00 -> reject
|
|
36
|
+
# 01 -> found
|
|
37
|
+
# 10 -> reject
|
|
38
|
+
# 11 -> reject*
|
|
39
|
+
# proove a few multi-backend cases?
|
|
40
|
+
|
|
41
|
+
it "lookup of bl should not return value" do
|
|
42
|
+
result = ""
|
|
43
|
+
out,err = capture_subprocess_io do
|
|
44
|
+
result=@backend.lookup("bl",{},nil, :priority)
|
|
45
|
+
end
|
|
46
|
+
assert_equal(nil,result)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "lookup of wl should return value" do
|
|
50
|
+
result = ""
|
|
51
|
+
out,err = capture_subprocess_io do
|
|
52
|
+
result=@backend.lookup("wl",{},nil, :priority)
|
|
53
|
+
end
|
|
54
|
+
assert_equal("should_be_allowed",result)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "lookup of black_and_white should not return value" do
|
|
58
|
+
result=""
|
|
59
|
+
out,err = capture_subprocess_io do
|
|
60
|
+
result=@backend.lookup("black_and_white",{},nil, :priority)
|
|
61
|
+
end
|
|
62
|
+
assert_equal(nil,result)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
gem 'minitest'
|
|
3
|
+
#require 'minitest/autorun'
|
|
4
|
+
require 'minitest/spec'
|
|
5
|
+
require 'hiera'
|
|
6
|
+
require 'hiera/backend/wrapper_backend'
|
|
7
|
+
|
|
8
|
+
class Hiera
|
|
9
|
+
module Backend
|
|
10
|
+
describe Wrapper_backend do
|
|
11
|
+
hiera_config=YAML.load_file("test/etc/hiera_empty_bl_empty_wl.yaml")
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
Config.load(hiera_config)
|
|
15
|
+
@new_out,@new_err = capture_subprocess_io do
|
|
16
|
+
@backend=Wrapper_backend.new()
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "Should announce its creation" do
|
|
21
|
+
assert_equal("",@new_out)
|
|
22
|
+
assert_match(/Hiera WRAP backend starting/,@new_err)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it ":priority lookup should fail when not found in either backend" do
|
|
26
|
+
result=""
|
|
27
|
+
out,err = capture_subprocess_io do
|
|
28
|
+
result=@backend.lookup("no_such_key",{},nil, :priority)
|
|
29
|
+
end
|
|
30
|
+
assert_equal(nil,result)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it ":array lookup should fail when not found in either backend" do
|
|
34
|
+
result=""
|
|
35
|
+
out,err = capture_subprocess_io do
|
|
36
|
+
result=@backend.lookup("no_such_key",{},nil, :array)
|
|
37
|
+
end
|
|
38
|
+
assert_equal(nil,result)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it ":hash lookup should fail when not found in either backend" do
|
|
42
|
+
result=""
|
|
43
|
+
out,err = capture_subprocess_io do
|
|
44
|
+
result=@backend.lookup("no_such_key",{},nil, :hash)
|
|
45
|
+
end
|
|
46
|
+
assert_equal(nil,result)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "element lookup should fail when not found in either backend" do
|
|
50
|
+
result=""
|
|
51
|
+
out,err = capture_subprocess_io do
|
|
52
|
+
result=@backend.lookup("no_such_key.element",{},nil, :priority)
|
|
53
|
+
end
|
|
54
|
+
assert_equal(nil,result)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "lookup of json_only should return value from json" do
|
|
58
|
+
result = ""
|
|
59
|
+
out,err = capture_subprocess_io do
|
|
60
|
+
result=@backend.lookup("json_only",{},nil, :priority)
|
|
61
|
+
end
|
|
62
|
+
assert_equal("json_only_value",result)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "lookup of yaml_only should return value from yaml" do
|
|
66
|
+
result = ""
|
|
67
|
+
out,err = capture_subprocess_io do
|
|
68
|
+
result=@backend.lookup("yaml_only",{},nil, :priority)
|
|
69
|
+
end
|
|
70
|
+
assert_equal("yaml_only_value",result)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "lookup of json_and_yaml :priority should return value from json" do
|
|
74
|
+
result = ""
|
|
75
|
+
out,err = capture_subprocess_io do
|
|
76
|
+
result=@backend.lookup("json_and_yaml",{},nil, :priority)
|
|
77
|
+
end
|
|
78
|
+
assert_equal("json_and_yaml_json_value",result)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "lookup of json_and_yaml, :array should return value from both" do
|
|
82
|
+
result = ""
|
|
83
|
+
out,err = capture_subprocess_io do
|
|
84
|
+
result=@backend.lookup("json_and_yaml",{},nil, :array)
|
|
85
|
+
end
|
|
86
|
+
#assert_equal([["json_and_yaml_json_value"], ["json_and_yaml_yaml_value"]],result)
|
|
87
|
+
assert_equal(["json_and_yaml_json_value", "json_and_yaml_yaml_value"],result)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "lookup of json_and_yaml (string), :hash should raise exception" do
|
|
91
|
+
result = ""
|
|
92
|
+
raised=false
|
|
93
|
+
begin
|
|
94
|
+
out,err = capture_subprocess_io do
|
|
95
|
+
result=@backend.lookup("json_and_yaml",{},nil, :hash)
|
|
96
|
+
end
|
|
97
|
+
rescue Exception
|
|
98
|
+
raised=true
|
|
99
|
+
end
|
|
100
|
+
assert_equal(true,raised)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
gem 'minitest'
|
|
3
|
+
#require 'minitest/autorun'
|
|
4
|
+
require 'minitest/spec'
|
|
5
|
+
require 'hiera'
|
|
6
|
+
require 'hiera/backend/wrapper_backend'
|
|
7
|
+
|
|
8
|
+
class Hiera
|
|
9
|
+
module Backend
|
|
10
|
+
describe Wrapper_backend do
|
|
11
|
+
hiera_config=YAML.load_file("test/etc/hiera_nolists.yaml")
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
Config.load(hiera_config)
|
|
15
|
+
@new_out,@new_err = capture_subprocess_io do
|
|
16
|
+
@backend=Wrapper_backend.new()
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "Should announce its creation" do
|
|
21
|
+
assert_equal("",@new_out)
|
|
22
|
+
assert_match(/Hiera WRAP backend starting/,@new_err)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it ":priority lookup should fail when not found in either backend" do
|
|
26
|
+
result=""
|
|
27
|
+
out,err = capture_subprocess_io do
|
|
28
|
+
result=@backend.lookup("no_such_key",{},nil, :priority)
|
|
29
|
+
end
|
|
30
|
+
assert_equal(nil,result)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it ":array lookup should fail when not found in either backend" do
|
|
34
|
+
result=""
|
|
35
|
+
out,err = capture_subprocess_io do
|
|
36
|
+
result=@backend.lookup("no_such_key",{},nil, :array)
|
|
37
|
+
end
|
|
38
|
+
assert_equal(nil,result)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it ":hash lookup should fail when not found in either backend" do
|
|
42
|
+
result=""
|
|
43
|
+
out,err = capture_subprocess_io do
|
|
44
|
+
result=@backend.lookup("no_such_key",{},nil, :hash)
|
|
45
|
+
end
|
|
46
|
+
assert_equal(nil,result)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "element lookup should fail when not found in either backend" do
|
|
50
|
+
result=""
|
|
51
|
+
out,err = capture_subprocess_io do
|
|
52
|
+
result=@backend.lookup("no_such_key.element",{},nil, :priority)
|
|
53
|
+
end
|
|
54
|
+
assert_equal(nil,result)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "lookup of json_only should return value from json" do
|
|
58
|
+
result = ""
|
|
59
|
+
out,err = capture_subprocess_io do
|
|
60
|
+
result=@backend.lookup("json_only",{},nil, :priority)
|
|
61
|
+
end
|
|
62
|
+
assert_equal("json_only_value",result)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "lookup of yaml_only should return value from yaml" do
|
|
66
|
+
result = ""
|
|
67
|
+
out,err = capture_subprocess_io do
|
|
68
|
+
result=@backend.lookup("yaml_only",{},nil, :priority)
|
|
69
|
+
end
|
|
70
|
+
assert_equal("yaml_only_value",result)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "lookup of json_and_yaml :priority should return value from json" do
|
|
74
|
+
result = ""
|
|
75
|
+
out,err = capture_subprocess_io do
|
|
76
|
+
result=@backend.lookup("json_and_yaml",{},nil, :priority)
|
|
77
|
+
end
|
|
78
|
+
assert_equal("json_and_yaml_json_value",result)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "lookup of json_and_yaml, :array should return value from both" do
|
|
82
|
+
result = ""
|
|
83
|
+
out,err = capture_subprocess_io do
|
|
84
|
+
result=@backend.lookup("json_and_yaml",{},nil, :array)
|
|
85
|
+
# lookup(key, scope, order_override, resolution_type, context)
|
|
86
|
+
end
|
|
87
|
+
#assert_equal([["json_and_yaml_json_value"], ["json_and_yaml_yaml_value"]],result)
|
|
88
|
+
assert_equal(["json_and_yaml_json_value", "json_and_yaml_yaml_value"],result)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "lookup of json_and_yaml (string), :hash should raise exception" do
|
|
92
|
+
result = ""
|
|
93
|
+
raised=false
|
|
94
|
+
begin
|
|
95
|
+
out,err = capture_subprocess_io do
|
|
96
|
+
result=@backend.lookup("json_and_yaml",{},nil, :hash)
|
|
97
|
+
end
|
|
98
|
+
rescue Exception
|
|
99
|
+
raised=true
|
|
100
|
+
end
|
|
101
|
+
assert_equal(true,raised)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
data/test/test_one.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hiera-wrapper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Frank Ederveen
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2015-09-04 00:00:00 +01:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: A simple hiera backend wrapper for existing backends, allowing filtering with black and whitelists
|
|
23
|
+
email:
|
|
24
|
+
- frank@crystalconsulting.eu
|
|
25
|
+
executables: []
|
|
26
|
+
|
|
27
|
+
extensions: []
|
|
28
|
+
|
|
29
|
+
extra_rdoc_files: []
|
|
30
|
+
|
|
31
|
+
files:
|
|
32
|
+
- .gitignore
|
|
33
|
+
- Gemfile
|
|
34
|
+
- LICENSE.md
|
|
35
|
+
- README.md
|
|
36
|
+
- Rakefile
|
|
37
|
+
- hiera-wrapper.gemspec
|
|
38
|
+
- hiera.yaml.example
|
|
39
|
+
- lib/hiera/backend/wrapper_backend.rb
|
|
40
|
+
- test/etc/hiera_bl_and_wl.yaml
|
|
41
|
+
- test/etc/hiera_empty_bl_empty_wl.yaml
|
|
42
|
+
- test/etc/hiera_no_bl_no_wl.yaml
|
|
43
|
+
- test/etc/hiera_nolists.yaml
|
|
44
|
+
- test/etc/hieradb/common.json
|
|
45
|
+
- test/etc/hieradb/common.yaml
|
|
46
|
+
- test/test_bl_and_wl.rb
|
|
47
|
+
- test/test_empty_lists.rb
|
|
48
|
+
- test/test_nolists.rb
|
|
49
|
+
- test/test_one.rb
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: https://github.com/senax/hiera-wrapper
|
|
52
|
+
licenses:
|
|
53
|
+
- MIT
|
|
54
|
+
post_install_message:
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
none: false
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
hash: 3
|
|
65
|
+
segments:
|
|
66
|
+
- 0
|
|
67
|
+
version: "0"
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
hash: 3
|
|
74
|
+
segments:
|
|
75
|
+
- 0
|
|
76
|
+
version: "0"
|
|
77
|
+
requirements: []
|
|
78
|
+
|
|
79
|
+
rubyforge_project:
|
|
80
|
+
rubygems_version: 1.3.7
|
|
81
|
+
signing_key:
|
|
82
|
+
specification_version: 3
|
|
83
|
+
summary: Hiera backend wrapper
|
|
84
|
+
test_files:
|
|
85
|
+
- test/etc/hiera_bl_and_wl.yaml
|
|
86
|
+
- test/etc/hiera_empty_bl_empty_wl.yaml
|
|
87
|
+
- test/etc/hiera_no_bl_no_wl.yaml
|
|
88
|
+
- test/etc/hiera_nolists.yaml
|
|
89
|
+
- test/etc/hieradb/common.json
|
|
90
|
+
- test/etc/hieradb/common.yaml
|
|
91
|
+
- test/test_bl_and_wl.rb
|
|
92
|
+
- test/test_empty_lists.rb
|
|
93
|
+
- test/test_nolists.rb
|
|
94
|
+
- test/test_one.rb
|