puppet-ghostbuster 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/lib/puppet-ghostbuster/puppetdb.rb +10 -2
- data/lib/puppet-ghostbuster/version.rb +1 -1
- data/lib/puppet-lint/plugins/check_ghostbuster_defines.rb +1 -1
- data/lib/puppet-lint/plugins/check_ghostbuster_files.rb +8 -11
- data/lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb +2 -0
- data/lib/puppet-lint/plugins/check_ghostbuster_types.rb +1 -1
- data/puppet-ghostbuster.gemspec +1 -1
- data/spec/spec_helper.rb +43 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da18d7d720b0464f30e395979feba89136c24299
|
4
|
+
data.tar.gz: 88229a5bd5b2ac831abfacb768d9bcca20406ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64f93ea5cb0909496add62ed2f1b57b62619e5b7bda5713971b37d25190f751daa6ba1c2c4224c601ae7de602c0abf8052bf4be92be8fd6f982688a2d654090
|
7
|
+
data.tar.gz: 8d9fdc6e93bf57aa54bbad62889435a71a2e1fa9c897ddbc84ad159ad95a8d1edec499a88a8acf9814066f3bd30ed26f2d137d3be5f0547cebdfc18c9446029f
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.9.0](https://rubygems.org/gems/puppet-ghostbuster/versions/0.9.0) (2017-08-18)
|
4
|
+
[Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.8.0...0.9.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Use PQL queries to filter out deactivated nodes
|
9
|
+
- Cache known resources
|
10
|
+
- Build on Ruby 2.3.1
|
11
|
+
|
3
12
|
## [0.8.0](https://rubygems.org/gems/puppet-ghostbuster/versions/0.8.0) (2016-09-23)
|
4
13
|
[Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.7.3...0.8.0)
|
5
14
|
|
@@ -4,7 +4,7 @@ class PuppetGhostbuster
|
|
4
4
|
class PuppetDB
|
5
5
|
def self.client
|
6
6
|
@@client ||= ::PuppetDB::Client.new({
|
7
|
-
:server => "#{ENV['PUPPETDB_URL'] || 'http://puppetdb:8080'}
|
7
|
+
:server => "#{ENV['PUPPETDB_URL'] || 'http://puppetdb:8080'}",
|
8
8
|
:pem => {
|
9
9
|
'key' => ENV['PUPPETDB_KEY_FILE'],
|
10
10
|
'cert' => ENV['PUPPETDB_CERT_FILE'],
|
@@ -18,11 +18,19 @@ class PuppetGhostbuster
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.classes
|
21
|
-
@@classes ||= client.request('
|
21
|
+
@@classes ||= client.request('', 'resources[title] { type = "Class" and nodes { deactivated is null } }').data.map { |r| r['title'] }.uniq
|
22
22
|
end
|
23
23
|
|
24
24
|
def classes
|
25
25
|
self.class.classes
|
26
26
|
end
|
27
|
+
|
28
|
+
def self.resources
|
29
|
+
@@resources ||= client.request('', 'resources[type] { nodes { deactivated is null } }').data.map { |r| r['type'] }.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
def resources
|
33
|
+
self.class.resources
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
@@ -24,7 +24,7 @@ PuppetLint.new_check(:ghostbuster_defines) do
|
|
24
24
|
title_token = define_idx[:name_token]
|
25
25
|
type = title_token.value.split('::').map(&:capitalize).join('::')
|
26
26
|
|
27
|
-
return if puppetdb.
|
27
|
+
return if puppetdb.resources.include? type
|
28
28
|
|
29
29
|
notify :warning, {
|
30
30
|
:message => "Define #{type} seems unused",
|
@@ -26,20 +26,17 @@ PuppetLint.new_check(:ghostbuster_files) do
|
|
26
26
|
puppetdb = PuppetGhostbuster::PuppetDB.new
|
27
27
|
|
28
28
|
module_name, file_name = m.captures
|
29
|
-
|
29
|
+
query = "resources[title] { parameters.source = 'puppet:///modules/#{module_name}/#{file_name}' and nodes { deactivated is null } }"
|
30
|
+
return if puppetdb.client.request('', query).data.size > 0
|
30
31
|
|
31
32
|
dir_name = File.dirname(file_name)
|
32
33
|
while dir_name != '.' do
|
33
|
-
|
34
|
-
'
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
],
|
40
|
-
[:'=', ['parameter', 'recurse'], true],
|
41
|
-
],
|
42
|
-
).data.size > 0
|
34
|
+
query = "resources[title] {
|
35
|
+
(parameters.source = 'puppet:///modules/#{module_name}/#{dir_name}'
|
36
|
+
or parameters.source = 'puppet:///modules/#{module_name}/#{dir_name}/')
|
37
|
+
and parameters.recurse = true
|
38
|
+
and nodes { deactivated is null } }"
|
39
|
+
return if puppetdb.client.request('', query).data.size > 0
|
43
40
|
dir_name = File.dirname(dir_name)
|
44
41
|
end
|
45
42
|
|
@@ -26,7 +26,7 @@ PuppetLint.new_check(:ghostbuster_types) do
|
|
26
26
|
type_name = m.captures[0]
|
27
27
|
|
28
28
|
puppetdb = PuppetGhostbuster::PuppetDB.new
|
29
|
-
return if puppetdb.
|
29
|
+
return if puppetdb.resources.include? type_name.capitalize
|
30
30
|
|
31
31
|
notify :warning, {
|
32
32
|
:message => "Type #{type_name.capitalize} seems unused",
|
data/puppet-ghostbuster.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -12,8 +12,50 @@ class PuppetDB::Client
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def process_pql_kv(q)
|
16
|
+
k, v = q.split(/\s*=\s*/)
|
17
|
+
".#{k}=#{v}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def pql_to_jgrep(query)
|
21
|
+
endpoint_cols = query.split('{').first
|
22
|
+
endpoint = endpoint_cols.split(/[\s\[]/).first
|
23
|
+
query.sub!(/^#{Regexp.quote(endpoint_cols)}\{\s*/, '')
|
24
|
+
query.sub!(/\s*}\s*/, '')
|
25
|
+
query.sub!(/(and\s+)?nodes\s*\{\s*deactivated\s+is\s+null\s*\}/, '')
|
26
|
+
|
27
|
+
return endpoint, '' if query == ''
|
28
|
+
|
29
|
+
query.gsub!('parameters.', 'parameter.')
|
30
|
+
query.sub!(/\s*=\s*/, '=')
|
31
|
+
|
32
|
+
jgrep_query_and_parts = []
|
33
|
+
query.split(/\s+and\s+/).each do |q|
|
34
|
+
newq = ''
|
35
|
+
if q.start_with?('(')
|
36
|
+
newq << '('
|
37
|
+
newq << q.split(/\s+or\s+/).map do |qq|
|
38
|
+
process_pql_kv(qq.sub(/^\(/, '').sub(/\)$/, ''))
|
39
|
+
end.join(' or ')
|
40
|
+
newq << ')'
|
41
|
+
else
|
42
|
+
newq << process_pql_kv(q)
|
43
|
+
end
|
44
|
+
jgrep_query_and_parts << newq
|
45
|
+
end
|
46
|
+
jgrep_query = jgrep_query_and_parts.join(" and ")
|
47
|
+
jgrep_query.rstrip!
|
48
|
+
|
49
|
+
return endpoint, jgrep_query
|
50
|
+
end
|
51
|
+
|
15
52
|
def request(endpoint, query, opts={})
|
16
|
-
|
53
|
+
if endpoint == ''
|
54
|
+
endpoint, query = pql_to_jgrep(query)
|
55
|
+
else
|
56
|
+
query = puppetdb_to_jgrep(query)
|
57
|
+
end
|
58
|
+
ret = JGrep.jgrep(File.read("spec/fixtures/#{endpoint}.json"), query)
|
17
59
|
PuppetDB::Response.new(ret, ret.size)
|
18
60
|
end
|
19
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-ghostbuster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camptocamp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -162,14 +162,14 @@ dependencies:
|
|
162
162
|
requirements:
|
163
163
|
- - ">="
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
165
|
+
version: 1.1.1
|
166
166
|
type: :runtime
|
167
167
|
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
170
|
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
172
|
+
version: 1.1.1
|
173
173
|
description: Try and find dead code in Puppet receipts
|
174
174
|
email:
|
175
175
|
executables: []
|
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
requirements: []
|
241
241
|
rubyforge_project:
|
242
|
-
rubygems_version: 2.5
|
242
|
+
rubygems_version: 2.4.5
|
243
243
|
signing_key:
|
244
244
|
specification_version: 4
|
245
245
|
summary: Dead code detector for Puppet
|