hieracles 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b4e601300916c99919b357e58d0752ec7a03e50
4
- data.tar.gz: 698972e747b63ce0b80d20b929022219f7fa6401
3
+ metadata.gz: 3eaabaf9bb23726ac33f23fed83dc3f52983e4ee
4
+ data.tar.gz: 11cbdfdca5bc942d1fc84b36273f1ac6c9447303
5
5
  SHA512:
6
- metadata.gz: f87602dbfde42cd11c5c5ee024075f8cb119c6e8b61d60528a4f88c9f8cd38843a1bd34ae84be42289c91aeaf756a6c48896b82f355f0eac9d70fd33de491bdd
7
- data.tar.gz: 636f04f5bf4b8f9d78263d56a94cae057b3e203af84744737338eccadb3cbcad69883168dbbaa33cc6a9fbc18de9922b29008a03e4dfc790a2a2c336b5f95583
6
+ metadata.gz: e20bbd06da0d72acde4f62a82f4202369b6890c640cc9f2b30e01cbcbecc87b5d23be3ee68259f3ec11f4a80d7c54698a6904a8559f34b33481fd9b9a46f9679
7
+ data.tar.gz: 4afac468de65f1797303e66d5ba32e1d9006797c7a7cec000c30b8fda1c09370f77e424545715b529c6c86e0fe5f0f7ea927e29f99dc4e18cac433669dd93b4b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Hieracles Changelog
2
2
  =======================
3
3
 
4
+ ### 0.1.0 - 2015-11-10
5
+ - display full local path in params output
6
+ - add an option to display version
7
+ - fix yaml output for true and false cases
8
+ - added a simple filter fetaure for yaml format,
9
+ but it only matches like a 'start_with'
10
+
4
11
  ### 0.0.6 - 2015-09-21
5
12
  - added doc on how to build the debian package
6
13
 
data/README.md CHANGED
@@ -74,12 +74,13 @@ Usage
74
74
  Also accepts a search string
75
75
 
76
76
  Extra args:
77
- -f <plain|console|csv|yaml|rawyaml> default console
77
+ -f <plain|console|csv|yaml|rawyaml> - default console
78
78
  -p extraparam=what;anotherparam=this
79
79
  -c <configfile>
80
80
  -h <hierafile>
81
81
  -b <basepath> default ./
82
82
  -e <encdir>
83
+ -v - displays version
83
84
 
84
85
  Completion
85
86
  -------------
@@ -112,6 +113,19 @@ and install
112
113
 
113
114
  dpkg -i hieracles_0.0.6-1_all.deb
114
115
 
116
+ Todo
117
+ --------------
118
+ - add json format
119
+ - add override information in yaml format
120
+ - add a command to search for node according to a filter
121
+ - add a command to find all nodes that use a given module
122
+ - add a command that finds all nodes for which a params is defined
123
+ - detect unused params
124
+ - create a repl, which at launch reads all data so the queries are blazing fast
125
+ - adapt to other ENCs
126
+ - adapt to puppetdb storage
127
+
128
+
115
129
  Authors
116
130
  -----------
117
131
  Hieracles original code is writen by [@mose](https://github.com/mose).
data/bin/hc CHANGED
@@ -6,6 +6,11 @@ require 'hieracles'
6
6
 
7
7
  opt = Hieracles::Optparse.new(ARGV)
8
8
 
9
+ if opt.options.has_key? :version
10
+ puts Hieracles.version
11
+ exit(0)
12
+ end
13
+
9
14
  fqdn = opt.payload[0]
10
15
  command = opt.payload[1]
11
16
  args = opt.payload[2..-1]
data/hieracles.gemspec CHANGED
@@ -13,8 +13,62 @@ Gem::Specification.new do |spec|
13
13
  spec.metadata = { "changelog" => "https://github.com/Gandi/hieracles/blob/master/CHANGELOG.md" }
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.files = %w(
17
+ CHANGELOG.md
18
+ Gemfile
19
+ LICENSE
20
+ README.md
21
+ Rakefile
22
+ bin/hc
23
+ hieracles.gemspec
24
+ lib/hieracles.rb
25
+ lib/hieracles/config.rb
26
+ lib/hieracles/format.rb
27
+ lib/hieracles/formats/console.rb
28
+ lib/hieracles/formats/csv.rb
29
+ lib/hieracles/formats/plain.rb
30
+ lib/hieracles/formats/rawyaml.rb
31
+ lib/hieracles/formats/yaml.rb
32
+ lib/hieracles/help.rb
33
+ lib/hieracles/hiera.rb
34
+ lib/hieracles/node.rb
35
+ lib/hieracles/optparse.rb
36
+ lib/hieracles/registry.rb
37
+ lib/hieracles/utils.rb
38
+ spec/files/config.yml
39
+ spec/files/enc/server.example.com.yaml
40
+ spec/files/enc/server2.example.com.yaml
41
+ spec/files/enc/server3.example.com.yaml
42
+ spec/files/enc/server4.example.com.yaml
43
+ spec/files/farm_modules/dev.pp
44
+ spec/files/farm_modules/dev2.pp
45
+ spec/files/farm_modules/dev4.pp
46
+ spec/files/hiera.yaml
47
+ spec/files/hiera_no_yamlbackend.yaml
48
+ spec/files/hiera_yamlbackend_notfound.yaml
49
+ spec/files/modules/fake_module/manifests/init.pp
50
+ spec/files/modules/fake_module2/manifests/init.pp
51
+ spec/files/modules/fake_module3/manifests/init.pp
52
+ spec/files/modules/faux_module1/manifests/init.pp
53
+ spec/files/modules/faux_module2/manifests/init.pp
54
+ spec/files/params/common/common.yml
55
+ spec/files/params/farm/dev.yaml
56
+ spec/files/params/nodes/server.example.com.yaml
57
+ spec/lib/config_spec.rb
58
+ spec/lib/format_spec.rb
59
+ spec/lib/formats/console_spec.rb
60
+ spec/lib/formats/csv_spec.rb
61
+ spec/lib/formats/plain_spec.rb
62
+ spec/lib/formats/rawyaml_spec.rb
63
+ spec/lib/formats/yaml_spec.rb
64
+ spec/lib/help_spec.rb
65
+ spec/lib/hiera_spec.rb
66
+ spec/lib/node_spec.rb
67
+ spec/lib/optparse_spec.rb
68
+ spec/lib/registry_spec.rb
69
+ spec/lib/utils_spec.rb
70
+ spec/spec_helper.rb
71
+ )
18
72
  spec.executables = ['hc']
19
73
  spec.test_files = spec.files.grep(%r{^spec/})
20
74
  spec.require_paths = ["lib"]
@@ -19,15 +19,21 @@ module Hieracles
19
19
  @node.modules.to_yaml
20
20
  end
21
21
 
22
- def params(args)
23
- commented_yaml_tree(true)
22
+ def params(args = nil)
23
+ if args
24
+ args = args.join(' ')
25
+ end
26
+ commented_yaml_tree(args, true)
24
27
  end
25
28
 
26
- def allparams(args)
27
- commented_yaml_tree(false)
29
+ def allparams(args = nil)
30
+ if args
31
+ args = args.join('.')
32
+ end
33
+ commented_yaml_tree(args, false)
28
34
  end
29
35
 
30
- def commented_yaml_tree(without_common = true)
36
+ def commented_yaml_tree(filter, without_common = true)
31
37
  tree = @node.params_tree(without_common)
32
38
  params = Hash[@node.params(without_common)]
33
39
  mergetree('---', [], tree, params)
@@ -64,6 +70,22 @@ module Hieracles
64
70
  output
65
71
  end
66
72
 
73
+ def add_trueclass(output, key, leaf, params, indent)
74
+ output += 'true'
75
+ if params["#{key.join('.')}"]
76
+ output += " # " + params[key.join('.')][0][:file]
77
+ end
78
+ output
79
+ end
80
+
81
+ def add_falseclass(output, key, leaf, params, indent)
82
+ output += 'false'
83
+ if params["#{key.join('.')}"]
84
+ output += " # " + params[key.join('.')][0][:file]
85
+ end
86
+ output
87
+ end
88
+
67
89
  end
68
90
  end
69
91
  end
@@ -29,6 +29,7 @@ module Hieracles
29
29
  -h <hierafile>
30
30
  -b <basepath> default ./
31
31
  -e <encdir>
32
+ -v just displays the version of Hieracles
32
33
  END
33
34
  end
34
35
  end
@@ -8,9 +8,9 @@ module Hieracles
8
8
  @loaded = YAML.load_file(@hierafile)
9
9
  end
10
10
 
11
- def datadir
11
+ def datapath
12
12
  raise TypeError, "Sorry hieracles only knows yaml backend for now." unless @loaded[:yaml]
13
- parampath = File.expand_path(File.join(Config.basepath, @loaded[:yaml][:datadir]))
13
+ parampath = File.expand_path(File.join(Config.basepath, datadir))
14
14
  raise IOError, "Params dir #{parampath} not found." unless Dir.exist? parampath
15
15
  parampath
16
16
  end
@@ -19,6 +19,10 @@ module Hieracles
19
19
  @loaded[:hierarchy]
20
20
  end
21
21
 
22
+ def datadir
23
+ @loaded[:yaml][:datadir]
24
+ end
25
+
22
26
  def params
23
27
  hierarchy.join(',').scan(/%\{(?:::)?([^\}]*)\}/).flatten.uniq
24
28
  end
@@ -30,23 +30,23 @@ module Hieracles
30
30
  @hiera.hierarchy.reduce([]) do |a, f|
31
31
  file = format("#{f}.yaml", @hiera_params) rescue nil
32
32
  if file &&
33
- File.exist?(File.join(@hiera.datadir, file)) &&
33
+ File.exist?(File.join(@hiera.datapath, file)) &&
34
34
  (!without_common ||
35
35
  !file[/common/])
36
- a << file
36
+ a << File.join(@hiera.datadir, file)
37
37
  end
38
38
  a
39
39
  end
40
40
  end
41
41
 
42
42
  def paths(without_common = true)
43
- files(without_common).map { |p| File.join(@hiera.datadir, p) }
43
+ files(without_common).map { |p| File.join(Config.basepath, p) }
44
44
  end
45
45
 
46
46
  def params(without_common = true)
47
47
  params = {}
48
48
  files(without_common).each do |f|
49
- data = YAML.load_file(File.join(@hiera.datadir, f))
49
+ data = YAML.load_file(File.join(Config.basepath, f))
50
50
  s = to_shallow_hash(data)
51
51
  s.each do |k,v|
52
52
  params[k] ||= []
@@ -28,6 +28,10 @@ module Hieracles
28
28
  encpath: {
29
29
  has_arg: true,
30
30
  aliases: ['e', 'encpath']
31
+ },
32
+ version: {
33
+ has_arg: false,
34
+ aliases: ['v', 'version']
31
35
  }
32
36
  }
33
37
 
@@ -0,0 +1,23 @@
1
+
2
+ module Hieracles
3
+ module Registry
4
+ extend self
5
+
6
+ def farms(config)
7
+ @_farms ||= Dir.glob(File.join(config.basepath, format(config.classpath, '*'))).sort
8
+ end
9
+
10
+ def nodes(config)
11
+ @_nodes ||= Dir.glob(File.join(config.basepath, config.encpath, '*.yaml')).sort.map do |f|
12
+ File.basename(f, '.yaml')
13
+ end
14
+ end
15
+
16
+ def modules(config)
17
+ @_modules ||= Dir.glob(File.join(config.basepath, config.modulepath, '*')).sort.map do |f|
18
+ File.basename(f)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
data/lib/hieracles.rb CHANGED
@@ -5,6 +5,7 @@ require 'hieracles/utils'
5
5
  require 'hieracles/help'
6
6
  require 'hieracles/node'
7
7
  require 'hieracles/format'
8
+ require 'hieracles/registry'
8
9
  require 'hieracles/formats/csv'
9
10
  require 'hieracles/formats/yaml'
10
11
  require 'hieracles/formats/plain'
@@ -13,4 +14,7 @@ require 'hieracles/formats/rawyaml'
13
14
 
14
15
  # https://github.com/Gandi/hieracles
15
16
  module Hieracles
17
+ def self.version
18
+ File.read(File.expand_path('../../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
19
+ end
16
20
  end
@@ -7,6 +7,7 @@ describe Hieracles::Hiera do
7
7
 
8
8
  context 'hiera file not found' do
9
9
  let(:options) { {
10
+ config: 'spec/files/config.yml',
10
11
  basepath: 'spec/files',
11
12
  hierafile: 'hiera_no.yaml'
12
13
  } }
@@ -17,6 +18,7 @@ describe Hieracles::Hiera do
17
18
 
18
19
  context 'hiera file found' do
19
20
  let(:options) { {
21
+ config: 'spec/files/config.yml',
20
22
  basepath: 'spec/files',
21
23
  hierafile: 'hiera.yaml'
22
24
  } }
@@ -32,25 +34,27 @@ describe Hieracles::Hiera do
32
34
 
33
35
  end
34
36
 
35
- describe '.datadir' do
37
+ describe '.datapath' do
36
38
  context 'hiera file do not have a yaml backend' do
37
39
  let(:options) { {
40
+ config: 'spec/files/config.yml',
38
41
  basepath: 'spec/files',
39
42
  hierafile: 'hiera_no_yamlbackend.yaml'
40
43
  } }
41
44
  let(:hiera) { Hieracles::Hiera.new }
42
45
  it 'raises an error' do
43
- expect { hiera.datadir }.to raise_error(TypeError)
46
+ expect { hiera.datapath }.to raise_error(TypeError)
44
47
  end
45
48
  end
46
49
  context 'hiera file has a yaml backend but dir not found' do
47
50
  let(:options) { {
51
+ config: 'spec/files/config.yml',
48
52
  basepath: 'spec/files',
49
53
  hierafile: 'hiera_yamlbackend_notfound.yaml'
50
54
  } }
51
55
  let(:hiera) { Hieracles::Hiera.new }
52
56
  it 'raises an error' do
53
- expect { hiera.datadir }.to raise_error(IOError)
57
+ expect { hiera.datapath }.to raise_error(IOError)
54
58
  end
55
59
  end
56
60
  context 'hiera file has a yaml backend' do
@@ -64,16 +68,31 @@ describe Hieracles::Hiera do
64
68
  let(:hiera) { Hieracles::Hiera.new }
65
69
  let(:expected) { File.expand_path(File.join(Hieracles::Config.basepath, 'params')) }
66
70
  it 'returns params path' do
67
- expect(hiera.datadir).to eq expected
71
+ expect(hiera.datapath).to eq expected
68
72
  end
69
73
  end
70
74
  end
71
75
 
76
+ describe '.datadir' do
77
+ let(:options) {
78
+ {
79
+ config: 'spec/files/config.yml',
80
+ hierafile: 'hiera.yaml',
81
+ basepath: 'spec/files'
82
+ }
83
+ }
84
+ let(:hiera) { Hieracles::Hiera.new }
85
+ it { expect(hiera.datadir).to eq 'params/' }
86
+ end
87
+
72
88
  context "with proper params" do
73
- let(:options) { {
74
- basepath: 'spec/files',
75
- hierafile: 'hiera.yaml'
76
- } }
89
+ let(:options) {
90
+ {
91
+ config: 'spec/files/config.yml',
92
+ basepath: 'spec/files',
93
+ hierafile: 'hiera.yaml'
94
+ }
95
+ }
77
96
  let(:hiera) { Hieracles::Hiera.new }
78
97
 
79
98
  describe '.hierarchy' do
@@ -57,8 +57,8 @@ describe Hieracles::Node do
57
57
  describe '.files' do
58
58
  let(:expected) {
59
59
  [
60
- 'nodes/server.example.com.yaml',
61
- 'farm/dev.yaml'
60
+ 'params/nodes/server.example.com.yaml',
61
+ 'params/farm/dev.yaml'
62
62
  ]
63
63
  }
64
64
  it { expect(node.files).to eq expected }
@@ -67,8 +67,8 @@ describe Hieracles::Node do
67
67
  describe '.paths' do
68
68
  let(:expected) {
69
69
  [
70
- File.join(node.hiera.datadir, 'nodes/server.example.com.yaml'),
71
- File.join(node.hiera.datadir, 'farm/dev.yaml')
70
+ File.join(node.hiera.datapath, 'nodes/server.example.com.yaml'),
71
+ File.join(node.hiera.datapath, 'farm/dev.yaml')
72
72
  ]
73
73
  }
74
74
  it { expect(node.paths).to eq expected }
@@ -80,19 +80,19 @@ describe Hieracles::Node do
80
80
  [ "another.sublevel.thing",
81
81
  [{
82
82
  value: "always",
83
- file: 'nodes/server.example.com.yaml'
83
+ file: 'params/nodes/server.example.com.yaml'
84
84
  }]
85
85
  ],
86
86
  [ "common_param.subparam",
87
87
  [{
88
88
  value: "overriden",
89
- file: 'nodes/server.example.com.yaml'
89
+ file: 'params/nodes/server.example.com.yaml'
90
90
  }]
91
91
  ],
92
92
  [ "somefarmparam",
93
93
  [{
94
94
  value: false,
95
- file: 'farm/dev.yaml'
95
+ file: 'params/farm/dev.yaml'
96
96
  }]
97
97
  ]
98
98
  ]
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hieracles::Registry do
4
+ let(:base) { File.expand_path('../../../', __FILE__)}
5
+
6
+ describe '.farms' do
7
+ let(:options) do
8
+ { config: 'spec/files/config.yml', basepath: 'spec/files' }
9
+ end
10
+ let(:expected) { [
11
+ File.join(base, options[:basepath], 'farm_modules', 'dev.pp'),
12
+ File.join(base, options[:basepath], 'farm_modules', 'dev2.pp'),
13
+ File.join(base, options[:basepath], 'farm_modules', 'dev4.pp')
14
+ ] }
15
+ before { Hieracles::Config.load options}
16
+ it { expect(Hieracles::Registry.farms Hieracles::Config).to eq expected }
17
+ end
18
+
19
+ describe '.nodes' do
20
+ let(:options) do
21
+ { config: 'spec/files/config.yml', basepath: 'spec/files' }
22
+ end
23
+ let(:expected) { [
24
+ 'server.example.com',
25
+ 'server2.example.com',
26
+ 'server3.example.com',
27
+ 'server4.example.com'
28
+ ] }
29
+ before { Hieracles::Config.load options}
30
+ it { expect(Hieracles::Registry.nodes Hieracles::Config).to eq expected }
31
+ end
32
+
33
+ describe '.modules' do
34
+ let(:options) do
35
+ { config: 'spec/files/config.yml', basepath: 'spec/files' }
36
+ end
37
+ let(:expected) { [
38
+ 'fake_module',
39
+ 'fake_module2',
40
+ 'fake_module3',
41
+ 'faux_module1',
42
+ 'faux_module2'
43
+ ] }
44
+ before { Hieracles::Config.load options}
45
+ it { expect(Hieracles::Registry.modules Hieracles::Config).to eq expected }
46
+ end
47
+
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
- require 'rubygems'
3
- require 'bundler'
2
+ # require 'rubygems'
3
+ # require 'bundler'
4
4
 
5
- if ENV['COV']
6
- require 'simplecov'
7
- SimpleCov.profiles.define :app do
8
- add_group 'bin', '/bin'
9
- add_group 'lib', '/lib'
10
- add_filter '/vendor/'
11
- add_filter '/spec/'
12
- end
13
- SimpleCov.start :app
14
- else
15
- require 'coveralls'
16
- Coveralls.wear!
17
- end
5
+ # if ENV['COV']
6
+ # require 'simplecov'
7
+ # SimpleCov.profiles.define :app do
8
+ # add_group 'bin', '/bin'
9
+ # add_group 'lib', '/lib'
10
+ # add_filter '/vendor/'
11
+ # add_filter '/spec/'
12
+ # end
13
+ # SimpleCov.start :app
14
+ # else
15
+ # require 'coveralls'
16
+ # Coveralls.wear!
17
+ # end
18
18
 
19
19
  require 'hieracles'
20
20
 
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.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,11 +102,6 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".coveralls.yml"
106
- - ".gitignore"
107
- - ".rspec"
108
- - ".ruby-version"
109
- - ".travis.yml"
110
105
  - CHANGELOG.md
111
106
  - Gemfile
112
107
  - LICENSE
@@ -126,6 +121,7 @@ files:
126
121
  - lib/hieracles/hiera.rb
127
122
  - lib/hieracles/node.rb
128
123
  - lib/hieracles/optparse.rb
124
+ - lib/hieracles/registry.rb
129
125
  - lib/hieracles/utils.rb
130
126
  - spec/files/config.yml
131
127
  - spec/files/enc/server.example.com.yaml
@@ -157,10 +153,9 @@ files:
157
153
  - spec/lib/hiera_spec.rb
158
154
  - spec/lib/node_spec.rb
159
155
  - spec/lib/optparse_spec.rb
156
+ - spec/lib/registry_spec.rb
160
157
  - spec/lib/utils_spec.rb
161
158
  - spec/spec_helper.rb
162
- - tools/completion/_hc
163
- - tools/nodeinfo
164
159
  homepage: https://github.com/Gandi/hieracles
165
160
  licenses:
166
161
  - MIT
@@ -217,5 +212,6 @@ test_files:
217
212
  - spec/lib/hiera_spec.rb
218
213
  - spec/lib/node_spec.rb
219
214
  - spec/lib/optparse_spec.rb
215
+ - spec/lib/registry_spec.rb
220
216
  - spec/lib/utils_spec.rb
221
217
  - spec/spec_helper.rb
data/.coveralls.yml DELETED
@@ -1,2 +0,0 @@
1
- service_name: travis-ci
2
- repo_token: MMYNBOKRQNladhirYnmkuJ3DqNSMbJh40
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- /vendor/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format progress
2
- --color
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.2
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 1.9.3
5
- - 2.2.2
data/tools/completion/_hc DELETED
@@ -1,13 +0,0 @@
1
- #compdef hc
2
-
3
- _hc() {
4
- local cmd
5
- if (( CURRENT == 2 ))
6
- then
7
- _values -C 'fqdn' ${$(find ./enc -print | xargs -- basename -s | sed -e 's~\.yaml~~')}
8
- else if (( CURRENT == 3 ))
9
- _values -C 'command' info files paths modules params allparams
10
- fi
11
- }
12
-
13
- _hc
data/tools/nodeinfo DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This is a cgi script intended to be installed on
3
- # puppetmasters v2.6 and v2.7
4
-
5
- require 'mysql'
6
- require 'cgi'
7
-
8
- cgi = CGI.new
9
-
10
- if cgi['q'].empty?
11
- puts "Content-type: text/plain\n\n"
12
- puts "KO"
13
- exit(0)
14
- end
15
-
16
- DB_HOST = 'localhost'
17
- DB_USER = ''
18
- DB_PASS = ''
19
- DB_FIELDS = %w(farm site country)
20
-
21
- fqdn = cgi['q'].gsub(/[^-_0-9a-zA-z\.]/, '')
22
- QUERY = "select #{DB_FIELDS.join(', ')} from node left join datacenter dc on node.site=dc.datacenter where nodename='#{fqdn}';"
23
- DB = "puppet"
24
-
25
-
26
- begin
27
- puts "Content-type: text/plain\n\n"
28
- con = Mysql.new DB_HOST, DB_USER, DB_PASS
29
- rs = con.query "use " + DB
30
- rs = con.query QUERY
31
- rs.each do |r|
32
- puts r.join(',')
33
- end
34
-
35
- rescue Mysql::Error => e
36
- puts e.errno
37
- puts e.error
38
-
39
- ensure
40
- con.close if con
41
- end