hieracles 0.3.2 → 0.3.3

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: c8a864c5618b6297ced275fbd2bdc05444ef190e
4
- data.tar.gz: 8417df1abc0dd1b2bd516f59c14c9924d5efedb4
3
+ metadata.gz: 44c29a8927b67e49372692e6b01dbc470d501934
4
+ data.tar.gz: 0d951af952efeaeae73dbe43dc22a93b6c1efb71
5
5
  SHA512:
6
- metadata.gz: a5f7e2ac82b91f4308615a7378c726d16487633a47438d47976e3e0e6251bd89ab9fc57b6aca8b87ea367fc38f9b99b7b59940d80e13d5de4f136ef522665e39
7
- data.tar.gz: 9c56a3cb36c07afa57c0548020d72641c8fe23e1d39825ac5c49a3f9161dead0f307507906a29d9e362da1b5580db3730f83d033b0cfef4dc5716c6181c9f332
6
+ metadata.gz: e8cf4e3b7cd75be578b054e4eaeb3f304d5335bf1300a417836574b04fb3437c31eab7c3f0002ed13f446b9bc1ca86d99f831990345f5d9e9f3d970cbd19c4a5
7
+ data.tar.gz: c79542cdc9cd45d562a32ecc30b40ebcdee791f9c94e469855fa1d47dec5cac8dabc0761aca34924a15b987f36aed62851ce1c72cacc8b7319feb0551560979f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Hieracles Changelog
2
2
  =======================
3
3
 
4
+ ### 0.3.3 - 2016-02-11
5
+ - add some convenience methods for usage as a lib
6
+ - add a nodes_data in registry module to get all info for all nodes.
7
+
4
8
  ### 0.3.2 - 2015-12-30
5
9
  - fix ppdb that suffered a regression
6
10
 
data/README.md CHANGED
@@ -4,7 +4,7 @@ Hieracles
4
4
  [![Gem Version](https://img.shields.io/gem/v/hieracles.svg)](http://rubygems.org/gems/hieracles)
5
5
  [![Downloads](http://img.shields.io/gem/dt/hieracles.svg)](https://rubygems.org/gems/hieracles)
6
6
  [![Build Status](https://img.shields.io/travis/Gandi/hieracles.svg)](https://travis-ci.org/Gandi/hieracles)
7
- [![Coverage Status](https://img.shields.io/coveralls/Gandi/hieracles.svg)](https://coveralls.io/github/Gandi/hieracles?branch=master)
7
+ [![Coverage Status](https://img.shields.io/coveralls/Gandi/hieracles.svg)](https://coveralls.io/github/Gandi/hieracles)
8
8
  [![Dependency Status](https://gemnasium.com/Gandi/hieracles.svg)](https://gemnasium.com/Gandi/hieracles)
9
9
  [![Code Climate](https://img.shields.io/codeclimate/github/Gandi/hieracles.svg)](https://codeclimate.com/github/Gandi/hieracles)
10
10
 
@@ -165,6 +165,8 @@ or for a ssl setup:
165
165
  ca_file: path/to/ca_file
166
166
  verify_peer: false
167
167
 
168
+ Note: the SSL config was not tested yet.
169
+
168
170
  #### Usage
169
171
 
170
172
  If you set `usedb: false` the `hc` commands will not query the puppetdb unless you pass the `-db` options.
@@ -2,7 +2,7 @@ module Hieracles
2
2
  module Interpolate
3
3
 
4
4
  def parse(data, values, interactive = false)
5
- data.gsub(/%\{(?:(scope|hiera|literal|alias)\(['"])?(?:::)?([^\}"']*)(?:["']\))?\}/) do |match|
5
+ data.gsub(regex) do |match|
6
6
  if interactive && !values[$2.to_sym]
7
7
  values[$2.to_sym] = ask_about($2)
8
8
  values[$2.to_sym]
@@ -12,6 +12,13 @@ module Hieracles
12
12
  end
13
13
  end
14
14
 
15
+ def extract(data)
16
+ data.scan(regex).reduce([]) do |a, m|
17
+ a << m[1] unless a.include?(m[1])
18
+ a
19
+ end
20
+ end
21
+
15
22
  def ask_about(var)
16
23
  @@output.puts
17
24
  @@output.puts "'#{var}' is not defined."
@@ -28,5 +35,9 @@ module Hieracles
28
35
  @@output = output
29
36
  end
30
37
 
38
+ def regex
39
+ /%\{(?:(scope|hiera|literal|alias)\(['"])?(?:::)?([^\}"']*)(?:["']\))?\}/
40
+ end
41
+
31
42
  end
32
43
  end
@@ -48,21 +48,6 @@ module Hieracles
48
48
  files(without_common).map { |p| File.join(@config.basepath, p) }
49
49
  end
50
50
 
51
- def params_old(without_common = true)
52
- params = {}
53
- files(without_common).reverse.each do |f|
54
- data = YAML.load_file(File.join(@config.basepath, f))
55
- if data
56
- s = to_shallow_hash(data)
57
- s.each do |k,v|
58
- params[k] ||= []
59
- params[k] << { value: v, file: f }.merge(merge_value(params[k], v))
60
- end
61
- end
62
- end
63
- params.sort
64
- end
65
-
66
51
  def params(without_common = true)
67
52
  params = {}
68
53
  files(without_common).each do |f|
@@ -87,7 +72,6 @@ module Hieracles
87
72
  overriden: false,
88
73
  found_in: [{ value: v, file: f }]
89
74
  }
90
-
91
75
  end
92
76
  end
93
77
  end
@@ -22,5 +22,16 @@ module Hieracles
22
22
  end
23
23
  end
24
24
 
25
+ def nodes_data(config, env = 'production', reload = false)
26
+ @_nodes_data = {} if reload || !@_nodes_data
27
+ @_nodes_data[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
28
+ fqdn = File.basename(f, '.yaml')
29
+ a[fqdn] = YAML.load_file(f)['parameters']
30
+ a
31
+ end
32
+ end
33
+
34
+
35
+
25
36
  end
26
37
  end
@@ -0,0 +1 @@
1
+ dc_param: value for dc1
@@ -0,0 +1 @@
1
+ dc_param: value for dc2
@@ -43,6 +43,24 @@ describe Hieracles::Interpolate do
43
43
  end
44
44
  end
45
45
 
46
+ describe '.extract' do
47
+ context 'with a single var' do
48
+ let(:data) { 'something_%{a_var}' }
49
+ let(:expected) { [ 'a_var' ] }
50
+ it { expect(extract data).to eq expected }
51
+ end
52
+ context 'with a 2 vars' do
53
+ let(:data) { "something_%{a_var}\nanother %{one}" }
54
+ let(:expected) { [ 'a_var', 'one' ] }
55
+ it { expect(extract data).to eq expected }
56
+ end
57
+ context 'with a 2 identical vars' do
58
+ let(:data) { "something_%{a_var}\nanother %{a_var}" }
59
+ let(:expected) { [ 'a_var' ] }
60
+ it { expect(extract data).to eq expected }
61
+ end
62
+ end
63
+
46
64
  describe ".ask_about" do
47
65
  end
48
66
 
@@ -54,4 +54,39 @@ describe Hieracles::Registry do
54
54
  it { expect(Hieracles::Registry.modules config).to eq expected }
55
55
  end
56
56
 
57
+ describe '.nodes_data' do
58
+ let(:options) do
59
+ {
60
+ config: 'spec/files/config.yml',
61
+ basepath: 'spec/files'
62
+ }
63
+ end
64
+ let(:expected) {
65
+ {
66
+ 'server.example.com' => {
67
+ 'country' => 'fr',
68
+ 'datacenter' => 'equinix',
69
+ 'farm' => 'dev'
70
+ },
71
+ 'server2.example.com' => {
72
+ 'country' => 'fr',
73
+ 'datacenter' => 'equinix',
74
+ 'farm' => 'dev2'
75
+ },
76
+ 'server3.example.com' => {
77
+ 'country' => 'fr',
78
+ 'datacenter' => 'equinix',
79
+ 'farm' => 'dev3'
80
+ },
81
+ 'server4.example.com' => {
82
+ 'country' => 'fr',
83
+ 'datacenter' => 'equinix',
84
+ 'farm' => 'dev2'
85
+ }
86
+ }
87
+ }
88
+ let(:config) { Hieracles::Config.new options }
89
+ it { expect(Hieracles::Registry.nodes_data config).to eq expected }
90
+ end
91
+
57
92
  end
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -203,6 +203,8 @@ files:
203
203
  - spec/files/modules/faux_module2/manifests/init.pp
204
204
  - spec/files/params/common/common.yml
205
205
  - spec/files/params/farm/dev.yaml
206
+ - spec/files/params/farm_datacenter/dev_dc1.yaml
207
+ - spec/files/params/farm_datacenter/dev_dc2.yaml
206
208
  - spec/files/params/nodes/server.example.com.yaml
207
209
  - spec/files/ssl/bad-ca.crt
208
210
  - spec/files/ssl/bad-cert.crt
@@ -256,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
258
  version: '0'
257
259
  requirements: []
258
260
  rubyforge_project:
259
- rubygems_version: 2.4.6
261
+ rubygems_version: 2.5.1
260
262
  signing_key:
261
263
  specification_version: 4
262
264
  summary: CLI tool for Hiera parameters visualization.
@@ -275,6 +277,8 @@ test_files:
275
277
  - spec/files/params/nodes/server.example.com.yaml
276
278
  - spec/files/params/farm/dev.yaml
277
279
  - spec/files/params/common/common.yml
280
+ - spec/files/params/farm_datacenter/dev_dc1.yaml
281
+ - spec/files/params/farm_datacenter/dev_dc2.yaml
278
282
  - spec/files/hiera_no_yamlbackend.yaml
279
283
  - spec/files/ssl/key.pem
280
284
  - spec/files/ssl/bad-cert.crt