puppet-check 2.0.0 → 2.0.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/lib/puppet-check/data_parser.rb +9 -8
- data/lib/puppet-check/output_results.rb +3 -2
- data/lib/puppet-check/puppet_parser.rb +12 -8
- data/lib/puppet-check/rspec_puppet_support.rb +18 -6
- data/spec/puppet-check/data_parser_spec.rb +1 -1
- data/spec/puppet-check/puppet_parser_spec.rb +11 -8
- data/spec/puppet-check/regression_check_spec.rb +1 -1
- data/spec/puppet-check/rspec_puppet_support_spec.rb +5 -1
- data/spec/puppet-check/ruby_parser_spec.rb +5 -1
- metadata +19 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa44aac16d4ff64057807c913172a7a064352f4fcfee70868b0d0c06dc0dffd6
|
4
|
+
data.tar.gz: 4a1fbf02e9638af8605b26377ac335594ac8d640308f38fdbc9dbae1ada78a99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58186b18c0aa0fe1600c158be2d20be6ccaf75389e18baae51041a47b8c314dd550f0817a329aca29e2ed1a6c96249f3220815b8f26387a2795306ce41715d9e
|
7
|
+
data.tar.gz: 616cdc41630d9b06e93cbc27015980baa3777063837ce91e1a88955a0fdbfb41cbcc79473133d4bbe1439961345cb8f745acda8f40b15c1d0bfb58b863a80be0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Puppet Check
|
2
2
|
[](https://travis-ci.org/mschuchard/puppet-check)
|
3
|
+
[](https://circleci.com/gh/mschuchard/puppet-check)
|
3
4
|
|
4
5
|
- [Description](#description)
|
5
6
|
- [Usage](#usage)
|
@@ -118,8 +118,8 @@ class DataParser
|
|
118
118
|
next warnings.push("'#{req_dep['name']}' is missing an upper bound.") unless req_dep['version_requirement'].include?('<')
|
119
119
|
|
120
120
|
# check for semantic versioning
|
121
|
-
if key == 'dependencies'
|
122
|
-
warnings.push("'#{req_dep['name']}' has non-semantic versioning in its 'version_requirement' key.")
|
121
|
+
if key == 'dependencies' && req_dep['version_requirement'] !~ /\d+\.\d+\.\d+.*\d+\.\d+\.\d+/
|
122
|
+
warnings.push("'#{req_dep['name']}' has non-semantic versioning in its 'version_requirement' key.")
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
@@ -177,16 +177,16 @@ class DataParser
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
# check that parameters is a hash
|
180
|
-
if parsed.key?('parameters')
|
181
|
-
warnings.push('parameters value is not a Hash')
|
180
|
+
if parsed.key?('parameters') && !parsed['parameters'].is_a?(Hash)
|
181
|
+
warnings.push('parameters value is not a Hash')
|
182
182
|
end
|
183
183
|
# check that puppet_task_version is an integer
|
184
|
-
if parsed.key?('puppet_task_version')
|
185
|
-
warnings.push('puppet_task_version value is not an Integer')
|
184
|
+
if parsed.key?('puppet_task_version') && !parsed['puppet_task_version'].is_a?(Integer)
|
185
|
+
warnings.push('puppet_task_version value is not an Integer')
|
186
186
|
end
|
187
187
|
# check that supports_noop is a boolean
|
188
|
-
if parsed.key?('supports_noop')
|
189
|
-
warnings.push('supports_noop value is not a Boolean')
|
188
|
+
if parsed.key?('supports_noop') && !(parsed['supports_noop'].is_a?(TrueClass) || parsed['supports_noop'].is_a?(FalseClass))
|
189
|
+
warnings.push('supports_noop value is not a Boolean')
|
190
190
|
end
|
191
191
|
# assume this is hieradata and ensure it is non-empty
|
192
192
|
elsif parsed
|
@@ -206,6 +206,7 @@ class DataParser
|
|
206
206
|
|
207
207
|
# disregard nil/undef value data check if default values (common)
|
208
208
|
unless file =~ /^common/
|
209
|
+
# unless /^common/.match?(file) TODO: use when ruby >= 2.4
|
209
210
|
data.each do |key, value|
|
210
211
|
# check for nil values in the data (nil keys are fine)
|
211
212
|
if (value.is_a?(Hash) && value.values.any?(&:nil?)) || value.nil?
|
@@ -31,10 +31,11 @@ class OutputResults
|
|
31
31
|
hash['ignored'] = PuppetCheck.settings[:ignored_files] unless PuppetCheck.settings[:ignored_files].empty?
|
32
32
|
|
33
33
|
# convert hash to markup language
|
34
|
-
|
34
|
+
case settings[:output_format]
|
35
|
+
when 'yaml'
|
35
36
|
require 'yaml'
|
36
37
|
puts Psych.dump(hash, indentation: 2)
|
37
|
-
|
38
|
+
when 'json'
|
38
39
|
require 'json'
|
39
40
|
puts JSON.pretty_generate(hash)
|
40
41
|
else
|
@@ -17,30 +17,34 @@ class PuppetParser
|
|
17
17
|
|
18
18
|
# check puppet syntax
|
19
19
|
begin
|
20
|
+
# initialize message
|
21
|
+
message = ''
|
20
22
|
# in puppet >= 6.5 the return of this method is a hash with the error
|
21
23
|
new_error = Puppet::Face[:parser, :current].validate(file)
|
22
24
|
# puppet 6.5 output format is now a hash from the face api
|
23
|
-
if Puppet::PUPPETVERSION
|
24
|
-
|
25
|
+
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0') && new_error != {}
|
26
|
+
message = new_error.values.map(&:to_s).join("\n").gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')
|
25
27
|
end
|
26
28
|
# this is the actual error that we need to rescue Puppet::Face from
|
27
29
|
rescue SystemExit
|
28
30
|
# puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info
|
29
|
-
if Puppet::PUPPETVERSION
|
30
|
-
|
31
|
+
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.4') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.5')
|
32
|
+
message = errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')
|
31
33
|
# puppet 5.0-5.2 can only do one error per line and outputs fake dir env info
|
32
|
-
elsif Puppet::PUPPETVERSION
|
33
|
-
|
34
|
+
elsif Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.3')
|
35
|
+
message = errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '')
|
34
36
|
end
|
35
37
|
# puppet < 5 and 5.3 parser output style
|
36
|
-
|
38
|
+
message = errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')
|
37
39
|
end
|
40
|
+
# output message
|
41
|
+
next PuppetCheck.settings[:error_files].push("#{file}:\n#{message}") unless message.empty?
|
38
42
|
|
39
43
|
# initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit
|
40
44
|
warnings = "#{file}:"
|
41
45
|
unless errors.empty?
|
42
46
|
# puppet 5.4-5.x has a new validator output format
|
43
|
-
warnings << if Puppet::PUPPETVERSION
|
47
|
+
warnings << if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.4')
|
44
48
|
"\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
|
45
49
|
# puppet <= 5.3 validator output format
|
46
50
|
else
|
@@ -3,7 +3,7 @@ class RSpecPuppetSupport
|
|
3
3
|
# code diagram:
|
4
4
|
# 'puppetcheck:spec' task invokes 'run'
|
5
5
|
# 'run' invokes 'file_setup' always and 'dependency_setup' if metadata.json exists
|
6
|
-
# 'dependency_setup' invokes 'git/forge/hg' if dependencies exist and git/forge/hg is download option
|
6
|
+
# 'dependency_setup' invokes 'git/forge/svn/hg' if dependencies exist and git/forge/svn/hg is download option
|
7
7
|
# 'git/forge/svn/hg' downloads module fixture appropriately
|
8
8
|
|
9
9
|
# prepare the spec fixtures directory for rspec-puppet testing
|
@@ -15,10 +15,10 @@ class RSpecPuppetSupport
|
|
15
15
|
# setup fixtures for rspec-puppet testing
|
16
16
|
specdirs.each do |specdir|
|
17
17
|
# skip to next specdir if it does not seem like a puppet module
|
18
|
-
next unless File.directory?(specdir
|
18
|
+
next unless File.directory?("#{specdir}/../manifests")
|
19
19
|
|
20
20
|
# change to module directory
|
21
|
-
Dir.chdir(specdir
|
21
|
+
Dir.chdir("#{specdir}/..")
|
22
22
|
|
23
23
|
# grab the module name from the directory name of the module to pass to file_setup
|
24
24
|
file_setup(File.basename(Dir.pwd))
|
@@ -90,7 +90,11 @@ class RSpecPuppetSupport
|
|
90
90
|
# establish path to clone module to
|
91
91
|
path = "spec/fixtures/modules/#{File.basename(git_url, '.git')}"
|
92
92
|
# is the module present and already cloned with git? do a pull; otherwise, do a clone
|
93
|
-
|
93
|
+
begin
|
94
|
+
File.directory?("#{path}/.git") ? spawn("git -C #{path} pull") : spawn("git clone #{args} #{git_url} #{path}")
|
95
|
+
rescue Errno::ENOENT
|
96
|
+
warn 'git is not installed and cannot be used to retrieve dependency modules'
|
97
|
+
end
|
94
98
|
end
|
95
99
|
|
96
100
|
# download external module dependency with forge
|
@@ -107,7 +111,11 @@ class RSpecPuppetSupport
|
|
107
111
|
# establish path to checkout module to
|
108
112
|
path = "spec/fixtures/modules/#{File.basename(svn_url)}"
|
109
113
|
# is the module present and already checked out with svn? do an update; otherwise, do a checkout
|
110
|
-
|
114
|
+
begin
|
115
|
+
File.directory?("#{path}/.svn") ? spawn("svn update #{path}") : spawn("svn co #{args} #{svn_url} #{path}")
|
116
|
+
rescue Errno::ENOENT
|
117
|
+
warn 'subversion is not installed and cannot be used to retrieve dependency modules'
|
118
|
+
end
|
111
119
|
end
|
112
120
|
|
113
121
|
# download external module dependency with hg
|
@@ -116,6 +124,10 @@ class RSpecPuppetSupport
|
|
116
124
|
# establish path to clone module to
|
117
125
|
path = "spec/fixtures/modules/#{File.basename(hg_url)}"
|
118
126
|
# is the module present and already cloned with hg? do a pull and update; otherwise do a clone
|
119
|
-
|
127
|
+
begin
|
128
|
+
File.directory?("#{path}/.hg") ? spawn("hg --cwd #{path} pull; hg --cwd #{path} update") : spawn("hg clone #{args} #{hg_url} #{path}")
|
129
|
+
rescue Errno::ENOENT
|
130
|
+
warn 'mercurial is not installed and cannot be used to retrieve dependency modules'
|
131
|
+
end
|
120
132
|
end
|
121
133
|
end
|
@@ -11,10 +11,10 @@ describe PuppetParser do
|
|
11
11
|
context '.manifest' do
|
12
12
|
it 'puts a bad syntax Puppet manifest in the error files array' do
|
13
13
|
PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, [])
|
14
|
-
if Puppet::PUPPETVERSION
|
14
|
+
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
|
15
15
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nLanguage validation logged 2 errors})
|
16
16
|
# dealing with annoying warning in puppet 5 and 6
|
17
|
-
elsif RUBY_VERSION
|
17
|
+
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3')
|
18
18
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nSupport for ruby version.*\n.*\nThis Variable has no effect.*\nIllegal variable name})
|
19
19
|
else
|
20
20
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
|
@@ -22,11 +22,14 @@ describe PuppetParser do
|
|
22
22
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
23
23
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# puppet 5 api has output issues for this fixture
|
26
|
+
unless Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.0.0')
|
27
|
+
it 'puts a bad syntax at eof Puppet manifest in the error files array' do
|
28
|
+
PuppetParser.manifest([fixtures_dir + 'manifests/eof_syntax.pp'], false, [])
|
29
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/eof_syntax.pp:\nSyntax error at end of input})
|
30
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
31
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
32
|
+
end
|
30
33
|
end
|
31
34
|
it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
|
32
35
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], true, [])
|
@@ -37,7 +40,7 @@ describe PuppetParser do
|
|
37
40
|
it 'puts a bad lint style Puppet manifest in the warning files array' do
|
38
41
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], true, [])
|
39
42
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
40
|
-
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
|
43
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)})
|
41
44
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
42
45
|
end
|
43
46
|
it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
|
@@ -5,7 +5,7 @@ require_relative '../../lib/puppet-check/regression_check'
|
|
5
5
|
describe RegressionCheck do
|
6
6
|
context '.config' do
|
7
7
|
# json gem got messed up for the EOL Ruby versions
|
8
|
-
if RUBY_VERSION
|
8
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2')
|
9
9
|
it 'raise an appropriate error if the file is malformed' do
|
10
10
|
expect { RegressionCheck.config(fixtures_dir + 'metadata.json') }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
|
11
11
|
end
|
@@ -14,7 +14,11 @@ describe RSpecPuppetSupport do
|
|
14
14
|
before(:each) { Dir.chdir(fixtures_dir) }
|
15
15
|
|
16
16
|
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
|
17
|
-
|
17
|
+
if File.directory?('/home/travis')
|
18
|
+
expect { rspec_puppet_setup }.to output("puppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
19
|
+
else
|
20
|
+
expect { rspec_puppet_setup }.to output("subversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
21
|
+
end
|
18
22
|
|
19
23
|
# .file_setup
|
20
24
|
expect(File.directory?('spec/fixtures/manifests')).to be true
|
@@ -38,7 +38,11 @@ describe RubyParser do
|
|
38
38
|
context '.template' do
|
39
39
|
it 'puts a bad syntax ruby template file in the error files array' do
|
40
40
|
RubyParser.template([fixtures_dir + 'templates/syntax.erb'])
|
41
|
-
|
41
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
|
42
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*1: syntax error, unexpected.*\n.*ruby})
|
43
|
+
else
|
44
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
|
45
|
+
end
|
42
46
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
43
47
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
44
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Schuchard
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: puppet-lint
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
version: '4.0'
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '7'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,21 +63,27 @@ dependencies:
|
|
63
63
|
version: '4.0'
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '7'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: rubocop
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0.58'
|
74
|
+
- - "<"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2'
|
74
77
|
type: :runtime
|
75
78
|
prerelease: false
|
76
79
|
version_requirements: !ruby/object:Gem::Requirement
|
77
80
|
requirements:
|
78
|
-
- - "
|
81
|
+
- - ">="
|
79
82
|
- !ruby/object:Gem::Version
|
80
83
|
version: '0.58'
|
84
|
+
- - "<"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '2'
|
81
87
|
- !ruby/object:Gem::Dependency
|
82
88
|
name: rubocop-performance
|
83
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +143,7 @@ dependencies:
|
|
137
143
|
description: Puppet Check is a gem that provides a comprehensive, streamlined, and
|
138
144
|
efficient analysis of the syntax, style, and validity of your entire Puppet code
|
139
145
|
and data.
|
140
|
-
email:
|
146
|
+
email:
|
141
147
|
executables:
|
142
148
|
- puppet-check
|
143
149
|
extensions: []
|
@@ -215,7 +221,7 @@ homepage: https://www.github.com/mschuchard/puppet-check
|
|
215
221
|
licenses:
|
216
222
|
- MIT
|
217
223
|
metadata: {}
|
218
|
-
post_install_message:
|
224
|
+
post_install_message:
|
219
225
|
rdoc_options: []
|
220
226
|
require_paths:
|
221
227
|
- lib
|
@@ -230,9 +236,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
236
|
- !ruby/object:Gem::Version
|
231
237
|
version: '0'
|
232
238
|
requirements: []
|
233
|
-
|
234
|
-
|
235
|
-
signing_key:
|
239
|
+
rubygems_version: 3.1.2
|
240
|
+
signing_key:
|
236
241
|
specification_version: 4
|
237
242
|
summary: A streamlined comprehensive set of checks for your entire Puppet code and
|
238
243
|
data
|