hieracles 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/hieracles/formats/console.rb +19 -6
- data/lib/hieracles/formats/csv.rb +9 -2
- data/lib/hieracles/formats/plain.rb +7 -2
- data/lib/hieracles/formats/yaml.rb +8 -1
- data/lib/hieracles/node.rb +23 -2
- data/spec/files/params/farm/dev.yaml +2 -0
- data/spec/lib/formats/console_spec.rb +3 -3
- data/spec/lib/formats/csv_spec.rb +42 -18
- data/spec/lib/formats/plain_spec.rb +3 -3
- data/spec/lib/formats/yaml_spec.rb +53 -0
- data/spec/lib/node_spec.rb +67 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b98d278d79f3de929cb583ab33e77f895f4676
|
4
|
+
data.tar.gz: 888be4768415d47ecef87847114b290e0a813d07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 842f1c0ed05b9c4b11663b04bdab2c09f34a9713a732a6e76fcf75e171cbf12fed644e72f9d8aca820466d6afe7b4b35ede87df59e4d5b8a79759723a0360b49
|
7
|
+
data.tar.gz: c0fa911cc8b01be9eaa6f1d1fb419ebf020721abb865210c4f7a0ac79061a43a03b1a45035ec061b6cb6e2412b0d1756cc2dcd86227385347f6a20e7515d3184
|
data/CHANGELOG.md
CHANGED
@@ -41,7 +41,7 @@ module Hieracles
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def build_head(without_common)
|
44
|
-
output =
|
44
|
+
output = "[-] (merged)\n"
|
45
45
|
@node.files(without_common).each_with_index do |f, i|
|
46
46
|
output << format("#{COLORS[i]}\n", "[#{i}] #{f}")
|
47
47
|
@colors[f] = i
|
@@ -55,11 +55,24 @@ module Hieracles
|
|
55
55
|
first = value.pop
|
56
56
|
filecolor_index = @colors[first[:file]]
|
57
57
|
filecolor = COLORS[filecolor_index]
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
if first[:merged] != first[:value]
|
59
|
+
output << format("%s #{COLORS[5]} %s\n",
|
60
|
+
"[-]",
|
61
|
+
key,
|
62
|
+
first[:merged].to_s.gsub('%', '%%')
|
63
|
+
)
|
64
|
+
output << format(" #{COLORS[8]} #{COLORS[8]} #{COLORS[8]}\n",
|
65
|
+
"[#{filecolor_index}]",
|
66
|
+
key,
|
67
|
+
first[:value].to_s.gsub('%', '%%')
|
68
|
+
)
|
69
|
+
else
|
70
|
+
output << format("#{filecolor} #{COLORS[5]} %s\n",
|
71
|
+
"[#{filecolor_index}]",
|
72
|
+
key,
|
73
|
+
first[:value].to_s.gsub('%', '%%')
|
74
|
+
)
|
75
|
+
end
|
63
76
|
while value.count > 0
|
64
77
|
overriden = value.pop
|
65
78
|
filecolor_index = @colors[overriden[:file]]
|
@@ -29,8 +29,15 @@ module Hieracles
|
|
29
29
|
output = ''
|
30
30
|
if !filter || Regexp.new(filter).match(key)
|
31
31
|
first = value.pop
|
32
|
-
|
33
|
-
|
32
|
+
if first[:value] == first[:merged]
|
33
|
+
output << make_csv(in_what_file(first[:file]) +
|
34
|
+
[key, first[:value].to_s, '0'])
|
35
|
+
else
|
36
|
+
output << make_csv(in_what_file('-') +
|
37
|
+
[key, first[:merged].to_s, '0'])
|
38
|
+
output << make_csv(in_what_file(first[:file]) +
|
39
|
+
[key, first[:value].to_s, '1'])
|
40
|
+
end
|
34
41
|
while value.count > 0
|
35
42
|
overriden = value.pop
|
36
43
|
output << make_csv(in_what_file(overriden[:file]) +
|
@@ -28,7 +28,7 @@ module Hieracles
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def build_head(without_common)
|
31
|
-
output =
|
31
|
+
output = "[-] (merged)\n"
|
32
32
|
@node.files(without_common).each_with_index do |f, i|
|
33
33
|
output << "[#{i}] #{f}\n"
|
34
34
|
@index[f] = i
|
@@ -41,7 +41,12 @@ module Hieracles
|
|
41
41
|
if !filter || Regexp.new(filter).match(key)
|
42
42
|
first = value.pop
|
43
43
|
filecolor_index = @index[first[:file]]
|
44
|
-
|
44
|
+
if first[:merged] != first[:value]
|
45
|
+
output << "[-] #{key} #{first[:merged]}\n"
|
46
|
+
output << " [#{filecolor_index}] #{key} #{first[:value]}\n"
|
47
|
+
else
|
48
|
+
output << "[#{filecolor_index}] #{key} #{first[:value]}\n"
|
49
|
+
end
|
45
50
|
while value.count > 0
|
46
51
|
overriden = value.pop
|
47
52
|
filecolor_index = @index[overriden[:file]]
|
@@ -57,7 +57,14 @@ module Hieracles
|
|
57
57
|
aryaml = yaml.each_line.map do |l|
|
58
58
|
indent + l
|
59
59
|
end
|
60
|
-
|
60
|
+
if @node.hiera.merge_behavior == :deep ||
|
61
|
+
@node.hiera.merge_behavior == :deeper
|
62
|
+
params[key.join('.')].each do |f|
|
63
|
+
output += "\n" + indent + "# " + f[:file]
|
64
|
+
end
|
65
|
+
else
|
66
|
+
output += "\n" + indent + "# " + params[key.join('.')].last[:file]
|
67
|
+
end
|
61
68
|
output += "\n" + aryaml.join().chomp
|
62
69
|
output
|
63
70
|
end
|
data/lib/hieracles/node.rb
CHANGED
@@ -55,7 +55,7 @@ module Hieracles
|
|
55
55
|
s.each do |k,v|
|
56
56
|
params[k] ||= []
|
57
57
|
# f needs interpolation
|
58
|
-
params[k] << { value: v, file: f}
|
58
|
+
params[k] << { value: v, file: f, merged: merge_value(params[k], v) }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -120,10 +120,31 @@ module Hieracles
|
|
120
120
|
left.deep_merge!(right)
|
121
121
|
when :deep
|
122
122
|
left.deep_merge(right)
|
123
|
-
else
|
123
|
+
else
|
124
124
|
local_merge!(left, right)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
def merge_value(previous, value)
|
129
|
+
if value.is_a? Array
|
130
|
+
if previous == []
|
131
|
+
deep_sort(value)
|
132
|
+
else
|
133
|
+
left = previous.last[:merged]
|
134
|
+
case @hiera.merge_behavior
|
135
|
+
# TODO: handle the case where right is not an array
|
136
|
+
when :deeper
|
137
|
+
deep_sort(left | value)
|
138
|
+
when :deep
|
139
|
+
deep_sort(left | value)
|
140
|
+
else
|
141
|
+
deep_sort(value)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
else
|
145
|
+
value
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
128
149
|
end
|
129
150
|
end
|
@@ -43,7 +43,7 @@ describe Hieracles::Formats::Console do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe ".build_head" do
|
46
|
-
let(:expected) { "\e[31m[0] path1\e[0m\n\e[32m[1] path2\e[0m\n\n" }
|
46
|
+
let(:expected) { "[-] (merged)\n\e[31m[0] path1\e[0m\n\e[32m[1] path2\e[0m\n\n" }
|
47
47
|
before {
|
48
48
|
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
49
49
|
}
|
@@ -59,8 +59,8 @@ describe Hieracles::Formats::Console do
|
|
59
59
|
}
|
60
60
|
let(:params) {
|
61
61
|
[
|
62
|
-
{ file: 'path1', value: 'value1'},
|
63
|
-
{ file: 'path2', value: 'value2'},
|
62
|
+
{ file: 'path1', value: 'value1', merged: 'value1'},
|
63
|
+
{ file: 'path2', value: 'value2', merged: 'value2'},
|
64
64
|
]
|
65
65
|
}
|
66
66
|
before {
|
@@ -50,24 +50,48 @@ describe Hieracles::Formats::Csv do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe ".build_params_line" do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
53
|
+
context "with array values" do
|
54
|
+
let(:expected) {
|
55
|
+
"0;0;params.this.var;[\"value1\", \"value2\"];0\n"+
|
56
|
+
"0;1;params.this.var;[\"value2\"];1\n"+
|
57
|
+
"1;0;params.this.var;[\"value1\"];1\n"
|
58
|
+
}
|
59
|
+
let(:params) {
|
60
|
+
[
|
61
|
+
{ file: 'path1', value: ['value1'], merged: ['value1'] },
|
62
|
+
{ file: 'path2', value: ['value2'], merged: ['value1','value2'] },
|
63
|
+
]
|
64
|
+
}
|
65
|
+
before {
|
66
|
+
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
67
|
+
}
|
68
|
+
it "outputs proper text" do
|
69
|
+
expect(csv_format.send :build_params_line,
|
70
|
+
"params.this.var",
|
71
|
+
params,
|
72
|
+
nil).to eq expected
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context "with non-array values" do
|
76
|
+
let(:expected) {
|
77
|
+
"0;1;params.this.var;value2;0\n"+
|
78
|
+
"1;0;params.this.var;value1;1\n"
|
79
|
+
}
|
80
|
+
let(:params) {
|
81
|
+
[
|
82
|
+
{ file: 'path1', value: 'value1', merged: 'value1' },
|
83
|
+
{ file: 'path2', value: 'value2', merged: 'value2' },
|
84
|
+
]
|
85
|
+
}
|
86
|
+
before {
|
87
|
+
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
88
|
+
}
|
89
|
+
it "outputs proper text" do
|
90
|
+
expect(csv_format.send :build_params_line,
|
91
|
+
"params.this.var",
|
92
|
+
params,
|
93
|
+
nil).to eq expected
|
94
|
+
end
|
71
95
|
end
|
72
96
|
end
|
73
97
|
|
@@ -43,7 +43,7 @@ describe Hieracles::Formats::Plain do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe ".build_head" do
|
46
|
-
let(:expected) { "[0] path1\n[1] path2\n\n" }
|
46
|
+
let(:expected) { "[-] (merged)\n[0] path1\n[1] path2\n\n" }
|
47
47
|
before {
|
48
48
|
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
49
49
|
}
|
@@ -59,8 +59,8 @@ describe Hieracles::Formats::Plain do
|
|
59
59
|
}
|
60
60
|
let(:params) {
|
61
61
|
[
|
62
|
-
{ file: 'path1', value: 'value1'},
|
63
|
-
{ file: 'path2', value: 'value2'},
|
62
|
+
{ file: 'path1', value: 'value1', merged: 'value1'},
|
63
|
+
{ file: 'path2', value: 'value2', merged: 'value2'},
|
64
64
|
]
|
65
65
|
}
|
66
66
|
before {
|
@@ -205,8 +205,61 @@ describe Hieracles::Formats::Yaml do
|
|
205
205
|
let(:expected) {
|
206
206
|
"\nkey: \n # what/file\n - value1\n - value2"
|
207
207
|
}
|
208
|
+
let(:hiera) { Struct.new( :merge_behavior ) }
|
209
|
+
before {
|
210
|
+
allow(node).to receive(:hiera).and_return(
|
211
|
+
hiera.new('deeper')
|
212
|
+
)
|
213
|
+
}
|
208
214
|
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
|
209
215
|
end
|
216
|
+
context "with a double array key-value" do
|
217
|
+
let(:params) {
|
218
|
+
{
|
219
|
+
'key' => [
|
220
|
+
{
|
221
|
+
file: 'what/file',
|
222
|
+
value: ['value1', 'value2'],
|
223
|
+
merged: ['value1', 'value2']
|
224
|
+
},
|
225
|
+
{
|
226
|
+
file: 'what/other-file',
|
227
|
+
value: ['value3'],
|
228
|
+
merged: ['value1', 'value2', 'value3']
|
229
|
+
}
|
230
|
+
]
|
231
|
+
}
|
232
|
+
}
|
233
|
+
let(:hiera) { Struct.new( :merge_behavior ) }
|
234
|
+
context "with native merge behavior" do
|
235
|
+
let(:input) {
|
236
|
+
{ 'key' => ['value3'] }
|
237
|
+
}
|
238
|
+
let(:expected) {
|
239
|
+
"\nkey: \n # what/other-file\n - value3"
|
240
|
+
}
|
241
|
+
before {
|
242
|
+
allow(node).to receive(:hiera).and_return(
|
243
|
+
hiera.new(:native)
|
244
|
+
)
|
245
|
+
}
|
246
|
+
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
|
247
|
+
end
|
248
|
+
context "with deep merge behavior" do
|
249
|
+
let(:input) {
|
250
|
+
{ 'key' => ['value1', 'value2', 'value3'] }
|
251
|
+
}
|
252
|
+
let(:expected) {
|
253
|
+
"\nkey: \n # what/file\n # what/other-file\n - value1\n - value2\n - value3"
|
254
|
+
}
|
255
|
+
before {
|
256
|
+
allow(node).to receive(:hiera).and_return(
|
257
|
+
hiera.new(:deep)
|
258
|
+
)
|
259
|
+
}
|
260
|
+
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
|
261
|
+
end
|
262
|
+
end
|
210
263
|
context "with a 2-levels string key-value" do
|
211
264
|
let(:params) {
|
212
265
|
{
|
data/spec/lib/node_spec.rb
CHANGED
@@ -81,37 +81,50 @@ describe Hieracles::Node do
|
|
81
81
|
[ "another.more_sublevel",
|
82
82
|
[{
|
83
83
|
value: "something",
|
84
|
-
file: 'params/farm/dev.yaml'
|
84
|
+
file: 'params/farm/dev.yaml',
|
85
|
+
merged: 'something'
|
85
86
|
}]
|
86
87
|
],
|
87
88
|
[ "another.sublevel.array",
|
88
89
|
[
|
89
90
|
{
|
90
91
|
value: ["one", "two", "three"],
|
91
|
-
file: 'params/farm/dev.yaml'
|
92
|
+
file: 'params/farm/dev.yaml',
|
93
|
+
merged: ["one", "three", "two"]
|
92
94
|
},
|
93
95
|
{
|
94
96
|
value: ["four", "five"],
|
95
|
-
file: 'params/nodes/server.example.com.yaml'
|
97
|
+
file: 'params/nodes/server.example.com.yaml',
|
98
|
+
merged: ["five", "four"]
|
96
99
|
}
|
97
100
|
]
|
98
101
|
],
|
99
102
|
[ "another.sublevel.thing",
|
100
103
|
[{
|
101
104
|
value: "always",
|
102
|
-
file: 'params/nodes/server.example.com.yaml'
|
105
|
+
file: 'params/nodes/server.example.com.yaml',
|
106
|
+
merged: "always"
|
103
107
|
}]
|
104
108
|
],
|
105
109
|
[ "common_param.subparam",
|
106
|
-
[
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
+
[
|
111
|
+
{
|
112
|
+
value: "override-me",
|
113
|
+
file: 'params/farm/dev.yaml',
|
114
|
+
merged: "override-me"
|
115
|
+
},
|
116
|
+
{
|
117
|
+
value: "overriden",
|
118
|
+
file: 'params/nodes/server.example.com.yaml',
|
119
|
+
merged: "overriden"
|
120
|
+
}
|
121
|
+
]
|
110
122
|
],
|
111
123
|
[ "somefarmparam",
|
112
124
|
[{
|
113
125
|
value: false,
|
114
|
-
file: 'params/farm/dev.yaml'
|
126
|
+
file: 'params/farm/dev.yaml',
|
127
|
+
merged: false
|
115
128
|
}]
|
116
129
|
]
|
117
130
|
]
|
@@ -233,37 +246,50 @@ describe Hieracles::Node do
|
|
233
246
|
[ "another.more_sublevel",
|
234
247
|
[{
|
235
248
|
value: "something",
|
236
|
-
file: 'params/farm/dev.yaml'
|
249
|
+
file: 'params/farm/dev.yaml',
|
250
|
+
merged: "something"
|
237
251
|
}]
|
238
252
|
],
|
239
253
|
[ "another.sublevel.array",
|
240
254
|
[
|
241
255
|
{
|
242
256
|
value: ["one", "two", "three"],
|
243
|
-
file: 'params/farm/dev.yaml'
|
257
|
+
file: 'params/farm/dev.yaml',
|
258
|
+
merged: ["one", "three", "two"]
|
244
259
|
},
|
245
260
|
{
|
246
261
|
value: ["four", "five"],
|
247
|
-
file: 'params/nodes/server.example.com.yaml'
|
262
|
+
file: 'params/nodes/server.example.com.yaml',
|
263
|
+
merged: ["five", "four", "one", "three", "two"]
|
248
264
|
}
|
249
265
|
]
|
250
266
|
],
|
251
267
|
[ "another.sublevel.thing",
|
252
268
|
[{
|
253
269
|
value: "always",
|
254
|
-
file: 'params/nodes/server.example.com.yaml'
|
270
|
+
file: 'params/nodes/server.example.com.yaml',
|
271
|
+
merged: "always"
|
255
272
|
}]
|
256
273
|
],
|
257
274
|
[ "common_param.subparam",
|
258
|
-
[
|
259
|
-
|
260
|
-
|
261
|
-
|
275
|
+
[
|
276
|
+
{
|
277
|
+
value: "override-me",
|
278
|
+
file: 'params/farm/dev.yaml',
|
279
|
+
merged: "override-me"
|
280
|
+
},
|
281
|
+
{
|
282
|
+
value: "overriden",
|
283
|
+
file: 'params/nodes/server.example.com.yaml',
|
284
|
+
merged: "overriden"
|
285
|
+
}
|
286
|
+
]
|
262
287
|
],
|
263
288
|
[ "somefarmparam",
|
264
289
|
[{
|
265
290
|
value: false,
|
266
|
-
file: 'params/farm/dev.yaml'
|
291
|
+
file: 'params/farm/dev.yaml',
|
292
|
+
merged: false
|
267
293
|
}]
|
268
294
|
]
|
269
295
|
]
|
@@ -282,7 +308,7 @@ describe Hieracles::Node do
|
|
282
308
|
}
|
283
309
|
},
|
284
310
|
"common_param" => {
|
285
|
-
"subparam" => "
|
311
|
+
"subparam" => "override-me"
|
286
312
|
},
|
287
313
|
"somefarmparam" => false
|
288
314
|
}
|
@@ -310,37 +336,50 @@ describe Hieracles::Node do
|
|
310
336
|
[ "another.more_sublevel",
|
311
337
|
[{
|
312
338
|
value: "something",
|
313
|
-
file: 'params/farm/dev.yaml'
|
339
|
+
file: 'params/farm/dev.yaml',
|
340
|
+
merged: "something"
|
314
341
|
}]
|
315
342
|
],
|
316
343
|
[ "another.sublevel.array",
|
317
344
|
[
|
318
345
|
{
|
319
346
|
value: ["one", "two", "three"],
|
320
|
-
file: 'params/farm/dev.yaml'
|
347
|
+
file: 'params/farm/dev.yaml',
|
348
|
+
merged: ["one", "three", "two"]
|
321
349
|
},
|
322
350
|
{
|
323
351
|
value: ["four", "five"],
|
324
|
-
file: 'params/nodes/server.example.com.yaml'
|
352
|
+
file: 'params/nodes/server.example.com.yaml',
|
353
|
+
merged: ["five", "four", "one", "three", "two"]
|
325
354
|
}
|
326
355
|
]
|
327
356
|
],
|
328
357
|
[ "another.sublevel.thing",
|
329
358
|
[{
|
330
359
|
value: "always",
|
331
|
-
file: 'params/nodes/server.example.com.yaml'
|
360
|
+
file: 'params/nodes/server.example.com.yaml',
|
361
|
+
merged: "always"
|
332
362
|
}]
|
333
363
|
],
|
334
364
|
[ "common_param.subparam",
|
335
|
-
[
|
336
|
-
|
337
|
-
|
338
|
-
|
365
|
+
[
|
366
|
+
{
|
367
|
+
value: "override-me",
|
368
|
+
file: 'params/farm/dev.yaml',
|
369
|
+
merged: "override-me"
|
370
|
+
},
|
371
|
+
{
|
372
|
+
value: "overriden",
|
373
|
+
file: 'params/nodes/server.example.com.yaml',
|
374
|
+
merged: "overriden"
|
375
|
+
}
|
376
|
+
]
|
339
377
|
],
|
340
378
|
[ "somefarmparam",
|
341
379
|
[{
|
342
380
|
value: false,
|
343
|
-
file: 'params/farm/dev.yaml'
|
381
|
+
file: 'params/farm/dev.yaml',
|
382
|
+
merged: false
|
344
383
|
}]
|
345
384
|
]
|
346
385
|
]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hieracles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|