hieracles 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +2 -0
  4. data/README.md +54 -8
  5. data/bin/hc +12 -6
  6. data/bin/ppdb +42 -0
  7. data/hc.1 +50 -8
  8. data/lib/hieracles.rb +2 -2
  9. data/lib/hieracles/config.rb +31 -19
  10. data/lib/hieracles/format.rb +4 -0
  11. data/lib/hieracles/formats/console.rb +49 -16
  12. data/lib/hieracles/formats/csv.rb +12 -8
  13. data/lib/hieracles/formats/json.rb +19 -6
  14. data/lib/hieracles/formats/plain.rb +24 -3
  15. data/lib/hieracles/formats/rawyaml.rb +4 -0
  16. data/lib/hieracles/formats/yaml.rb +4 -0
  17. data/lib/hieracles/node.rb +55 -10
  18. data/lib/hieracles/notification.rb +31 -0
  19. data/lib/hieracles/options/hc.rb +109 -0
  20. data/lib/hieracles/options/ppdb.rb +32 -0
  21. data/lib/hieracles/optparse.rb +4 -43
  22. data/lib/hieracles/puppetdb.rb +12 -0
  23. data/lib/hieracles/puppetdb/apierror.rb +10 -0
  24. data/lib/hieracles/puppetdb/client.rb +63 -0
  25. data/lib/hieracles/puppetdb/filter.rb +15 -0
  26. data/lib/hieracles/puppetdb/fixsslconnectionadapter.rb +25 -0
  27. data/lib/hieracles/puppetdb/query.rb +79 -0
  28. data/lib/hieracles/puppetdb/request.rb +44 -0
  29. data/lib/hieracles/puppetdb/response.rb +14 -0
  30. data/ppdb.1 +158 -0
  31. data/spec/files/config.yml +2 -0
  32. data/spec/files/config_withdb.yml +9 -0
  33. data/spec/files/facts.json +110 -0
  34. data/spec/files/facts.yaml +103 -0
  35. data/spec/files/hiera_columns.yaml +16 -0
  36. data/spec/files/hiera_deep.yaml +17 -0
  37. data/spec/files/hiera_deeper.yaml +17 -0
  38. data/spec/files/ssl/bad-ca.crt +1 -0
  39. data/spec/files/ssl/bad-cert.crt +1 -0
  40. data/spec/files/ssl/bad-key.pem +1 -0
  41. data/spec/files/ssl/ca.crt +16 -0
  42. data/spec/files/ssl/cert.crt +16 -0
  43. data/spec/files/ssl/key-pass.pem +18 -0
  44. data/spec/files/ssl/key.pem +15 -0
  45. data/spec/lib/config_spec.rb +51 -11
  46. data/spec/lib/format_spec.rb +5 -0
  47. data/spec/lib/formats/console_spec.rb +24 -3
  48. data/spec/lib/formats/csv_spec.rb +15 -0
  49. data/spec/lib/formats/json_spec.rb +22 -2
  50. data/spec/lib/formats/plain_spec.rb +23 -3
  51. data/spec/lib/formats/rawyaml_spec.rb +13 -0
  52. data/spec/lib/formats/yaml_spec.rb +138 -48
  53. data/spec/lib/hiera_spec.rb +0 -1
  54. data/spec/lib/hieracles_spec.rb +8 -0
  55. data/spec/lib/interpolate_spec.rb +49 -0
  56. data/spec/lib/node_spec.rb +50 -9
  57. data/spec/lib/notification_spec.rb +29 -0
  58. data/spec/lib/options/hc_spec.rb +82 -0
  59. data/spec/lib/optparse_spec.rb +7 -7
  60. data/spec/lib/puppetdb/apierror_spec.rb +11 -0
  61. data/spec/lib/puppetdb/client_spec.rb +64 -0
  62. data/spec/lib/puppetdb/fixsslconnectionadapter_spec.rb +107 -0
  63. data/spec/lib/puppetdb/query_spec.rb +39 -0
  64. data/spec/lib/puppetdb/request_spec.rb +61 -0
  65. data/spec/lib/puppetdb/response_spec.rb +13 -0
  66. data/spec/spec_helper.rb +4 -4
  67. metadata +133 -30
  68. data/Rakefile +0 -14
  69. data/hieracles.gemspec +0 -90
  70. data/lib/hieracles/help.rb +0 -38
  71. data/spec/lib/help_spec.rb +0 -8
@@ -17,6 +17,11 @@ describe Hieracles::Format do
17
17
  expect(dispatch.info nil).to eq format(not_implemented, 'info')
18
18
  end
19
19
  end
20
+ describe ".facts" do
21
+ it "returns a message informing that this class should be inherited" do
22
+ expect(dispatch.facts nil).to eq format(not_implemented, 'facts')
23
+ end
24
+ end
20
25
  describe ".files" do
21
26
  it "returns a message informing that this class should be inherited" do
22
27
  expect(dispatch.files nil).to eq format(not_implemented, 'files')
@@ -16,19 +16,40 @@ describe Hieracles::Formats::Console do
16
16
  'Farm' => 'farm'
17
17
  }
18
18
  )
19
+ allow(node).to receive(:notifications).and_return(nil)
19
20
  }
20
21
  it "outputs proper text" do
21
- expect(console_format.info nil).to eq expected
22
+ expect(console_format.info []).to eq expected
22
23
  end
23
24
  end
24
25
 
26
+ describe ".facts" do
27
+ let(:expected) {
28
+ "\e[97mNode \e[0m fqdn\n" +
29
+ "\e[97mFarm \e[0m farm\n"
30
+ }
31
+ before {
32
+ allow(node).to receive(:facts).and_return(
33
+ {
34
+ 'Node' => 'fqdn',
35
+ 'Farm' => 'farm'
36
+ }
37
+ )
38
+ allow(node).to receive(:notifications).and_return(nil)
39
+ }
40
+ it "outputs proper text" do
41
+ expect(console_format.facts []).to eq expected
42
+ end
43
+ end
44
+
45
+
25
46
  describe ".files" do
26
47
  let(:expected) { "path1\npath2\n" }
27
48
  before {
28
49
  allow(node).to receive(:files).and_return(['path1', 'path2'])
29
50
  }
30
51
  it "outputs proper text" do
31
- expect(console_format.files nil).to eq expected
52
+ expect(console_format.files []).to eq expected
32
53
  end
33
54
  end
34
55
 
@@ -38,7 +59,7 @@ describe Hieracles::Formats::Console do
38
59
  allow(node).to receive(:paths).and_return(['path1', 'path2'])
39
60
  }
40
61
  it "outputs proper text" do
41
- expect(console_format.paths nil).to eq expected
62
+ expect(console_format.paths []).to eq expected
42
63
  end
43
64
  end
44
65
 
@@ -19,6 +19,21 @@ describe Hieracles::Formats::Csv do
19
19
  end
20
20
  end
21
21
 
22
+ describe ".facts" do
23
+ let(:expected) {"Node;Farm\nfqdn;farm\n"}
24
+ before {
25
+ allow(node).to receive(:facts).and_return(
26
+ {
27
+ 'Node' => 'fqdn',
28
+ 'Farm' => 'farm'
29
+ }
30
+ )
31
+ }
32
+ it "outputs proper text" do
33
+ expect(csv_format.facts nil).to eq expected
34
+ end
35
+ end
36
+
22
37
  describe ".files" do
23
38
  let(:expected) { "path1;path2\n" }
24
39
  before {
@@ -13,22 +13,39 @@ describe Hieracles::Formats::Json do
13
13
  'Farm' => 'farm'
14
14
  }
15
15
  )
16
+ allow(node).to receive(:notifications).and_return([])
16
17
  }
17
18
  it { expect(json_format.info nil).to eq expected }
18
19
  end
19
20
 
21
+ describe ".facts" do
22
+ let(:expected) { '{"Node":"fqdn","Farm":"farm"}' }
23
+ before {
24
+ allow(node).to receive(:facts).and_return(
25
+ {
26
+ 'Node' => 'fqdn',
27
+ 'Farm' => 'farm'
28
+ }
29
+ )
30
+ allow(node).to receive(:notifications).and_return([])
31
+ }
32
+ it { expect(json_format.facts nil).to eq expected }
33
+ end
34
+
20
35
  describe ".files" do
21
- let(:expected) { '["path1","path2"]' }
36
+ let(:expected) { '{"files":["path1","path2"]}' }
22
37
  before {
23
38
  allow(node).to receive(:files).and_return(['path1', 'path2'])
39
+ allow(node).to receive(:notifications).and_return([])
24
40
  }
25
41
  it { expect(json_format.files nil).to eq expected }
26
42
  end
27
43
 
28
44
  describe ".paths" do
29
- let(:expected) { '["path1","path2"]' }
45
+ let(:expected) { '{"paths":["path1","path2"]}' }
30
46
  before {
31
47
  allow(node).to receive(:paths).and_return(['path1', 'path2'])
48
+ allow(node).to receive(:notifications).and_return([])
32
49
  }
33
50
  it { expect(json_format.paths nil).to eq expected }
34
51
  end
@@ -43,6 +60,7 @@ describe Hieracles::Formats::Json do
43
60
  'longmodule2' => "not found"
44
61
  }
45
62
  )
63
+ allow(node).to receive(:notifications).and_return([])
46
64
  }
47
65
  it { expect(json_format.modules nil).to eq expected }
48
66
  end
@@ -59,6 +77,7 @@ describe Hieracles::Formats::Json do
59
77
  }
60
78
  }
61
79
  )
80
+ allow(node).to receive(:notifications).and_return([])
62
81
  }
63
82
  it { expect(json_format.params nil).to eq expected }
64
83
  end
@@ -75,6 +94,7 @@ describe Hieracles::Formats::Json do
75
94
  }
76
95
  }
77
96
  )
97
+ allow(node).to receive(:notifications).and_return([])
78
98
  }
79
99
  it { expect(json_format.allparams nil).to eq expected }
80
100
  end
@@ -16,9 +16,29 @@ describe Hieracles::Formats::Plain do
16
16
  'Farm' => 'farm'
17
17
  }
18
18
  )
19
+ allow(node).to receive(:notifications).and_return(nil)
19
20
  }
20
21
  it "outputs proper text" do
21
- expect(plain_format.info nil).to eq expected
22
+ expect(plain_format.info []).to eq expected
23
+ end
24
+ end
25
+
26
+ describe ".facts" do
27
+ let(:expected) {
28
+ "Node fqdn\n" +
29
+ "Farm farm\n"
30
+ }
31
+ before {
32
+ allow(node).to receive(:facts).and_return(
33
+ {
34
+ 'Node' => 'fqdn',
35
+ 'Farm' => 'farm'
36
+ }
37
+ )
38
+ allow(node).to receive(:notifications).and_return(nil)
39
+ }
40
+ it "outputs proper text" do
41
+ expect(plain_format.facts []).to eq expected
22
42
  end
23
43
  end
24
44
 
@@ -28,7 +48,7 @@ describe Hieracles::Formats::Plain do
28
48
  allow(node).to receive(:files).and_return(['path1', 'path2'])
29
49
  }
30
50
  it "outputs proper text" do
31
- expect(plain_format.files nil).to eq expected
51
+ expect(plain_format.files []).to eq expected
32
52
  end
33
53
  end
34
54
 
@@ -38,7 +58,7 @@ describe Hieracles::Formats::Plain do
38
58
  allow(node).to receive(:paths).and_return(['path1', 'path2'])
39
59
  }
40
60
  it "outputs proper text" do
41
- expect(plain_format.paths nil).to eq expected
61
+ expect(plain_format.paths []).to eq expected
42
62
  end
43
63
  end
44
64
 
@@ -17,6 +17,19 @@ describe Hieracles::Formats::Rawyaml do
17
17
  it { expect(yaml_format.info nil).to eq expected }
18
18
  end
19
19
 
20
+ describe ".facts" do
21
+ let(:expected) {"---\nNode: fqdn\nFarm: farm\n"}
22
+ before {
23
+ allow(node).to receive(:facts).and_return(
24
+ {
25
+ 'Node' => 'fqdn',
26
+ 'Farm' => 'farm'
27
+ }
28
+ )
29
+ }
30
+ it { expect(yaml_format.facts nil).to eq expected }
31
+ end
32
+
20
33
  describe ".files" do
21
34
  let(:expected) { "---\n- path1\n- path2\n" }
22
35
  before {
@@ -17,6 +17,19 @@ describe Hieracles::Formats::Yaml do
17
17
  it { expect(yaml_format.info nil).to eq expected }
18
18
  end
19
19
 
20
+ describe ".facts" do
21
+ let(:expected) {"---\nNode: fqdn\nFarm: farm\n"}
22
+ before {
23
+ allow(node).to receive(:facts).and_return(
24
+ {
25
+ 'Node' => 'fqdn',
26
+ 'Farm' => 'farm'
27
+ }
28
+ )
29
+ }
30
+ it { expect(yaml_format.facts nil).to eq expected }
31
+ end
32
+
20
33
  describe ".files" do
21
34
  let(:expected) { "---\n- path1\n- path2\n" }
22
35
  before {
@@ -47,61 +60,121 @@ describe Hieracles::Formats::Yaml do
47
60
  end
48
61
 
49
62
  describe ".params" do
50
- let(:expected) {
51
- "---\n" +
52
- "params: \n" +
53
- " this: \n" +
54
- " var: value1 # some/file"
55
- }
56
- before {
57
- allow(node).to receive(:params).and_return(
58
- {
59
- 'params.this.var' => [{
60
- file: 'some/file',
61
- value: 'value1'
62
- }]
63
- }
64
- )
65
- allow(node).to receive(:params_tree).and_return(
66
- {
67
- 'params' => {
68
- 'this' => {
69
- 'var' => 'value1'
63
+ context "with args" do
64
+ let(:expected) {
65
+ "---\n" +
66
+ "params: \n" +
67
+ " this: \n" +
68
+ " var: value1 # some/file"
69
+ }
70
+ before {
71
+ allow(node).to receive(:params).with(true).and_return(
72
+ {
73
+ 'params.this.var' => [{
74
+ file: 'some/file',
75
+ value: 'value1'
76
+ }]
77
+ }
78
+ )
79
+ allow(node).to receive(:params_tree).with(true).and_return(
80
+ {
81
+ 'params' => {
82
+ 'this' => {
83
+ 'var' => 'value1'
84
+ }
70
85
  }
71
86
  }
72
- }
73
- )
74
- }
75
- it { expect(yaml_format.params nil).to eq expected }
87
+ )
88
+ }
89
+ it { expect(yaml_format.params ['some', 'things']).to eq expected }
90
+ end
91
+ context "without args" do
92
+ let(:expected) {
93
+ "---\n" +
94
+ "params: \n" +
95
+ " this: \n" +
96
+ " var: value1 # some/file"
97
+ }
98
+ before {
99
+ allow(node).to receive(:params).and_return(
100
+ {
101
+ 'params.this.var' => [{
102
+ file: 'some/file',
103
+ value: 'value1'
104
+ }]
105
+ }
106
+ )
107
+ allow(node).to receive(:params_tree).and_return(
108
+ {
109
+ 'params' => {
110
+ 'this' => {
111
+ 'var' => 'value1'
112
+ }
113
+ }
114
+ }
115
+ )
116
+ }
117
+ it { expect(yaml_format.params nil).to eq expected }
118
+ end
76
119
  end
77
120
 
78
121
  describe ".allparams" do
79
- let(:expected) {
80
- "---\n"+
81
- "params: \n" +
82
- " this: \n" +
83
- " var: value1 # some/file"
84
- }
85
- before {
86
- allow(node).to receive(:params).and_return(
87
- {
88
- 'params.this.var' => [{
89
- file: 'some/file',
90
- value: 'value1'
91
- }]
92
- }
93
- )
94
- allow(node).to receive(:params_tree).and_return(
95
- {
96
- 'params' => {
97
- 'this' => {
98
- 'var' => 'value1'
122
+ context 'with args' do
123
+ let(:expected) {
124
+ "---\n"+
125
+ "params: \n" +
126
+ " this: \n" +
127
+ " var: value1 # some/file"
128
+ }
129
+ before {
130
+ allow(node).to receive(:params).and_return(
131
+ {
132
+ 'params.this.var' => [{
133
+ file: 'some/file',
134
+ value: 'value1'
135
+ }]
136
+ }
137
+ )
138
+ allow(node).to receive(:params_tree).and_return(
139
+ {
140
+ 'params' => {
141
+ 'this' => {
142
+ 'var' => 'value1'
143
+ }
99
144
  }
100
145
  }
101
- }
102
- )
103
- }
104
- it { expect(yaml_format.allparams nil).to eq expected }
146
+ )
147
+ }
148
+ it { expect(yaml_format.allparams nil).to eq expected }
149
+ end
150
+ context 'without args' do
151
+ let(:expected) {
152
+ "---\n"+
153
+ "params: \n" +
154
+ " this: \n" +
155
+ " var: value1 # some/file"
156
+ }
157
+ before {
158
+ allow(node).to receive(:params).with(false).and_return(
159
+ {
160
+ 'params.this.var' => [{
161
+ file: 'some/file',
162
+ value: 'value1'
163
+ }]
164
+ }
165
+ )
166
+ allow(node).to receive(:params_tree).with(false).and_return(
167
+ {
168
+ 'params' => {
169
+ 'this' => {
170
+ 'var' => 'value1'
171
+ }
172
+ }
173
+ }
174
+ )
175
+ }
176
+ it { expect(yaml_format.allparams ['some', 'things']).to eq expected }
177
+ end
105
178
  end
106
179
 
107
180
  describe '.mergetree' do
@@ -139,6 +212,23 @@ describe Hieracles::Formats::Yaml do
139
212
  }
140
213
  it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
141
214
  end
215
+ context "with various null type of key-values (nil)" do
216
+ let(:params) {
217
+ {
218
+ 'key' => [{
219
+ file: 'what/file',
220
+ value: nil
221
+ }]
222
+ }
223
+ }
224
+ let(:input) {
225
+ { 'key' => nil }
226
+ }
227
+ let(:expected) {
228
+ "\nkey: # what/file"
229
+ }
230
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
231
+ end
142
232
  context "with various boolean type of key-values (false)" do
143
233
  let(:params) {
144
234
  {
@@ -8,7 +8,6 @@ describe Hieracles::Hiera do
8
8
  let(:options) { {
9
9
  basepath: 'spec/files',
10
10
  config: 'spec/files/config.yml',
11
- basepath: 'spec/files',
12
11
  hierafile: 'hiera_no.yaml'
13
12
  } }
14
13
  it 'raises an error' do
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hieracles do
4
+ describe '.version' do
5
+ let(:expected) { File.read(File.expand_path('../../../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/] }
6
+ it { expect(Hieracles.version).to eq expected }
7
+ end
8
+ end