hiera-examiner 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/hiera-examiner +10 -0
- data/lib/hiera-examiner.rb +102 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75995a51092b3e500d8c5f564b74e3aa6c584387
|
4
|
+
data.tar.gz: af86a32b73b60ef46b27af16d0aa1e167f91295c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8eaef8d209fa6ac42152709240e2d1b69e112ed0163adb8fb33dd7d2ebc6e7d06f1c8fa22b02b420313f05a19695d7fb8d03677512ffdc8de9fb5933f8751c0a
|
7
|
+
data.tar.gz: 323b2f5539f9e0a199636cdbb8ddd482c054fc8f7b4065e6eaa02c3731e35ad66c35a3f9f0210edad12939a7c0ac4c05dc58f52745c0ab0b1232b3c8f775432d
|
data/bin/hiera-examiner
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
class HieraExaminer
|
2
|
+
require 'rubygems'
|
3
|
+
require 'hiera'
|
4
|
+
require 'hiera/backend'
|
5
|
+
require 'puppet'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
def initialize(conf = "/vagrant/puppet/hiera/hiera.yaml")
|
9
|
+
@conf = conf
|
10
|
+
end
|
11
|
+
|
12
|
+
def yamlLookup(key)
|
13
|
+
scope = YAML.load("")
|
14
|
+
hiera = Hiera.new(:config => @conf)
|
15
|
+
value = {val: nil, file: nil}
|
16
|
+
Hiera::Backend.datasourcefiles('yaml', scope, 'yaml') { |source, file|
|
17
|
+
yaml = YAML.load_file(file)
|
18
|
+
if (yaml.has_key?(key) && value[:val] == nil)
|
19
|
+
value = {val: yaml[key], file: file}
|
20
|
+
end
|
21
|
+
}
|
22
|
+
return value
|
23
|
+
end
|
24
|
+
|
25
|
+
def hieraLookup(key)
|
26
|
+
scope = YAML.load("")
|
27
|
+
hiera = Hiera.new(:config => @conf)
|
28
|
+
return hiera.lookup(key, @conf, scope)
|
29
|
+
end
|
30
|
+
|
31
|
+
def explain(key)
|
32
|
+
puts "#{key.red}\n#{explainDetail(key, '', true)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def explainDetail(key, prefix = '', showSource = false, yamlFileParam = '')
|
36
|
+
startExp = /%{hiera\('/
|
37
|
+
endExp = /'\)}/
|
38
|
+
|
39
|
+
firstIndex = key.index(startExp)
|
40
|
+
|
41
|
+
if (firstIndex)
|
42
|
+
newIndex = firstIndex + 9
|
43
|
+
endIndex = key.index(endExp) - 1
|
44
|
+
padding = "#{prefix}#{' '.rjust((firstIndex + 2) - prefix.length)}"
|
45
|
+
yamlMap = yamlLookup(key[newIndex..endIndex])
|
46
|
+
yamlVal = yamlMap[:val]
|
47
|
+
yamlFile = yamlMap[:file]
|
48
|
+
|
49
|
+
newVal = ''
|
50
|
+
keyVal = key
|
51
|
+
if (firstIndex == 0)
|
52
|
+
keyVal = "#{key[0..endIndex + 3].bold.red}#{key[endIndex + 4..-1]}"
|
53
|
+
newVal += "#{yamlVal}#{key[endIndex + 4..-1]}"
|
54
|
+
else
|
55
|
+
keyVal = "#{key[0..firstIndex - 1]}#{key[firstIndex..endIndex + 3].bold.red}#{key[endIndex + 4..-1]}"
|
56
|
+
newVal += "#{key[0..firstIndex - 1]}#{yamlVal}#{key[endIndex + 4..-1]}"
|
57
|
+
end
|
58
|
+
|
59
|
+
if (showSource && !yamlFileParam.empty?())
|
60
|
+
yamlFileString = " \u2794 #{yamlFileParam}"
|
61
|
+
res = "#{keyVal}#{yamlFileString.cyan}\n"
|
62
|
+
else
|
63
|
+
res = "#{keyVal}\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
res += "#{padding}#{"\u2B07".yellow}\n"
|
67
|
+
if yamlVal
|
68
|
+
yamlFileString = " \u2794 #{yamlFile}"
|
69
|
+
yamlVal = "#{yamlVal.bold.green}#{yamlFileString.cyan}"
|
70
|
+
else
|
71
|
+
yamlVal = 'MISSING'.magenta.blink
|
72
|
+
end
|
73
|
+
res += "#{padding}#{yamlVal}"
|
74
|
+
if (newVal.index(startExp))
|
75
|
+
res += "\n#{explainDetail(newVal, prefix)}"
|
76
|
+
end
|
77
|
+
|
78
|
+
return res
|
79
|
+
else
|
80
|
+
hieraVal = hieraLookup(key)
|
81
|
+
yamlMap = yamlLookup(key)
|
82
|
+
yamlVal = yamlMap[:val]
|
83
|
+
yamlFile = yamlMap[:file]
|
84
|
+
|
85
|
+
if (hieraVal.empty?() && yamlVal.empty?())
|
86
|
+
puts 'Unknown value'
|
87
|
+
elsif (yamlVal.index(startExp))
|
88
|
+
if (showSource)
|
89
|
+
res = explainDetail(yamlVal, "#{prefix}|", true, yamlFile)
|
90
|
+
else
|
91
|
+
res = explainDetail(yamlVal, "#{prefix}|")
|
92
|
+
end
|
93
|
+
res = "|\n#{res}\n#{hieraVal.green}"
|
94
|
+
return res
|
95
|
+
else
|
96
|
+
res = "|\n#{yamlVal}"
|
97
|
+
return res
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-examiner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Stortz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple hiera gem
|
14
|
+
email: astortz@redstonecontentsolutions.com
|
15
|
+
executables:
|
16
|
+
- hiera-examiner
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/hiera-examiner
|
21
|
+
- lib/hiera-examiner.rb
|
22
|
+
homepage: http://www.redstonecontentsolutions.com
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.5
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: ''
|
46
|
+
test_files: []
|