puppet-ghostbuster 0.9.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +17 -0
- data/.github/workflows/release.yml +33 -0
- data/.github/workflows/test.yml +57 -0
- data/.gitignore +5 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +173 -0
- data/CHANGELOG.md +226 -95
- data/Gemfile +13 -1
- data/README.md +20 -5
- data/Rakefile +31 -9
- data/lib/puppet-ghostbuster/puppetdb.rb +35 -9
- data/lib/puppet-ghostbuster/util.rb +19 -0
- data/lib/puppet-ghostbuster/version.rb +1 -1
- data/lib/puppet-lint/plugins/check_ghostbuster_classes.rb +4 -4
- data/lib/puppet-lint/plugins/check_ghostbuster_defines.rb +4 -5
- data/lib/puppet-lint/plugins/check_ghostbuster_facts.rb +21 -19
- data/lib/puppet-lint/plugins/check_ghostbuster_files.rb +11 -10
- data/lib/puppet-lint/plugins/check_ghostbuster_functions.rb +9 -8
- data/lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb +45 -33
- data/lib/puppet-lint/plugins/check_ghostbuster_templates.rb +14 -11
- data/lib/puppet-lint/plugins/check_ghostbuster_types.rb +4 -4
- data/puppet-ghostbuster.gemspec +21 -19
- data/spec/fixtures/hiera.yaml +17 -12
- data/spec/fixtures/modules/foo/lib/facter/asym.rb +8 -0
- data/spec/fixtures/modules/foo/lib/facter/bar.rb +2 -0
- data/spec/fixtures/modules/foo/lib/facter/baz.rb +2 -0
- data/spec/fixtures/modules/foo/lib/facter/foo.rb +2 -0
- data/spec/fixtures/modules/foo/lib/facter/multi.rb +2 -0
- data/spec/fixtures/modules/foo/lib/facter/quux.rb +2 -0
- data/spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb +8 -2
- data/spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb +8 -2
- data/spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb +8 -2
- data/spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb +8 -2
- data/spec/fixtures/modules/foo/lib/puppet/type/bar.rb +2 -0
- data/spec/fixtures/modules/foo/lib/puppet/type/foo.rb +2 -0
- data/spec/puppet-lint/plugins/ghostbuster_classes_spec.rb +10 -9
- data/spec/puppet-lint/plugins/ghostbuster_defines_spec.rb +11 -11
- data/spec/puppet-lint/plugins/ghostbuster_facts_spec.rb +33 -20
- data/spec/puppet-lint/plugins/ghostbuster_files_spec.rb +25 -25
- data/spec/puppet-lint/plugins/ghostbuster_functions_spec.rb +16 -15
- data/spec/puppet-lint/plugins/ghostbuster_hiera_files_spec.rb +54 -30
- data/spec/puppet-lint/plugins/ghostbuster_templates_spec.rb +17 -16
- data/spec/puppet-lint/plugins/ghostbuster_types_spec.rb +10 -9
- data/spec/spec_helper.rb +34 -34
- metadata +78 -36
- data/.travis.yml +0 -20
@@ -1,28 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_defines' do
|
4
|
-
|
5
6
|
context 'with fix disabled' do
|
6
|
-
|
7
7
|
context 'when define is not used' do
|
8
|
-
let(:code) {
|
9
|
-
let(:path) {
|
8
|
+
let(:code) { 'define foo::foo {}' }
|
9
|
+
let(:path) { './modules/foo/manifests/foo.pp' }
|
10
10
|
|
11
|
-
it '
|
12
|
-
expect(problems).to
|
11
|
+
it 'detects one problem' do
|
12
|
+
expect(problems.size).to eq(1)
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
15
|
+
it 'creates a warning' do
|
16
16
|
expect(problems).to contain_warning('Define Foo::Foo seems unused')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'when define is used' do
|
21
|
-
let(:code) {
|
22
|
-
let(:path) {
|
21
|
+
let(:code) { 'define bar::foo {}' }
|
22
|
+
let(:path) { './modules/bar/manifests/foo.pp' }
|
23
23
|
|
24
|
-
it '
|
25
|
-
expect(problems).to
|
24
|
+
it 'does not detect any problem' do
|
25
|
+
expect(problems.size).to eq(0)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,55 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_facts' do
|
4
6
|
let(:code) { "Facter.add('foo')" }
|
5
7
|
|
6
8
|
context 'with fix disabled' do
|
7
|
-
|
8
9
|
context 'when fact is not used' do
|
9
|
-
let(:path) {
|
10
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/multi.rb' }
|
10
11
|
|
11
|
-
it '
|
12
|
-
expect(problems).to
|
12
|
+
it 'detects one problem' do
|
13
|
+
expect(problems.size).to eq(2)
|
13
14
|
end
|
14
15
|
|
15
|
-
it '
|
16
|
-
expect(problems).to contain_warning(
|
16
|
+
it 'creates a warning' do
|
17
|
+
expect(problems).to contain_warning('Fact multi1 seems unused')
|
17
18
|
end
|
18
19
|
|
19
|
-
it '
|
20
|
-
expect(problems).to contain_warning(
|
20
|
+
it 'creates a warning' do
|
21
|
+
expect(problems).to contain_warning('Fact multi2 seems unused')
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
context 'when fact is used in a string' do
|
25
|
-
let(:path) {
|
26
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/foo.rb' }
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(problems).to
|
28
|
+
it 'does not detect any problem' do
|
29
|
+
expect(problems.size).to eq(0)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
context 'when fact is used in manifest' do
|
33
|
-
let(:path) {
|
34
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/bar.rb' }
|
34
35
|
|
35
|
-
it '
|
36
|
-
expect(problems).to
|
36
|
+
it 'does not detect any problem' do
|
37
|
+
expect(problems.size).to eq(0)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
context 'when fact is used in a template' do
|
41
|
-
let(:path) {
|
42
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/baz.rb' }
|
42
43
|
|
43
|
-
it '
|
44
|
-
expect(problems).to
|
44
|
+
it 'does not detect any problem' do
|
45
|
+
expect(problems.size).to eq(0)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
context 'when fact is used in an inline_template' do
|
49
|
-
let(:path) {
|
50
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/quux.rb' }
|
51
|
+
|
52
|
+
it 'does not detect any problem' do
|
53
|
+
expect(problems.size).to eq(0)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when added fact is a symbol and unused' do
|
58
|
+
let(:path) { './spec/fixtures/modules/foo/lib/facter/asym.rb' }
|
59
|
+
|
60
|
+
it 'detects one problem' do
|
61
|
+
expect(problems.size).to eq(1)
|
62
|
+
end
|
50
63
|
|
51
|
-
it '
|
52
|
-
expect(problems).to
|
64
|
+
it 'creates a warning' do
|
65
|
+
expect(problems).to contain_warning('Fact asym seems unused')
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
@@ -1,64 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_files' do
|
4
|
-
|
5
|
-
let(:code) { "" }
|
6
|
+
let(:code) { '' }
|
6
7
|
|
7
8
|
context 'with fix disabled' do
|
8
|
-
|
9
9
|
context 'when file usage is found in puppetdb' do
|
10
|
-
let(:path) {
|
10
|
+
let(:path) { './modules/foo/files/bar' }
|
11
11
|
|
12
|
-
it '
|
13
|
-
expect(problems).to
|
12
|
+
it 'does not detect any problem' do
|
13
|
+
expect(problems.size).to eq(0)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when parent directory with recurse => true usage is found in puppetdb' do
|
18
|
-
let(:path) {
|
18
|
+
let(:path) { './modules/foo/files/baz/baz' }
|
19
19
|
|
20
|
-
it '
|
21
|
-
expect(problems).to
|
20
|
+
it 'does not detect any problem' do
|
21
|
+
expect(problems.size).to eq(0)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when using full module name syntax' do
|
26
|
-
let(:path) {
|
26
|
+
let(:path) { './modules/foo/files/used_with_file' }
|
27
27
|
|
28
|
-
it '
|
29
|
-
expect(problems).to
|
28
|
+
it 'does not detect any problem' do
|
29
|
+
expect(problems.size).to eq(0)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'when using $module_name syntax' do
|
34
|
-
let(:path) {
|
34
|
+
let(:path) { './modules/foo/files/used_with_file_and_module_name' }
|
35
35
|
|
36
|
-
it '
|
37
|
-
expect(problems).to
|
36
|
+
it 'does not detect any problem' do
|
37
|
+
expect(problems.size).to eq(0)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'when file in ROOT is not used' do
|
42
|
-
let(:path) {
|
42
|
+
let(:path) { './modules/bar/files/foo' }
|
43
43
|
|
44
|
-
it '
|
45
|
-
expect(problems).to
|
44
|
+
it 'detects one problem' do
|
45
|
+
expect(problems.size).to eq(1)
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
49
|
-
expect(problems).to contain_warning(
|
48
|
+
it 'creates a warning' do
|
49
|
+
expect(problems).to contain_warning('File bar/foo seems unused')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'when file in subdir is not used' do
|
54
|
-
let(:path) {
|
54
|
+
let(:path) { './modules/bar/files/foo/bar' }
|
55
55
|
|
56
|
-
it '
|
57
|
-
expect(problems).to
|
56
|
+
it 'detects one problem' do
|
57
|
+
expect(problems.size).to eq(1)
|
58
58
|
end
|
59
59
|
|
60
|
-
it '
|
61
|
-
expect(problems).to contain_warning(
|
60
|
+
it 'creates a warning' do
|
61
|
+
expect(problems).to contain_warning('File bar/foo/bar seems unused')
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -1,43 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_functions' do
|
4
6
|
let(:code) { '' }
|
5
7
|
|
6
8
|
context 'with fix disabled' do
|
7
|
-
|
8
9
|
context 'when function is not used' do
|
9
|
-
let(:path) {
|
10
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb' }
|
10
11
|
|
11
|
-
it '
|
12
|
-
expect(problems).to
|
12
|
+
it 'detects one problem' do
|
13
|
+
expect(problems.size).to eq(1)
|
13
14
|
end
|
14
15
|
|
15
|
-
it '
|
16
|
-
expect(problems).to contain_warning(
|
16
|
+
it 'creates a warning' do
|
17
|
+
expect(problems).to contain_warning('Function foo seems unused')
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
context 'when function is used in a manifest' do
|
21
|
-
let(:path) {
|
22
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb' }
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(problems).to
|
24
|
+
it 'does not detect any problem' do
|
25
|
+
expect(problems.size).to eq(0)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
context 'when function is used in a template using scope.function_baz()' do
|
29
|
-
let(:path) {
|
30
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb' }
|
30
31
|
|
31
|
-
it '
|
32
|
-
expect(problems).to
|
32
|
+
it 'does not detect any problem' do
|
33
|
+
expect(problems.size).to eq(0)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
context 'when function is used in a template using Puppet::Parser::Functions.function(:quux)' do
|
37
|
-
let(:path) {
|
38
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb' }
|
38
39
|
|
39
|
-
it '
|
40
|
-
expect(problems).to
|
40
|
+
it 'does not detect any problem' do
|
41
|
+
expect(problems.size).to eq(0)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,78 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
ENV['HIERA_YAML_PATH'] = './spec/fixtures/hiera.yaml'
|
4
6
|
|
5
7
|
describe 'ghostbuster_hiera_files' do
|
6
|
-
|
7
|
-
let(:code) { "" }
|
8
|
+
let(:code) { '' }
|
8
9
|
|
9
10
|
context 'with fix disabled' do
|
10
|
-
|
11
11
|
context 'when a certname file is NOT used' do
|
12
|
-
let(:path) {
|
12
|
+
let(:path) { './data/nodes/foo.example.com.yaml' }
|
13
13
|
|
14
|
-
it '
|
15
|
-
expect(problems).to
|
14
|
+
it 'detects one problem' do
|
15
|
+
expect(problems.size).to eq(1)
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
19
|
-
expect(problems).to contain_warning("Hiera File
|
18
|
+
it 'creates a warning' do
|
19
|
+
expect(problems).to contain_warning("Hiera File #{path} seems unused")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when a certname file is used' do
|
24
|
-
let(:path) {
|
24
|
+
let(:path) { './data/nodes/bar.example.com.yaml' }
|
25
25
|
|
26
|
-
it '
|
27
|
-
expect(problems).to
|
26
|
+
it 'does not detect any problem' do
|
27
|
+
expect(problems.size).to eq(0)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when an environment file is NOT used' do
|
32
|
-
let(:path) {
|
32
|
+
let(:path) { './data/environment/foo.yaml' }
|
33
33
|
|
34
|
-
it '
|
35
|
-
expect(problems).to
|
34
|
+
it 'detects one problem' do
|
35
|
+
expect(problems.size).to eq(1)
|
36
36
|
end
|
37
37
|
|
38
|
-
it '
|
39
|
-
expect(problems).to contain_warning("Hiera File
|
38
|
+
it 'creates a warning' do
|
39
|
+
expect(problems).to contain_warning("Hiera File #{path} seems unused")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'when an environment file is used' do
|
44
|
-
let(:path) {
|
44
|
+
let(:path) { './data/environment/production.yaml' }
|
45
45
|
|
46
|
-
it '
|
47
|
-
expect(problems).to
|
46
|
+
it 'does not detect any problem' do
|
47
|
+
expect(problems.size).to eq(0)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'when an fact is NOT used' do
|
52
|
-
let(:path) {
|
52
|
+
let(:path) { './data/virtual/false.yaml' }
|
53
53
|
|
54
|
-
it '
|
55
|
-
expect(problems).to
|
54
|
+
it 'detects one problem' do
|
55
|
+
expect(problems.size).to eq(1)
|
56
56
|
end
|
57
57
|
|
58
|
-
it '
|
59
|
-
expect(problems).to contain_warning("Hiera File
|
58
|
+
it 'creates a warning' do
|
59
|
+
expect(problems).to contain_warning("Hiera File #{path} seems unused")
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when an fact file is used' do
|
64
|
-
let(:path) {
|
64
|
+
let(:path) { './data/virtual/true.yaml' }
|
65
|
+
|
66
|
+
it 'does not detect any problem' do
|
67
|
+
expect(problems.size).to eq(0)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when an fact file is used with wrong extension' do
|
72
|
+
let(:path) { './data/virtual/true.eyaml' }
|
73
|
+
|
74
|
+
it 'detects one problem' do
|
75
|
+
expect(problems.size).to eq(1)
|
76
|
+
end
|
65
77
|
|
66
|
-
it '
|
67
|
-
expect(problems).to
|
78
|
+
it 'creates a warning' do
|
79
|
+
expect(problems).to contain_warning("Hiera File #{path} seems unused")
|
68
80
|
end
|
69
81
|
end
|
70
82
|
|
71
83
|
context 'when using a variable in hierarchy' do
|
72
|
-
let(:path) {
|
84
|
+
let(:path) { './data/domain/example.com.yaml' }
|
85
|
+
|
86
|
+
it 'does not detect any problem' do
|
87
|
+
expect(problems.size).to eq(0)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when hierarchy datadir is NOT default and NOT used' do
|
92
|
+
let(:path) { './private/nodes/privates.example.com.eyaml' }
|
93
|
+
|
94
|
+
it 'detects one problem' do
|
95
|
+
expect(problems.size).to eq(1)
|
96
|
+
end
|
73
97
|
|
74
|
-
it '
|
75
|
-
expect(problems).to
|
98
|
+
it 'creates a warning' do
|
99
|
+
expect(problems).to contain_warning("Hiera File #{path} seems unused")
|
76
100
|
end
|
77
101
|
end
|
78
102
|
end
|
@@ -1,43 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_templates' do
|
4
|
-
let(:code) {
|
6
|
+
let(:code) { '' }
|
5
7
|
|
6
8
|
context 'with fix disabled' do
|
7
|
-
|
8
9
|
context 'when using full module name syntax' do
|
9
|
-
let(:path) {
|
10
|
+
let(:path) { './modules/foo/templates/used_with_template' }
|
10
11
|
|
11
|
-
it '
|
12
|
-
expect(problems).to
|
12
|
+
it 'does not detect any problem' do
|
13
|
+
expect(problems.size).to eq(0)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
context 'when using $module_name syntax' do
|
17
|
-
let(:path) {
|
18
|
+
let(:path) { './modules/foo/templates/used_with_template_and_module_name' }
|
18
19
|
|
19
|
-
it '
|
20
|
-
expect(problems).to
|
20
|
+
it 'does not detect any problem' do
|
21
|
+
expect(problems.size).to eq(0)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
context 'when using template in template' do
|
25
|
-
let(:path) {
|
26
|
+
let(:path) { './modules/foo/templates/used_in_template.erb' }
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(problems).to
|
28
|
+
it 'does not detect any problem' do
|
29
|
+
expect(problems.size).to eq(0)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
context 'when template usage is not found in manifests' do
|
33
|
-
let(:path) {
|
34
|
+
let(:path) { './modules/foo/templates/unused' }
|
34
35
|
|
35
|
-
it '
|
36
|
-
expect(problems).to
|
36
|
+
it 'detects one problem' do
|
37
|
+
expect(problems.size).to eq(1)
|
37
38
|
end
|
38
39
|
|
39
|
-
it '
|
40
|
-
expect(problems).to contain_warning(
|
40
|
+
it 'creates a warning' do
|
41
|
+
expect(problems).to contain_warning('Template foo/unused seems unused')
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,27 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'ghostbuster_types' do
|
4
6
|
let(:code) { '' }
|
5
7
|
|
6
8
|
context 'with fix disabled' do
|
7
|
-
|
8
9
|
context 'when type is not used' do
|
9
|
-
let(:path) {
|
10
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/type/foo.rb' }
|
10
11
|
|
11
|
-
it '
|
12
|
-
expect(problems).to
|
12
|
+
it 'detects one problem' do
|
13
|
+
expect(problems.size).to eq(1)
|
13
14
|
end
|
14
15
|
|
15
|
-
it '
|
16
|
-
expect(problems).to contain_warning(
|
16
|
+
it 'creates a warning' do
|
17
|
+
expect(problems).to contain_warning('Type Foo seems unused')
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
context 'when type is used in a manifest' do
|
21
|
-
let(:path) {
|
22
|
+
let(:path) { './spec/fixtures/modules/foo/lib/puppet/type/bar.rb' }
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(problems).to
|
24
|
+
it 'does not detect any problem' do
|
25
|
+
expect(problems.size).to eq(0)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ PuppetLint::Plugins.load_spec_helper
|
|
5
5
|
|
6
6
|
class PuppetDB::Client
|
7
7
|
def puppetdb_to_jgrep(query)
|
8
|
-
if query[0] == :
|
8
|
+
if query[0] == :and || query[0] == :or
|
9
9
|
"(#{puppetdb_to_jgrep(query[1])} #{query[0]} #{puppetdb_to_jgrep(query[2])})"
|
10
10
|
else
|
11
11
|
"#{[query[1]].flatten.join('.')}#{query[0]}#{query[2]}"
|
@@ -13,50 +13,50 @@ class PuppetDB::Client
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def process_pql_kv(q)
|
16
|
-
|
17
|
-
|
16
|
+
k, v = q.split(/\s*=\s*/)
|
17
|
+
".#{k}=#{v}"
|
18
18
|
end
|
19
19
|
|
20
20
|
def pql_to_jgrep(query)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
jgrep_query_and_parts << newq
|
21
|
+
endpoint_cols = query.split('{').first
|
22
|
+
endpoint = endpoint_cols.split(/[\s\[]/).first
|
23
|
+
query.sub!(/^#{Regexp.quote(endpoint_cols)}\{\s*/, '')
|
24
|
+
query.sub!(/(group\s+by\s+(type|title))/, '')
|
25
|
+
query.sub!(/\s*}\s*/, '')
|
26
|
+
query.sub!(/(and\s+)?nodes\s*\{\s*deactivated\s+is\s+null\s*\}/, '')
|
27
|
+
|
28
|
+
return endpoint, '' if query == ''
|
29
|
+
|
30
|
+
query.gsub!('parameters.', 'parameter.')
|
31
|
+
query.sub!(/\s*=\s*/, '=')
|
32
|
+
|
33
|
+
jgrep_query_and_parts = []
|
34
|
+
query.split(/\s+and\s+/).each do |q|
|
35
|
+
newq = ''
|
36
|
+
if q.start_with?('(')
|
37
|
+
newq << '('
|
38
|
+
newq << q.split(/\s+or\s+/).map do |qq|
|
39
|
+
process_pql_kv(qq.sub(/^\(/, '').sub(/\)$/, ''))
|
40
|
+
end.join(' or ')
|
41
|
+
newq << ')'
|
42
|
+
else
|
43
|
+
newq << process_pql_kv(q)
|
45
44
|
end
|
46
|
-
|
47
|
-
|
45
|
+
jgrep_query_and_parts << newq
|
46
|
+
end
|
47
|
+
jgrep_query = jgrep_query_and_parts.join(' and ')
|
48
|
+
jgrep_query.rstrip!
|
48
49
|
|
49
|
-
|
50
|
+
[endpoint, jgrep_query]
|
50
51
|
end
|
51
52
|
|
52
|
-
def request(endpoint, query,
|
53
|
+
def request(endpoint, query, _opts = {})
|
53
54
|
if endpoint == ''
|
54
|
-
|
55
|
+
endpoint, query = pql_to_jgrep(query)
|
55
56
|
else
|
56
|
-
|
57
|
+
query = puppetdb_to_jgrep(query)
|
57
58
|
end
|
58
59
|
ret = JGrep.jgrep(File.read("spec/fixtures/#{endpoint}.json"), query)
|
59
60
|
PuppetDB::Response.new(ret, ret.size)
|
60
61
|
end
|
61
62
|
end
|
62
|
-
|