hiera-fragment 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7939bc1e4e12103550e438dcef1de4971dea9fea
4
+ data.tar.gz: 35132f56661ab3c95f5301bdb9eee55410957769
5
+ SHA512:
6
+ metadata.gz: f986dbb49e55a3406eab186840bd52e0e5b5e27019365d78e1b11038131dcf1fd53a785de9b96e5892dc02d7c0baa79c3c9e3045b6cad8b5808e9401c676165a
7
+ data.tar.gz: 3501461d4b1d09f866009a9e11ba92902b6b3e4fa942c4c47674a9b3d93b7eef5088c09036f5667174e99dbab8cd7af70dd6ca0c89744c6cfbb1c0ef7d9b9614
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require "autotest/bundler"
data/.editorconfig ADDED
@@ -0,0 +1,11 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
24
+ test/output
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hiera-fragment.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+
179
+ Copyright 2015 Adaptavist.com Ltd.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Hiera::Fragment
2
+
3
+ The hiera-fragment gem uses a custom algorithm to merge YAML files together to produce output for Hiera. It is intended to allow
4
+ secrets to be specified in separate files (eyaml supported). It also supports replacement of fragments of YAML which
5
+ should result in a reduction of size of the configuration for Hiera
6
+
7
+ ## Installation
8
+
9
+ Install:
10
+
11
+ $ gem install hiera-fragment
12
+
13
+ ## Usage
14
+
15
+ `fragment` should be added as a backend to Hiera. A top-level `:fragment` key is used to configure hiera-fragment
16
+
17
+ * `:datadir` Array of paths or single path to the fragments.
18
+ * `:extensions` Array of extensions to search for.
19
+ * `:inputdirs` Array of paths or single path to the source files.
20
+ * `:fragments` Array of fragments, specified in the same way as `:hierarchy`
21
+ * `:destdir` Directory to ouput modified files to. Defaults to `:yaml[:datadir]`
22
+
23
+ Only YAML (and eyaml) is currently supported
24
+
25
+ Example `hiera.yaml` file
26
+
27
+ ---
28
+ :backends:
29
+ - fragment
30
+ - yaml
31
+
32
+ :hierarchy:
33
+ - source
34
+
35
+ :yaml:
36
+ :datadir: ./test/output
37
+
38
+ :logger: console
39
+
40
+ :fragment:
41
+ :datadir: ./test/fragment
42
+ :extensions:
43
+ - yaml
44
+ - eyaml
45
+ :inputdirs:
46
+ - ./test/input
47
+ :fragments:
48
+ - source
49
+ - foo
50
+
51
+
52
+ Source file:
53
+
54
+ ---
55
+ key: 'value'
56
+
57
+ Fragment file
58
+
59
+ ---
60
+ key: 'replaced value'
61
+
62
+ `hiera -c hiera.yaml key` will output 'replaced value'
63
+
64
+ ## License
65
+
66
+ avst-wizard is released under the terms of the Apache 2.0 license. See LICENSE.txt
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/adaptavist/hiera-fragment/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = "--tag ~standalone --tag standard"
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:spec_standalone) do |t|
11
+ t.rspec_opts = "--tag standalone --tag ~standard"
12
+ end
13
+
14
+ task :default => :spec
15
+ rescue LoadError
16
+ # no rspec available
17
+ end
18
+
19
+ begin
20
+ require 'ruby-lint/rake_task'
21
+
22
+ RubyLint::RakeTask.new do |task|
23
+ task.name = 'lint'
24
+ task.files = Dir.glob('lib/**/*.rb')
25
+ end
26
+ rescue LoadError
27
+ # no ruby-lint available
28
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'hiera-fragment'
7
+ spec.version = '0.0.6'
8
+ spec.authors = ['Jon Mort']
9
+ spec.email = ['jmort@adaptavist.com']
10
+ spec.summary = %q{Merges YAML fragments into YAML documents}
11
+ spec.description = %q{Takes YAML fragments and merges them into a larger document as par of a Hiera pre-process phase}
12
+ spec.homepage = ''
13
+ spec.license = 'Apache-2.0'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'ruby-lint'
23
+ spec.add_development_dependency 'rspec-autotest'
24
+ spec.add_dependency 'hiera'
25
+ end
@@ -0,0 +1,136 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'fileutils'
16
+ require 'yaml'
17
+ require 'set'
18
+ require 'pathname'
19
+
20
+ class Hiera
21
+ module Backend
22
+ class Fragment_backend
23
+ def initialize
24
+ Fragment_backend::debug 'Hiera fragment backend starting'
25
+ end
26
+
27
+ def lookup(key, scope, order_override, resolution_type)
28
+ answer = nil
29
+ case resolution_type
30
+ when :array
31
+ answer = []
32
+ when :hash
33
+ answer = {}
34
+ end
35
+ answer
36
+ end
37
+
38
+ SUPPORTED_EXTENSIONS = %w{yaml eyaml}
39
+
40
+ def self.process_files
41
+ conf = Config[:fragment]
42
+ data_dir = conf[:datadir]
43
+ # restrict to yaml extensions only
44
+
45
+ if conf[:extensions] and not conf[:extensions].to_set.subset? SUPPORTED_EXTENSIONS.to_set
46
+ raise "Unsupported extensions #{conf[:extensions]}. Only #{SUPPORTED_EXTENSIONS} are supported"
47
+ end
48
+
49
+ extensions = [conf[:extensions] || SUPPORTED_EXTENSIONS].flatten.join(',')
50
+
51
+ fragments = [conf[:fragments]].flatten.map do |fragment|
52
+ path_join_glob(data_dir, "#{fragment}.{#{extensions}}")
53
+ end.flatten.select do |file|
54
+ File.file? file
55
+ end
56
+
57
+ if fragments.empty?
58
+ warn "No fragments found in #{data_dir}"
59
+ end
60
+
61
+ dest_dir = conf[:destdir] || Config[:yaml][:datadir]
62
+
63
+ input_dirs = [conf[:inputdirs]].flatten.map { |file| Pathname.new(file).realpath.to_s }
64
+
65
+ debug "Cleaning output dir: #{dest_dir}"
66
+ FileUtils.rm_rf dest_dir
67
+ FileUtils.mkdir_p dest_dir
68
+
69
+ glob_pattern = "**/*.{#{extensions}}"
70
+ debug "Using fragments #{fragments.join(',')}"
71
+ merge_input(fragments, glob_pattern, input_dirs) do |yaml_file, input_dir, yaml|
72
+ output_file = Pathname.new(yaml_file).realpath.to_s.sub(input_dir, dest_dir)
73
+ debug "Writing to #{output_file}"
74
+
75
+ FileUtils.mkdir_p File.dirname(output_file)
76
+ File.open(output_file, 'w+') { |file| YAML.dump(yaml, file) }
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def self.debug(message)
83
+ Hiera.debug("[fragment_backend]: #{message}")
84
+ end
85
+
86
+ def self.warn(message)
87
+ Hiera.warn("[fragment_backend]: #{message}")
88
+ end
89
+
90
+ def self.path_join_glob(dir, file_pattern)
91
+ Dir.glob(File.join(dir, file_pattern))
92
+ end
93
+
94
+ def self.merge_input(fragments, glob_pattern, input_dirs, &f)
95
+ input_dirs.each do |input_dir|
96
+ debug "Searching for files in #{input_dir} using pattern #{glob_pattern}"
97
+ path_join_glob(input_dir, glob_pattern).each do |yaml_file|
98
+ debug "Processing #{yaml_file}"
99
+
100
+ yaml = merge_files(yaml_file, fragments)
101
+ f.call(yaml_file, input_dir, yaml)
102
+ end
103
+ end
104
+ end
105
+
106
+ def self.replace_values(target, source)
107
+ if source.nil? or target.nil? or not source.is_a?(Hash) or not target.is_a?(Hash)
108
+ return
109
+ end
110
+ keys = source.keys.to_set
111
+ target.select {|key,value| keys.include? key}.each do |key, val|
112
+ if val.is_a?(Hash) and not val.empty?
113
+ replace_values val, source[key]
114
+ else
115
+ target[key] = source[key]
116
+ end
117
+ end
118
+ end
119
+
120
+ def self.merge_files(base, overrides = [])
121
+ result = YAML.load_file(base)
122
+ if result.nil? or not result.is_a?(Hash)
123
+ return
124
+ end
125
+ keys = result.keys.to_set
126
+ [overrides].flatten.select {|file| File.readable? file}.each do |override_file|
127
+ override = YAML.load_file(override_file)
128
+ replace_values result, override
129
+ end
130
+ result
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ Hiera::Backend::Fragment_backend.process_files
@@ -0,0 +1,28 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'hiera'
16
+ require 'rspec'
17
+
18
+ RSpec.describe Hiera do
19
+ describe '#no-data-dir', :standalone => true do
20
+ context 'with no data dir' do
21
+ it 'no replacement made' do
22
+ hiera = Hiera.new(:config => 'test/hiera-nodatadir.yaml')
23
+ value = hiera.lookup('str', nil, [])
24
+ expect(value).to eq('one')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'hiera'
16
+ require 'rspec'
17
+
18
+ RSpec.describe Hiera do
19
+ describe '#fragment', :standard => true do
20
+ context 'with default config' do
21
+ it 'has replaced single value' do
22
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
23
+ value = hiera.lookup('str', nil, [])
24
+ expect(value).to eq('a replaced value')
25
+ end
26
+ it 'has replaced a whole hash' do
27
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
28
+ value = hiera.lookup('test', nil, [])
29
+ expect(value).to eq({'foo' => 'bar', 'baz' => 'asd'})
30
+ end
31
+ it 'has replaced a partial hash' do
32
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
33
+ value = hiera.lookup('partial', nil, [])
34
+ expect(value['key']).to eq('a replaced value')
35
+ end
36
+ it 'has replaced a nested value' do
37
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
38
+ value = hiera.lookup('nested', nil, [])
39
+ expect(value['level1']['level2']).to eq('a replaced value')
40
+ end
41
+ it 'hash lookup still works' do
42
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
43
+ value = hiera.lookup('hash', nil, [], nil, :hash)
44
+ expect(value['key']).to eq('value')
45
+ end
46
+
47
+ it 'array lookup still works' do
48
+ hiera = Hiera.new(:config => 'test/hiera.yaml')
49
+ value = hiera.lookup('array', nil, [], nil, :array)
50
+ expect(value).to eq(['one', 'two'])
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,90 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ config.filter_run_excluding :standalone => true
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # The settings below are suggested to provide a good initial experience
43
+ # with RSpec, but feel free to customize to your heart's content.
44
+ =begin
45
+ # These two settings work together to allow you to limit a spec run
46
+ # to individual examples or groups you care about by tagging them with
47
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
+ # get run.
49
+ config.filter_run :focus
50
+ config.run_all_when_everything_filtered = true
51
+
52
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
53
+ # For more details, see:
54
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
55
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
57
+ config.disable_monkey_patching!
58
+
59
+ # This setting enables warnings. It's recommended, but in some cases may
60
+ # be too noisy due to issues in dependencies.
61
+ config.warnings = true
62
+
63
+ # Many RSpec users commonly either run the entire suite or an individual
64
+ # file, and it's useful to allow more verbose output when running an
65
+ # individual spec file.
66
+ if config.files_to_run.one?
67
+ # Use the documentation formatter for detailed output,
68
+ # unless a formatter has already been configured
69
+ # (e.g. via a command-line flag).
70
+ config.default_formatter = 'doc'
71
+ end
72
+
73
+ # Print the 10 slowest examples and example groups at the
74
+ # end of the spec run, to help surface which specs are running
75
+ # particularly slow.
76
+ config.profile_examples = 10
77
+
78
+ # Run specs in random order to surface order dependencies. If you find an
79
+ # order dependency and want to debug it, you can fix the order by providing
80
+ # the seed, which is printed after each run.
81
+ # --seed 1234
82
+ config.order = :random
83
+
84
+ # Seed global randomization in this process using the `--seed` CLI option.
85
+ # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # test failures related to randomization by passing the same `--seed` value
87
+ # as the one that triggered the failure.
88
+ Kernel.srand config.seed
89
+ =end
90
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+
@@ -0,0 +1,8 @@
1
+ ---
2
+
3
+ one:
4
+ two: 'one'
5
+ three:
6
+ foo: 'bar'
7
+ four:
8
+ - 5
@@ -0,0 +1,25 @@
1
+ ---
2
+
3
+ one:
4
+ two: 'one'
5
+ three:
6
+ foo: 'bar'
7
+ four:
8
+ - 3:
9
+ foo: 'bar'
10
+ - 4
11
+
12
+ test:
13
+ foo: 'bar'
14
+ baz: 'asd'
15
+
16
+
17
+ str: 'a replaced value'
18
+
19
+ partial:
20
+ key: 'a replaced value'
21
+
22
+
23
+ nested:
24
+ level1:
25
+ level2: 'a replaced value'
@@ -0,0 +1,24 @@
1
+ ---
2
+ :backends:
3
+ - fragment
4
+ - yaml
5
+
6
+ :hierarchy:
7
+ - source
8
+ - empty
9
+
10
+ :yaml:
11
+ :datadir: ./test/output
12
+
13
+ :logger: console
14
+
15
+ :fragment:
16
+ :datadir: ./test/fragment-doesnt-exist
17
+ :extensions:
18
+ - yaml
19
+ - eyaml
20
+ :inputdirs:
21
+ - ./test/input
22
+ :fragments:
23
+ - source
24
+ - empty
data/test/hiera.yaml ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ :backends:
3
+ - fragment
4
+ - yaml
5
+
6
+ :hierarchy:
7
+ - source
8
+ - empty
9
+
10
+ :yaml:
11
+ :datadir: ./test/output
12
+
13
+ :logger: console
14
+
15
+ :fragment:
16
+ :datadir: ./test/fragment
17
+ :extensions:
18
+ - yaml
19
+ - eyaml
20
+ :inputdirs:
21
+ - ./test/input
22
+ :fragments:
23
+ - source
24
+ - empty
@@ -0,0 +1 @@
1
+ ---
@@ -0,0 +1,29 @@
1
+ ---
2
+
3
+ one:
4
+ two: 'two'
5
+ three: 'three'
6
+ four:
7
+ - 1
8
+ - 2
9
+ - 3:
10
+ foo: 'baz'
11
+
12
+ test: {}
13
+
14
+
15
+ str: 'one'
16
+
17
+ partial:
18
+ key: 'value'
19
+
20
+ hash:
21
+ key: 'value'
22
+
23
+ array:
24
+ - one
25
+ - two
26
+
27
+ nested:
28
+ level1:
29
+ level2: 'value'
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-fragment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Jon Mort
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-lint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-autotest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hiera
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Takes YAML fragments and merges them into a larger document as par of
84
+ a Hiera pre-process phase
85
+ email:
86
+ - jmort@adaptavist.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".autotest"
92
+ - ".editorconfig"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - hiera-preprocess.gemspec
100
+ - lib/hiera/backend/fragment_backend.rb
101
+ - spec/integration/hiera_noinput_spec.rb
102
+ - spec/integration/hiera_spec.rb
103
+ - spec/spec_helper.rb
104
+ - test/fragment/empty.yaml
105
+ - test/fragment/source.eyaml
106
+ - test/fragment/source.yaml
107
+ - test/hiera-nodatadir.yaml
108
+ - test/hiera.yaml
109
+ - test/input/empty.yaml
110
+ - test/input/source.yaml
111
+ homepage: ''
112
+ licenses:
113
+ - Apache-2.0
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.2.0
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Merges YAML fragments into YAML documents
135
+ test_files:
136
+ - spec/integration/hiera_noinput_spec.rb
137
+ - spec/integration/hiera_spec.rb
138
+ - spec/spec_helper.rb
139
+ - test/fragment/empty.yaml
140
+ - test/fragment/source.eyaml
141
+ - test/fragment/source.yaml
142
+ - test/hiera-nodatadir.yaml
143
+ - test/hiera.yaml
144
+ - test/input/empty.yaml
145
+ - test/input/source.yaml