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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fd0578b7418b3a9ec4293c472e1dca897a6418d
4
- data.tar.gz: 87358497e0a8e39d82d785f0557515f59465355b
3
+ metadata.gz: da18d7d720b0464f30e395979feba89136c24299
4
+ data.tar.gz: 88229a5bd5b2ac831abfacb768d9bcca20406ae7
5
5
  SHA512:
6
- metadata.gz: 9f97143c1e2252c9abf4a256e0739c823fc25103ef7ab639a6cc3b5065fb65be75d10b0f0b6ea50eed4e146d540f54c78b357d5d873a078d4a0e502b84486012
7
- data.tar.gz: a6f023e7d57d327920d4b2a64f0eed8c4a7f3f37b697bc699df0e23aaf001e90cb0da19fafb1360868f060ee6e02f9c94d892c22190b8bfda2c0654f996ba3f5
6
+ metadata.gz: b64f93ea5cb0909496add62ed2f1b57b62619e5b7bda5713971b37d25190f751daa6ba1c2c4224c601ae7de602c0abf8052bf4be92be8fd6f982688a2d654090
7
+ data.tar.gz: 8d9fdc6e93bf57aa54bbad62889435a71a2e1fa9c897ddbc84ad159ad95a8d1edec499a88a8acf9814066f3bd30ed26f2d137d3be5f0547cebdfc18c9446029f
@@ -5,7 +5,7 @@ cache: bundler
5
5
  script:
6
6
  bundle exec rake spec
7
7
  rvm:
8
- - 2.1.5
8
+ - 2.3.1
9
9
  matrix:
10
10
  fast_finish: true
11
11
  deploy:
@@ -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'}/pdb/query",
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('resources', [:'=', 'type', 'Class']).data.map { |r| r['title'] }.uniq
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
@@ -1,3 +1,3 @@
1
1
  class PuppetGhostbuster
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  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.client.request('resources', [:'=', 'type', type]).data.size > 0
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
- return if puppetdb.client.request('resources', [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{file_name}"],).data.size > 0
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
- return if puppetdb.client.request(
34
- 'resources',
35
- [:'and',
36
- [:'or',
37
- [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{dir_name}"],
38
- [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{dir_name}/"],
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
 
@@ -63,6 +63,8 @@ PuppetLint.new_check(:ghostbuster_hiera_files) do
63
63
  end
64
64
  end
65
65
 
66
+ query = [:'and', query, [:'=', 'deactivated', nil]]
67
+
66
68
  return if puppetdb.client.request('nodes', query ).data.size > 0
67
69
  end
68
70
 
@@ -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.client.request('resources', [:'=', 'type', type_name.capitalize]).data.size > 0
29
+ return if puppetdb.resources.include? type_name.capitalize
30
30
 
31
31
  notify :warning, {
32
32
  :message => "Type #{type_name.capitalize} seems unused",
@@ -25,5 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'json'
26
26
  s.add_runtime_dependency 'puppet'
27
27
  s.add_dependency 'puppet-lint', '>= 1.0', '< 3.0'
28
- s.add_runtime_dependency 'puppetdb-ruby'
28
+ s.add_runtime_dependency 'puppetdb-ruby', '>= 1.1.1'
29
29
  end
@@ -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
- ret = JGrep.jgrep(File.read("spec/fixtures/#{endpoint}.json"), puppetdb_to_jgrep(query))
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.8.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: 2016-09-23 00:00:00.000000000 Z
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: '0'
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: '0'
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.1
242
+ rubygems_version: 2.4.5
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: Dead code detector for Puppet