hiera-yaml-array 1.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +15 -0
- data/lib/hiera/backend/yaml_array_backend.rb +95 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 695e2b0d14801ef5768d17dbb67f9387e8c431aa
|
4
|
+
data.tar.gz: 8a23dbb4f507392839f2f2b70a381bfa9da770b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dea134956c75f9f4fcfc60c985163520a9d886ee06aa658b704d3f9f8db5aa08ff04003ee060c67f6d8f50f0fa36e53fae31512243b02baddbc713ee142072a1
|
7
|
+
data.tar.gz: bb3121b736b96ebb8ce2791b0e1feb1af82a6a9c3e4e014db7eba6605f3db8940844eaa3af84de628dfa050af769ff65f522e6e9aef3cd4e55d4158838dd318d
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Copyright (C) 2016 Reliant Solutions Inc
|
2
|
+
Copyright (C) 2012-2014 Puppet Labs Inc
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
# This file is basically a copy of the hiera Yaml backend, we just override the parse_string method to
|
4
|
+
# achieve our needs.
|
5
|
+
class Hiera
|
6
|
+
module Backend
|
7
|
+
|
8
|
+
class Yaml_array_backend
|
9
|
+
VERSION = '1.0.0'
|
10
|
+
|
11
|
+
def initialize(cache=nil)
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
Hiera.debug('Hiera YAML Array backend starting.')
|
15
|
+
@cache = cache || Filecache.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def lookup(key, scope, order_override, resolution_type, context)
|
19
|
+
answer = nil
|
20
|
+
found = false
|
21
|
+
|
22
|
+
Backend.datasourcefiles(:yaml_array, scope, 'yaml', order_override) do |source, yamlfile|
|
23
|
+
data = @cache.read_file(yamlfile, Hash) do |data|
|
24
|
+
YAML.load(data) || {}
|
25
|
+
end
|
26
|
+
|
27
|
+
next if data.empty?
|
28
|
+
next unless data.include?(key)
|
29
|
+
found = true
|
30
|
+
|
31
|
+
# Extra logging that we found the key. This can be outputted
|
32
|
+
# multiple times if the resolution type is array or hash but that
|
33
|
+
# should be expected as the logging will then tell the user ALL the
|
34
|
+
# places where the key is found.
|
35
|
+
Hiera.debug("Found #{key} in #{source}")
|
36
|
+
|
37
|
+
# for array resolution we just append to the array whatever
|
38
|
+
# we find, we then goes onto the next file and keep adding to
|
39
|
+
# the array
|
40
|
+
#
|
41
|
+
# for priority searches we break after the first found data item
|
42
|
+
new_answer = parse_answer(data[key], scope, {}, context)
|
43
|
+
case resolution_type.is_a?(Hash) ? :hash : resolution_type
|
44
|
+
when :array
|
45
|
+
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
|
46
|
+
answer ||= []
|
47
|
+
answer << new_answer
|
48
|
+
when :hash
|
49
|
+
raise Exception, "Hiera type mismatch for key '#{key}': expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
50
|
+
answer ||= {}
|
51
|
+
answer = Backend.merge_answer(new_answer, answer, resolution_type)
|
52
|
+
else
|
53
|
+
answer = new_answer
|
54
|
+
break
|
55
|
+
end
|
56
|
+
end
|
57
|
+
throw :no_such_key unless found
|
58
|
+
puts answer.inspect
|
59
|
+
answer
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def parse_answer(data, scope, extra_data, context)
|
65
|
+
if data.is_a?(Numeric) or data.is_a?(TrueClass) or data.is_a?(FalseClass)
|
66
|
+
return data
|
67
|
+
elsif data.is_a?(String)
|
68
|
+
return parse_string(data, scope, extra_data, context)
|
69
|
+
elsif data.is_a?(Hash)
|
70
|
+
answer = {}
|
71
|
+
data.each_pair do |key, val|
|
72
|
+
interpolated_key = parse_string(key, scope, extra_data, context)
|
73
|
+
answer[interpolated_key] = parse_answer(val, scope, extra_data, context)
|
74
|
+
end
|
75
|
+
elsif data.is_a?(Array)
|
76
|
+
answer = []
|
77
|
+
data.each do |item|
|
78
|
+
answer << parse_answer(item, scope, extra_data, context)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
answer
|
82
|
+
end
|
83
|
+
|
84
|
+
# The backend code is just these lines bellow, have fun.
|
85
|
+
SINGLE_VARIABLE_REGEXP = /\A%\{([^\[\]]+)\}\z/
|
86
|
+
SEEMS_A_ARRAY = /\A\[.+\]\z/
|
87
|
+
|
88
|
+
def parse_string(data, scope, extra_data, context)
|
89
|
+
value = Hiera::Interpolate.interpolate(data, scope, extra_data, context)
|
90
|
+
value = JSON.parse(value) if data =~ SINGLE_VARIABLE_REGEXP && value =~ SEEMS_A_ARRAY
|
91
|
+
value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-yaml-array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Reliant Security, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hiera
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awesome_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
description: Fork of Yaml hiera backend with support for array interpolations.
|
56
|
+
email: dev@reliantsecurity.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- LICENSE
|
62
|
+
- lib/hiera/backend/yaml_array_backend.rb
|
63
|
+
homepage: https://github.com/reliantsolutions/hiera-yaml-array
|
64
|
+
licenses:
|
65
|
+
- Apache-2.0
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.8
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Yaml hiera backend with support for array interpolations.
|
87
|
+
test_files: []
|