metadata-json-lint 2.1.0 → 2.2.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
  SHA256:
3
- metadata.gz: fb2c947e575640401cda92a61f4b092a3670a0eac2c2bb94de66ce03b6d13d9f
4
- data.tar.gz: 39c477f21af81c03b70e6e019fe38871d010dd8367561842b67c450d737f9679
3
+ metadata.gz: 18ae05b2da0e3412d155e0ef98619401e66103b491592d0bf39662ef779ff510
4
+ data.tar.gz: 1e072d693b6a7f3f1f819b81584a0766da507a18526195d7111617fcd1404cfd
5
5
  SHA512:
6
- metadata.gz: 6248827093dbcbde3a6e49beed51c61f40ed8b28b443155f04b062ee24f52790004dcb30567f6eb1f750250e0c9df34c0965de264f0589e851ff9706e72b6f39
7
- data.tar.gz: f66771e15322868d43eb8e140f734e710c84a9035f4f47870c095a1af5d06aca12e4b49be94828bce7ea21773989028d7aea8db912782a9cca6212b489de1824
6
+ metadata.gz: a6e20d329944205d3e8c24cc86176feca9a94609dfba8aabce7bf92c1529518ca51b6d24ef874df397b49f8e8769df3694f41983696a316b0cb1f06b8721c371
7
+ data.tar.gz: cbf678ed70b94343ea6f123104bbc8471888b32c65fa4b40e7189adce53d679d879c4a1393afe11f8a5968622c83b331ab862a08583c862b188ac03dfc689ed3
@@ -20,6 +20,7 @@ Metrics/MethodLength:
20
20
  Metrics/BlockLength:
21
21
  Exclude:
22
22
  - spec/**/*_spec.rb
23
+ - ./*.gemspec
23
24
 
24
25
  Metrics/PerceivedComplexity:
25
26
  Enabled: false
@@ -7,10 +7,10 @@ script:
7
7
  sudo: false
8
8
 
9
9
  rvm:
10
- - 2.0.0
11
10
  - 2.1.9
12
- - 2.3.1
13
- - 2.4.1
11
+ - 2.4.3
12
+ - 2.4.4
13
+ - 2.5.1
14
14
 
15
15
  deploy:
16
16
  provider: rubygems
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## 2.2.0
9
+ * Validate Puppet version_requirement [#99](https://github.com/voxpupuli/metadata-json-lint/issues/99)
10
+ * Add optional check `--strict-puppet-version` to validate the Puppet Agent Version is not EOL or open ended [#100](https://github.com/voxpupuli/metadata-json-lint/pull/100)
11
+
8
12
  ## 2.1.0
9
13
 
10
14
  ### Changes
data/README.md CHANGED
@@ -8,8 +8,6 @@ metadata-json-lint is compatible with Ruby versions 2.0.0, 2.1.9, 2.3.1, and 2.4
8
8
 
9
9
  ## Installation
10
10
 
11
- Puppet 4.9.0 and newer:
12
-
13
11
  via `gem` command:
14
12
  ``` shell
15
13
  gem install metadata-json-lint
@@ -20,19 +18,6 @@ via Gemfile:
20
18
  gem 'metadata-json-lint'
21
19
  ```
22
20
 
23
- **Puppet 4.8.x and older:**
24
-
25
- via `gem` command:
26
- ``` shell
27
- gem install metadata-json-lint semantic_puppet
28
- ```
29
-
30
- via Gemfile:
31
- ``` ruby
32
- gem 'metadata-json-lint'
33
- gem 'semantic_puppet'
34
- ```
35
-
36
21
  ## Usage
37
22
 
38
23
  ### Testing with metadata-json-lint
@@ -76,6 +61,7 @@ MetadataJsonLint.options.strict_license = false
76
61
  * `--[no-]strict-dependencies`: Whether to fail if module version dependencies are open-ended. Defaults to `false`.
77
62
  * `--[no-]strict-license`: Whether to fail on strict license check. Defaults to `true`.
78
63
  * `--[no-]fail-on-warnings`: Whether to fail on warnings. Defaults to `true`.
64
+ * `--[no-]strict-puppet-version`: Whether to fail if Puppet version requirements are open-ended or no longer supported. Defaults to `false`.
79
65
 
80
66
  ## Contributors
81
67
 
@@ -47,6 +47,22 @@ module MetadataJsonLint
47
47
  end
48
48
  end
49
49
 
50
+ def puppet_eol?
51
+ true if range.begin < SemanticPuppet::Version.parse(MIN_PUPPET_VER)
52
+ end
53
+
54
+ def ver_range
55
+ range
56
+ end
57
+
58
+ def min
59
+ range.begin
60
+ end
61
+
62
+ def max
63
+ range.end
64
+ end
65
+
50
66
  private
51
67
 
52
68
  attr_reader :range, :requirement
@@ -9,16 +9,20 @@ require 'metadata-json-lint/schema'
9
9
  require 'metadata-json-lint/version_requirement'
10
10
 
11
11
  module MetadataJsonLint
12
+ MIN_PUPPET_VER = '4.10.0'.freeze
13
+
12
14
  def options
13
15
  @options ||= Struct.new(
14
16
  :fail_on_warnings,
15
17
  :strict_license,
16
18
  :strict_dependencies,
19
+ :strict_puppet_version,
17
20
  :format
18
21
  ).new(
19
22
  true, # fail_on_warnings
20
23
  true, # strict_license
21
24
  false, # strict_dependencies
25
+ false, # strict_puppet_version
22
26
  'text', # format
23
27
  )
24
28
  end
@@ -40,6 +44,10 @@ module MetadataJsonLint
40
44
  options[:fail_on_warnings] = v
41
45
  end
42
46
 
47
+ opts.on('--[no-]strict-puppet-version', "Fail on strict Puppet Version check based on current supported Puppet versions. Defaults to '#{options[:strict_puppet_version]}'.") do |v|
48
+ options[:strict_puppet_version] = v
49
+ end
50
+
43
51
  opts.on('-f', '--format FORMAT', %i[text json], 'The format in which results will be output (text, json)') do |format|
44
52
  options[:format] = format
45
53
  end
@@ -136,10 +144,34 @@ module MetadataJsonLint
136
144
  if requirement['name'] == 'pe'
137
145
  warn :requirements, "The 'pe' requirement is no longer supported by the Forge."
138
146
  end
147
+
148
+ begin
149
+ puppet_req = VersionRequirement.new(requirement.fetch('version_requirement', ''))
150
+ rescue ArgumentError => e
151
+ # Raised when the version_requirement provided could not be parsed
152
+ error :requirements, "Invalid 'version_requirement' field in metadata.json: #{e}"
153
+ end
154
+
155
+ validate_puppet_ver!(puppet_req) unless puppet_req.instance_variable_get('@requirement').nil?
139
156
  end
140
157
  end
141
158
  module_function :validate_requirements!
142
159
 
160
+ def validate_puppet_ver!(requirement)
161
+ if options[:strict_puppet_version] && requirement.open_ended?
162
+ warn(:requirement, "Puppet has an open ended version requirement #{requirement.ver_range}")
163
+ end
164
+
165
+ if options[:strict_puppet_version] && requirement.puppet_eol?
166
+ warn(:requirement, "#{requirement.min} is no longer supported. Minimum supported version is #{MIN_PUPPET_VER}")
167
+ end
168
+
169
+ return unless requirement.mixed_syntax?
170
+ warn(:requirement, 'Mixing "x" or "*" version syntax with operators is not recommended in ' \
171
+ "metadata.json, use one style in the puppet version: #{requirement.instance_variable_get('@requirement')}")
172
+ end
173
+ module_function :validate_puppet_ver!
174
+
143
175
  def validate_dependencies!(deps)
144
176
  dep_names = []
145
177
  deps.each do |dep|
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'metadata-json-lint'
5
- s.version = '2.1.0'
5
+ s.version = '2.2.0'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'metadata-json-lint /path/to/metadata.json'
8
8
  s.description = 'Utility to verify Puppet metadata.json files'
@@ -19,7 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.required_ruby_version = '>= 2.0.0'
20
20
  s.add_runtime_dependency 'spdx-licenses', '~> 1.0'
21
21
  s.add_runtime_dependency 'json-schema', '~> 2.8'
22
+ s.add_development_dependency 'pry'
22
23
  s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'semantic_puppet'
23
25
  s.add_development_dependency 'rspec'
24
26
  s.add_development_dependency 'rubocop', '~> 0.50.0'
25
27
  s.post_install_message = '
@@ -0,0 +1,37 @@
1
+ describe MetadataJsonLint do
2
+ describe '.validate_requirements!' do
3
+ context 'empty requirements' do
4
+ let :requirements do
5
+ []
6
+ end
7
+
8
+ it { expect { described_class.validate_requirements!(requirements) }.not_to raise_error }
9
+ end
10
+
11
+ context 'with pe' do
12
+ let :requirements do
13
+ [
14
+ { 'name' => 'pe' }
15
+ ]
16
+ end
17
+
18
+ it do
19
+ expect(described_class).to receive('warn').with(:requirements, "The 'pe' requirement is no longer supported by the Forge.")
20
+ expect { described_class.validate_requirements!(requirements) }.not_to raise_error
21
+ end
22
+ end
23
+
24
+ context 'with invalid requirement' do
25
+ let :requirements do
26
+ [
27
+ { 'name' => 'puppet', 'version_requirement' => 'a' }
28
+ ]
29
+ end
30
+
31
+ it do
32
+ expect(described_class).to receive('error').with(:requirements, "Invalid 'version_requirement' field in metadata.json: Unparsable version range: \"a\"")
33
+ expect { described_class.validate_requirements!(requirements) }.not_to raise_error
34
+ end
35
+ end
36
+ end
37
+ end
@@ -57,13 +57,9 @@
57
57
  }
58
58
  ],
59
59
  "requirements": [
60
- {
61
- "name": "pe",
62
- "version_requirement": ">= 3.2.0 < 3.4.0"
63
- },
64
60
  {
65
61
  "name": "puppet",
66
- "version_requirement": "3.x"
62
+ "version_requirement": "5.5.1"
67
63
  }
68
64
  ],
69
65
  "dependencies": [
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1,2 @@
1
+ (WARN) requirements: 3.2.0 is no longer supported. Minimum supported version is 4.10.0(WARN) requirement: 3.2.0 is no longer supported. Minimum supported version is 4.10.0
2
+ Warnings found in metadata.json
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Apache-2.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "tags": [ "postgres" ],
11
+ "operatingsystem_support": [
12
+ {
13
+ "operatingsystem": "RedHat",
14
+ "operatingsystemrelease": [
15
+ "5",
16
+ "6",
17
+ "7"
18
+ ]
19
+ },
20
+ {
21
+ "operatingsystem": "CentOS",
22
+ "operatingsystemrelease": [
23
+ "5",
24
+ "6",
25
+ "7"
26
+ ]
27
+ },
28
+ {
29
+ "operatingsystem": "OracleLinux",
30
+ "operatingsystemrelease": [
31
+ "5",
32
+ "6",
33
+ "7"
34
+ ]
35
+ },
36
+ {
37
+ "operatingsystem": "Scientific",
38
+ "operatingsystemrelease": [
39
+ "5",
40
+ "6",
41
+ "7"
42
+ ]
43
+ },
44
+ {
45
+ "operatingsystem": "Debian",
46
+ "operatingsystemrelease": [
47
+ "6",
48
+ "7"
49
+ ]
50
+ },
51
+ {
52
+ "operatingsystem": "Ubuntu",
53
+ "operatingsystemrelease": [
54
+ "10.04",
55
+ "12.04",
56
+ "14.04"
57
+ ]
58
+ }
59
+ ],
60
+ "requirements": [
61
+ {
62
+ "name": "puppet",
63
+ "version_requirement": "3.2.0"
64
+ }
65
+ ],
66
+ "dependencies": [
67
+ {
68
+ "name": "puppetlabs/stdlib",
69
+ "version_requirement": "1.2.3"
70
+ },
71
+ {
72
+ "name": "puppetlabs/apt",
73
+ "version_requirement": "< 1.2.3"
74
+ },
75
+ {
76
+ "name": "puppetlabs/puppetdb",
77
+ "version_requirement": "<= 1.2.3"
78
+ },
79
+ {
80
+ "name": "puppetlabs/vcsrepo",
81
+ "version_requirement": ">= 1.0.0 < 2.0.0"
82
+ },
83
+ {
84
+ "name": "puppetlabs/rabbitmq",
85
+ "version_requirement": "1.x"
86
+ },
87
+ {
88
+ "name": "puppetlabs/motd",
89
+ "version_requirement": "1.2.x"
90
+ }
91
+ ]
92
+ }
@@ -144,6 +144,9 @@ test "json_format" $FAILURE --format json
144
144
  # Run against a metadata.json with a string for the requirements
145
145
  test "non_array_requirements" $FAILURE
146
146
 
147
+ # Run against a metadata.json with an unsupported minimum Puppet version for the requirements
148
+ test "requirements_eol_version" $FAILURE --strict-puppet-version
149
+
147
150
  # Test running without specifying file to parse
148
151
  cd perfect
149
152
  bundle exec metadata-json-lint
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata-json-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spdx-licenses
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: semantic_puppet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +132,7 @@ files:
104
132
  - lib/metadata-json-lint/version_requirement.rb
105
133
  - lib/metadata_json_lint.rb
106
134
  - metadata-json-lint.gemspec
135
+ - spec/metadata_json_lint_spec.rb
107
136
  - spec/schema_spec.rb
108
137
  - spec/spec_helper.rb
109
138
  - spec/version_requirement_spec.rb
@@ -160,6 +189,9 @@ files:
160
189
  - tests/rake_multiple_json_options/Rakefile
161
190
  - tests/rake_multiple_json_options/metadata_license.json
162
191
  - tests/rake_multiple_json_options/metadata_ok.json
192
+ - tests/requirements_eol_version/Rakefile
193
+ - tests/requirements_eol_version/expected
194
+ - tests/requirements_eol_version/metadata.json
163
195
  - tests/tags_no_array/Rakefile
164
196
  - tests/tags_no_array/expected
165
197
  - tests/tags_no_array/metadata.json
@@ -195,11 +227,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
227
  version: '0'
196
228
  requirements: []
197
229
  rubyforge_project:
198
- rubygems_version: 2.7.5
230
+ rubygems_version: 2.7.7
199
231
  signing_key:
200
232
  specification_version: 4
201
233
  summary: metadata-json-lint /path/to/metadata.json
202
234
  test_files:
235
+ - spec/metadata_json_lint_spec.rb
203
236
  - spec/schema_spec.rb
204
237
  - spec/spec_helper.rb
205
238
  - spec/version_requirement_spec.rb
@@ -256,6 +289,9 @@ test_files:
256
289
  - tests/rake_multiple_json_options/Rakefile
257
290
  - tests/rake_multiple_json_options/metadata_license.json
258
291
  - tests/rake_multiple_json_options/metadata_ok.json
292
+ - tests/requirements_eol_version/Rakefile
293
+ - tests/requirements_eol_version/expected
294
+ - tests/requirements_eol_version/metadata.json
259
295
  - tests/tags_no_array/Rakefile
260
296
  - tests/tags_no_array/expected
261
297
  - tests/tags_no_array/metadata.json