hiera-browser 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTMzYmYyODE0OWJlOTE5MjczNDYyNGVhNWQ0M2M2OWRkZmFmZGNjNQ==
5
+ data.tar.gz: !binary |-
6
+ Yjg4ODRjZTBkZTdmY2U5MGQ3NjNiZGQ1MGJjMDliYTQ4YTVkNDgxNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2Q5MTI3NjAyMGUwNDFjOWY3NDY2YmUxNzU4ODQ2NTgwZjEzNGM5ODQyMGIz
10
+ OWYyZGRhYTM3YmU4OWQ2NGZjOWYzMzQ4NGU5MzYzZjE0N2JiNTgwMmVjZDA2
11
+ OTc2NGQ4OGMzZTcwZmE4NDBhN2E5YWVkNjY3Njk3M2VmMDEwMjI=
12
+ data.tar.gz: !binary |-
13
+ YWJhZjdjNWIzZTMzYTBkMTljZmMwYTcxNjAwMmE2YjcxMzNhYzdkZGEyNTBm
14
+ MDg2Yzg4ZTE2MWI0YWNkODA2ZTZlYmU1N2MxN2VlNTgzYTdjMDg1OGVmZGQz
15
+ NGM0NWQxZTZhZmNkMzk4MjZhYzQ5ODNiNmNmMmZjZWE4ODIxZmY=
data/bin/hiera-browser ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['RACK_ENV'] = 'production'
4
+
5
+ require 'rack'
6
+ require 'rack/server'
7
+ require 'app/ui'
8
+
9
+ if ENV['HIERA_YAML'] && File.exist?(ENV['HIERA_YAML'])
10
+ Rack::Server.start :app => HieraBrowserUI
11
+ else
12
+ puts "Must provide the location of your hiera.yaml as ENV['HIERA_YAML']"
13
+ end
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ require 'app/ui'
2
+ require 'sinatra'
3
+ require 'tilt'
4
+
5
+ run HieraBrowserUI
data/lib/app/ui.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ require 'sinatra'
5
+ require 'hiera_browser'
6
+ require 'ap'
7
+ require 'json'
8
+ require 'slim'
9
+
10
+ use Rack::Session::Cookie, :secret => '4zENWx0ruhWU3ZN'
11
+
12
+ class HieraBrowserUI < Sinatra::Application
13
+ # api
14
+ get '/api/v1/nodes' do
15
+ @nodes = Node.list
16
+ JSON.generate(@nodes)
17
+ end
18
+
19
+ get "/api/v1/node/:node" do |node|
20
+ keys = session[:keys] || []
21
+ @values = Node.new(:certname => node).hiera_values(:additive_keys => keys)
22
+ JSON.generate(@values)
23
+ end
24
+
25
+ post "/api/v1/node/:node" do |node|
26
+ keys = JSON.instance_eval(request['keys']) || []
27
+ @values = Node.new(:certname => node).hiera_values(:additive_keys => keys)
28
+ JSON.generate(@values)
29
+ end
30
+
31
+ # human
32
+ get '/' do
33
+ redirect('/nodes')
34
+ end
35
+
36
+ get '/nodes' do
37
+ @title = "node list"
38
+ @nodes = Node.list
39
+ slim :nodes
40
+ end
41
+
42
+ get '/node/:node' do |node|
43
+ @title, @node = "node: #{node}", node
44
+ keys = session[:keys] || []
45
+ @values = Node.new(:certname => node).sorted_values(:keys => keys)
46
+ slim :node
47
+ end
48
+
49
+ get '/add/additive/:key' do |key|
50
+ session[:keys] = session[:keys] || []
51
+ session[:keys] << key
52
+ redirect back
53
+ end
54
+
55
+ get '/remove/additive/:key' do |key|
56
+ session[:keys].reject!{|k| k == key}
57
+ redirect back
58
+ end
59
+
60
+ get '/debug/session' do
61
+ debug_hash = {
62
+ :keys => session[:keys],
63
+ :env => settings.environment,
64
+ :rack_env => ENV['RACK_ENV'],
65
+ }
66
+ JSON.generate(debug_hash)
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ html
2
+ head
3
+ title
4
+ = @title
5
+ body
6
+ p
7
+ a href="/nodes" nodes
8
+ - if @node
9
+ | >
10
+ strong
11
+ a href=request.path_info = @node
@@ -0,0 +1,15 @@
1
+ == slim :header
2
+ h1 = @node
3
+ - @values.each do |key, value|
4
+ - $stdout = StringIO.new
5
+ - if session[:keys] && session[:keys].include?(key)
6
+ a href="/remove/additive/#{key}" => key
7
+ | (additive)
8
+ - else
9
+ a href="/add/additive/#{key}" = key
10
+ | :
11
+ - ap value, :html => true
12
+ == $stdout.string
13
+ - $stdout = STDOUT
14
+ br
15
+ hr
@@ -0,0 +1,6 @@
1
+ == slim :header
2
+ h1 node list
3
+ ul
4
+ - @nodes.each do |node|
5
+ li
6
+ a href="node/#{node}" = node
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+
3
+ class DataDir
4
+ attr_reader :path
5
+
6
+ def initialize(args={})
7
+ @hiera = args[:hiera]
8
+ @paths = render_paths(:path => args[:path])
9
+ end
10
+
11
+ def render_paths(args)
12
+ begin
13
+ variables = args[:path].match(/\%\{([a-z_\:]+)\}/).captures
14
+ variables.map{|v|
15
+ Node.parameters[v].map{|param|
16
+ args[:path].gsub(/\%\{#{v}\}/, param)}.flatten
17
+ }.flatten
18
+ rescue NoMethodError
19
+ [args[:path]]
20
+ end
21
+ end
22
+
23
+ def yaml_files
24
+ @paths.map{|p|
25
+ Dir.chdir(p) { Dir.glob('**/*.yaml') }
26
+ }.flatten
27
+ end
28
+
29
+ def datafiles
30
+ @paths.map{|path|
31
+ yaml_files.map{|f| DataFile.new(:path => File.join(path,f))}.flatten
32
+ }.flatten
33
+ end
34
+
35
+ def keys
36
+ datafiles.map{|datafile| datafile.keys}.flatten.uniq.sort
37
+ end
38
+ end
39
+
40
+ class DataFile
41
+ attr_reader :path
42
+
43
+ def initialize(args={})
44
+ @path = args[:path]
45
+ @keys = keys
46
+ end
47
+
48
+ def keys
49
+ YAML.load_file(@path).keys
50
+ end
51
+ end
@@ -0,0 +1,72 @@
1
+ require 'yaml'
2
+
3
+ class HieraController
4
+ @@hiera_yaml = ENV['HIERA_YAML'] || './hiera.yaml'
5
+ attr_reader :hiera_yaml
6
+
7
+ def initialize(args={})
8
+ @hiera_yaml = args[:hiera_yaml] || @@hiera_yaml
9
+ @hiera = hiera(:config => @hiera_yaml)
10
+ end
11
+
12
+ def hiera(args={})
13
+ @hiera || Hiera.new(args)
14
+ end
15
+
16
+ def config
17
+ hiera.config
18
+ end
19
+
20
+ def datadirs
21
+ config[:backends].map{|b|
22
+ path = config[b.to_sym][:datadir]
23
+ DataDir.new(
24
+ :hiera => self,
25
+ :path => path,
26
+ )
27
+ }
28
+ end
29
+
30
+ def keys
31
+ datadirs.map{|d| d.keys}.flatten.uniq.sort
32
+ end
33
+
34
+ def hierarchy
35
+ config[:hierarchy]
36
+ end
37
+
38
+ def lookup(args)
39
+ key = args[:key]
40
+ scope = args[:scope]
41
+ resolution_type = args[:resolution_type] || :priority
42
+ Hash[*[key,hiera.lookup(key, nil, scope, nil, resolution_type)]]
43
+ end
44
+
45
+ def get_all(args)
46
+ scope = args[:scope]
47
+ values = keys.inject({}){|a, k|
48
+ a.merge({k => lookup(:key => k, :scope => scope)}) }
49
+ if args[:additive_keys]
50
+ additive_values = args[:additive_keys].inject({}){|a,k|
51
+ a.merge({k => lookup_additive(:key => k, :scope => scope)}) }
52
+ values = values.delete_if {|k,v| additive_values.has_key?(k)}.merge!(additive_values)
53
+ end
54
+ values
55
+ end
56
+
57
+ def lookup_additive(args)
58
+ key = args[:key]
59
+ scope = args[:scope]
60
+ value = lookup(:key => key, :scope => scope)
61
+ lookup_type =
62
+ case value.values.pop
63
+ when Hash
64
+ :hash
65
+ when TrueClass, FalseClass
66
+ :priority
67
+ else
68
+ :array
69
+ end
70
+ lookup(:key => key, :scope => scope, :resolution_type => lookup_type)
71
+ end
72
+ end
@@ -0,0 +1,71 @@
1
+ require 'yaml'
2
+ require 'puppet'
3
+
4
+ class Node
5
+ attr_reader :certname, :facts, :node_dir
6
+
7
+ @@node_dir =
8
+ if ENV['YAML_DIR']
9
+ ENV['YAML_DIR']
10
+ elsif File.exist?('/var/opt/lib/pe-puppet/yaml')
11
+ '/var/opt/lib/pe-puppet/yaml/node'
12
+ else
13
+ '/var/lib/puppet/yaml/node'
14
+ end
15
+
16
+ def initialize(args)
17
+ @certname = args[:certname]
18
+ @facts = facts_yaml
19
+ @hiera = args[:hiera] || HieraController.new
20
+ end
21
+
22
+ def facts_yaml
23
+ path = File.join(@@node_dir,"#{@certname}.yaml")
24
+ node = YAML.load_file(path)
25
+ node.parameters.merge(node.facts.values)
26
+ end
27
+
28
+ def hiera_values(args={})
29
+ additive_keys = args[:additive_keys] || []
30
+ @hiera.get_all(:scope => @facts, :additive_keys => additive_keys).
31
+ values.inject({}){|a,v| a.merge!(v)}
32
+ end
33
+
34
+ def sorted_values(args)
35
+ keys = args[:keys]
36
+ hiera_values(:additive_keys => keys).sort_by{|k,v|k}
37
+ end
38
+
39
+ def environment
40
+ @facts['environment']
41
+ end
42
+
43
+ def self.files
44
+ begin
45
+ Dir.chdir(@@node_dir) { Dir.glob('**/*.yaml') }
46
+ rescue Errno::ENOENT => e
47
+ raise "Can't find your $yamldir: #{e}"
48
+ end
49
+ end
50
+
51
+ def self.list
52
+ files = self.files
53
+ files.map{|f| f.split('.yaml')}.flatten
54
+ end
55
+
56
+ def self.parameters
57
+ files = self.files
58
+ files.map{|f| YAML.load_file(File.join(@@node_dir,f)).parameters}.
59
+ inject({}){|a,params|
60
+ params.each {|key, value|
61
+ a[key] = [] unless a[key]
62
+ a[key] << value unless a[key].include? value
63
+ }
64
+ a
65
+ }
66
+ end
67
+
68
+ def self.environments
69
+ self.parameters["environment"]
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ require 'hiera'
2
+ require 'hiera_browser/hiera_controller'
3
+ require 'hiera_browser/data'
4
+ require 'hiera_browser/node'
5
+
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-browser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - David Gwilliam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 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: 1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: slim
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: tilt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.4.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.4.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: dotenv
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 2.8.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.8.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: puppet
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.12.6
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.12.6
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-doc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: shotgun
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: lookout-rack-test
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: Tries to guess what values hiera will return for any existing node in
196
+ your infrastructure
197
+ email: dhgwilliam@gmail.com
198
+ executables:
199
+ - hiera-browser
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - bin/hiera-browser
204
+ - config.ru
205
+ - lib/app/ui.rb
206
+ - lib/app/views/header.slim
207
+ - lib/app/views/node.slim
208
+ - lib/app/views/nodes.slim
209
+ - lib/hiera_browser.rb
210
+ - lib/hiera_browser/data.rb
211
+ - lib/hiera_browser/hiera_controller.rb
212
+ - lib/hiera_browser/node.rb
213
+ homepage:
214
+ licenses:
215
+ - APACHE 2.0
216
+ metadata: {}
217
+ post_install_message:
218
+ rdoc_options: []
219
+ require_paths:
220
+ - lib
221
+ required_ruby_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ! '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ! '>'
229
+ - !ruby/object:Gem::Version
230
+ version: 1.3.1
231
+ requirements: []
232
+ rubyforge_project:
233
+ rubygems_version: 2.2.2
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: Naive browser for hiera data
237
+ test_files: []
238
+ has_rdoc: