puppet-syntax 2.3.0 → 2.4.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: e5a8ea5b2dd10a9474032154b4716a5a51d59c2f
4
- data.tar.gz: 620bbfbea83b5fedeb8d1e34161b2b08d0afad38
3
+ metadata.gz: 6606744a1866c599818bf66f5049dd0fdafeaa68
4
+ data.tar.gz: 353c86d96ce6356fa46fddcbb66eb8429ee81a3a
5
5
  SHA512:
6
- metadata.gz: cc7eeb21577dd0ad6b0ce2b72f0fd207c44b40d35eba98f6108c2d133f53976d4b66a6896acd44e6278e56f3cf736efa3ac410ec530ce1faf1d1b7a1e14199f2
7
- data.tar.gz: 4dedf7bfd033d33b8b7404234717e36b1c5e1d0c8e38c8e39f4d7d1f12fd487238a33d53af56ff9cc03279e561be20649f264b48599893868d9267655b059bc9
6
+ metadata.gz: 3ea3d4e1c1f63a3f7f92dcd1d99e3401004c3e6eec01036d2227f0127b45d01a7790f58f9147b4f9d172649aa4264aed100da2e9a822179f5b68b6363616de85
7
+ data.tar.gz: e50e01a78dcf9b35ee36be7866e1328ab39df08dbab5d45f45a7bdcd4ef06e9ffdc5149df7227dbf92f8e461be9b92f23c84d231b07e410a20ac401963259a0e
@@ -12,7 +12,9 @@ rvm:
12
12
  env:
13
13
  - PUPPET_VERSION="~> 3.8.7"
14
14
  - PUPPET_VERSION="~> 4.8.0"
15
+ - PUPPET_VERSION="~> 4.9.0"
15
16
  - PUPPET_VERSION=">= 0"
17
+ - PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
16
18
  matrix:
17
19
  exclude:
18
20
  - env: PUPPET_VERSION="~> 3.8.7"
@@ -21,9 +23,16 @@ matrix:
21
23
  rvm: 2.3.3
22
24
  - env: PUPPET_VERSION="~> 3.8.7"
23
25
  rvm: 2.4.0
26
+ # 4.9 with Ruby 1.9.3 issues deprecation warnings
27
+ - env: PUPPET_VERSION="~> 4.9.0"
28
+ rvm: 1.9.3
29
+ - env: PUPPET_VERSION=">= 0"
30
+ rvm: 1.9.3
31
+ - env: PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
32
+ rvm: 1.9.3
24
33
  allow_failures:
25
34
  - env: PUPPET_VERSION=">= 0"
26
-
35
+ - env: PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
27
36
  deploy:
28
37
  provider: rubygems
29
38
  api_key:
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 2017-03-14 Release 2.4.0
2
+ - Add check_hiera_keys flag for deep checking of Hiera key name correctness. Thanks @petems.
3
+ - Fix Puppet version comparisons for compatibility with Puppet 4.10.
4
+ - Fix app_management setting compatibility with Puppet 5.
5
+ - Refactor PUPPETVERSION usage to Puppet.version public API.
6
+
1
7
  2017-01-30 Release 2.3.0
2
8
  - Add app_management flag for Puppet application orchestration support. Thanks @ipcrm.
3
9
  - Check all *yaml file extensions, including eyaml. thanks @kjetilho, @rjw1.
data/Gemfile CHANGED
@@ -1,11 +1,24 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Find a location or specific version for a gem. place_or_version can be a
4
+ # version, which is most often used. It can also be git, which is specified as
5
+ # `git://somewhere.git#branch`. You can also use a file source location, which
6
+ # is specified as `file://some/location/on/disk`.
7
+ def location_for(place_or_version, fake_version = nil)
8
+ if place_or_version =~ /^(git[:@][^#]*)#(.*)/
9
+ [fake_version, { :git => $1, :branch => $2, :require => false }].compact
10
+ elsif place_or_version =~ /^file:\/\/(.*)/
11
+ ['>= 0', { :path => File.expand_path($1), :require => false }]
12
+ else
13
+ [place_or_version, { :require => false }]
14
+ end
15
+ end
16
+
3
17
  # Specify your gem's dependencies in puppet-syntax.gemspec
4
18
  gemspec
5
19
 
6
20
  # Override gemspec for CI matrix builds.
7
- puppet_version = ENV['PUPPET_VERSION'] || '>2.7.0'
8
- gem 'puppet', puppet_version
21
+ gem 'puppet', *location_for(ENV['PUPPET_VERSION'] || '>2.7.0')
9
22
 
10
23
  # older version required for ruby 1.9 compat, as it is pulled in as dependency of puppet, this has to be carried by the module
11
24
  gem 'json_pure', '<= 2.0.1'
data/README.md CHANGED
@@ -97,10 +97,23 @@ If you are trying to validate the syntax of code written for application orchest
97
97
 
98
98
  PuppetSyntax.app_management = true
99
99
 
100
+ `app_management` is supported on Puppet 4.3 or higher, defaulting to off. On Puppet 5, it is always enabled.
101
+
100
102
  Deprecation notices will cause a failure by default, you can override this functionality by setting:
101
103
 
102
104
  PuppetSyntax.fail_on_deprecation_notices = false
103
105
 
106
+ Common mistakes in key names in Hiera files will be reported:
107
+
108
+ - Leading :: in keys eg. `::notsotypical::warning2: true`
109
+ - Single colon scope seperators eg. `:picky::warning5: true`
110
+ - Invalid camel casing eg. `noCamelCase::warning3: true`
111
+ - Use of hyphens eg. `no-hyphens::warning4: true`
112
+
113
+ This can be enabled by setting
114
+
115
+ PuppetSyntax.check_hiera_keys = true
116
+
104
117
  ## Installation
105
118
 
106
119
  Add this line to your application's Gemfile:
@@ -2,15 +2,32 @@ require "puppet-syntax/version"
2
2
  require "puppet-syntax/manifests"
3
3
  require "puppet-syntax/templates"
4
4
  require "puppet-syntax/hiera"
5
+ require "puppet/version"
5
6
 
6
7
  module PuppetSyntax
7
8
  @exclude_paths = []
8
9
  @future_parser = false
9
- @hieradata_paths = ["**/data/**/*.*yaml", "hieradata/**/*.*yaml", "hiera*.*yaml"]
10
+ @hieradata_paths = [
11
+ "**/data/**/*.*yaml",
12
+ "hieradata/**/*.*yaml",
13
+ "hiera*.*yaml"
14
+ ]
10
15
  @fail_on_deprecation_notices = true
11
- @app_management = false
16
+ @app_management = Puppet.version.to_i >= 5 ? true : false
17
+ @check_hiera_keys = false
12
18
 
13
19
  class << self
14
- attr_accessor :exclude_paths, :future_parser, :hieradata_paths, :fail_on_deprecation_notices, :epp_only, :app_management
20
+ attr_accessor :exclude_paths,
21
+ :future_parser,
22
+ :hieradata_paths,
23
+ :fail_on_deprecation_notices,
24
+ :epp_only,
25
+ :check_hiera_keys
26
+ attr_reader :app_management
27
+
28
+ def app_management=(app_management)
29
+ raise 'app_management cannot be disabled on Puppet 5 or higher' if Puppet.version.to_i >= 5 && !app_management
30
+ @app_management = app_management
31
+ end
15
32
  end
16
33
  end
@@ -2,6 +2,24 @@ require 'yaml'
2
2
 
3
3
  module PuppetSyntax
4
4
  class Hiera
5
+
6
+ def check_hiera_key(key)
7
+ if key.is_a? Symbol
8
+ if key.to_s.start_with?(':')
9
+ return "Puppet automatic lookup will not use leading '::'"
10
+ elsif key !~ /^[a-z]+$/ # we allow Hiera's own configuration
11
+ return "Puppet automatic lookup will not look up symbols"
12
+ end
13
+ elsif key !~ /^[a-z][a-z0-9_]+(::[a-z][a-z0-9_]+)*$/
14
+ if key =~ /[^:]:[^:]/
15
+ # be extra helpful
16
+ return "Looks like a missing colon"
17
+ else
18
+ return "Not a valid Puppet variable name for automatic lookup"
19
+ end
20
+ end
21
+ end
22
+
5
23
  def check(filelist)
6
24
  raise "Expected an array of files" unless filelist.is_a?(Array)
7
25
 
@@ -9,11 +27,20 @@ module PuppetSyntax
9
27
 
10
28
  filelist.each do |hiera_file|
11
29
  begin
12
- YAML.load_file(hiera_file)
30
+ yamldata = YAML.load_file(hiera_file)
13
31
  rescue Exception => error
14
32
  errors << "ERROR: Failed to parse #{hiera_file}: #{error}"
33
+ next
34
+ end
35
+ if yamldata
36
+ yamldata.each do |k,v|
37
+ if PuppetSyntax.check_hiera_keys
38
+ key_msg = check_hiera_key(k)
39
+ errors << "WARNING: #{hiera_file}: Key :#{k}: #{key_msg}" if key_msg
40
+ end
41
+ end
15
42
  end
16
- end
43
+ end
17
44
 
18
45
  errors.map! { |e| e.to_s }
19
46
 
@@ -58,8 +58,8 @@ module PuppetSyntax
58
58
 
59
59
  private
60
60
  def validate_manifest(file)
61
- Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet::PUPPETVERSION.to_i < 4
62
- Puppet[:app_management] = true if PuppetSyntax.app_management and Puppet::PUPPETVERSION.to_f >= 4.3
61
+ Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet.version.to_i < 4
62
+ Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5)
63
63
  Puppet::Face[:parser, :current].validate(file)
64
64
  end
65
65
  end
@@ -48,13 +48,13 @@ to puppetlabs_spec_helper >= 0.8.0 which now uses puppet-syntax.
48
48
 
49
49
  desc 'Syntax check Puppet manifests'
50
50
  task :manifests do |t|
51
- if Puppet::PUPPETVERSION.to_i >= 4 and PuppetSyntax.future_parser
51
+ if Puppet.version.to_i >= 4 and PuppetSyntax.future_parser
52
52
  $stderr.puts <<-EOS
53
53
  [INFO] Puppet 4 has been detected and `future_parser` has been set to
54
54
  'true'. The `future_parser setting will be ignored.
55
55
  EOS
56
56
  end
57
- if Puppet::PUPPETVERSION.to_f < 4.3 and PuppetSyntax.app_management
57
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') < 0 and PuppetSyntax.app_management
58
58
  $stderr.puts <<-EOS
59
59
  [WARNING] Puppet `app_management` has been detected but the Puppet
60
60
  version is less then 4.3. The `app_management` setting will be ignored.
@@ -27,7 +27,7 @@ module PuppetSyntax
27
27
  end
28
28
 
29
29
  def validate_epp(filename)
30
- if Puppet::PUPPETVERSION.to_f < 3.7
30
+ if Puppet.version.to_f < 3.7
31
31
  raise "Cannot validate EPP without Puppet 4 or future parser (3.7+)"
32
32
  end
33
33
 
@@ -1,3 +1,3 @@
1
1
  module PuppetSyntax
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -21,5 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "rake"
22
22
 
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rb-readline"
24
26
  spec.add_development_dependency "gem_publisher", "~> 1.3"
25
27
  end
@@ -0,0 +1,11 @@
1
+ ---
2
+ this_is_ok: 0
3
+ this_is_ok::too: 0
4
+ th1s_is_ok::two3: 0
5
+ :eventhis: 0
6
+
7
+ typical:typo::warning1: true
8
+ ::notsotypical::warning2: true
9
+ noCamelCase::warning3: true
10
+ no-hyphens::warning4: true
11
+ :picky::warning5: true
@@ -21,4 +21,34 @@ describe PuppetSyntax::Hiera do
21
21
  expect(res.size).to be == 1
22
22
  expect(res.first).to match(expected)
23
23
  end
24
+
25
+ context 'check_hiera_keys = true' do
26
+ before(:each) {
27
+ PuppetSyntax.check_hiera_keys = true
28
+ }
29
+
30
+ it "should return warnings for invalid keys" do
31
+ hiera_yaml = 'hiera_badkey.yaml'
32
+ examples = 5
33
+ files = fixture_hiera(hiera_yaml)
34
+ res = subject.check(files)
35
+ (1..examples).each do |n|
36
+ expect(res).to include(/::warning#{n}/)
37
+ end
38
+ expect(res.size).to be == examples
39
+ expect(res[0]).to match('Key :typical:typo::warning1: Looks like a missing colon')
40
+ expect(res[1]).to match('Key ::notsotypical::warning2: Puppet automatic lookup will not use leading \'::\'')
41
+ expect(res[2]).to match('Key :noCamelCase::warning3: Not a valid Puppet variable name for automatic lookup')
42
+ expect(res[3]).to match('Key :no-hyphens::warning4: Not a valid Puppet variable name for automatic lookup')
43
+ expect(res[4]).to match('Key :picky::warning5: Puppet automatic lookup will not look up symbols')
44
+ end
45
+
46
+ it "should handle empty files" do
47
+ hiera_yaml = 'hiera_key_empty.yaml'
48
+ files = fixture_hiera(hiera_yaml)
49
+ res = subject.check(files)
50
+ expect(res).to be_empty
51
+ end
52
+
53
+ end
24
54
  end
@@ -28,9 +28,9 @@ describe PuppetSyntax::Manifests do
28
28
  files = fixture_manifests('fail_error.pp')
29
29
  output, has_errors = subject.check(files)
30
30
 
31
- if Puppet::PUPPETVERSION.to_i >= 4
31
+ if Puppet.version.to_i >= 4
32
32
  expect(output.size).to eq(3)
33
- expect(output[2]).to match(/Found 2 errors. Giving up/)
33
+ expect(output[2]).to match(/2 errors. Giving up/)
34
34
  expect(has_errors).to eq(true)
35
35
  else
36
36
  expect(output.size).to eq(1)
@@ -72,11 +72,11 @@ describe PuppetSyntax::Manifests do
72
72
  output, has_errors = subject.check(files)
73
73
 
74
74
  expect(has_errors).to eq(true)
75
- if Puppet::PUPPETVERSION.to_i >= 4
75
+ if Puppet.version.to_i >= 4
76
76
  expect(output.size).to eq(5)
77
77
  expect(output[0]).to match(/This Name has no effect. A Host Class Definition can not end with a value-producing expression without other effect at \S*\/fail_error.pp:2:32$/)
78
78
  expect(output[1]).to match(/This Name has no effect. A value(-producing expression without other effect may only be placed last in a block\/sequence| was produced and then forgotten.*) at \S*\/fail_error.pp:2:3$/)
79
- expect(output[2]).to match('Found 2 errors. Giving up')
79
+ expect(output[2]).to match('2 errors. Giving up')
80
80
  expect(output[3]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/)
81
81
  expect(output[4]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
82
82
  else
@@ -138,10 +138,10 @@ describe PuppetSyntax::Manifests do
138
138
 
139
139
  describe 'app_management' do
140
140
  after do
141
- PuppetSyntax.app_management = false
141
+ PuppetSyntax.app_management = false if Puppet.version.to_i < 5
142
142
  end
143
143
 
144
- context 'app_management = false (default)' do
144
+ context 'app_management = false (default)', :if => (Puppet.version.to_i < 5) do
145
145
  it 'should fail to parse an application manifest' do
146
146
 
147
147
  files = fixture_manifests(['test_app.pp'])
@@ -155,7 +155,7 @@ describe PuppetSyntax::Manifests do
155
155
  before(:each) {
156
156
  PuppetSyntax.app_management = true
157
157
  }
158
- if Puppet::PUPPETVERSION.to_f >= 4.3
158
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
159
159
  it 'should successfully parse an application manifest on Puppet >= 4.3.0' do
160
160
  expect(PuppetSyntax.app_management).to eq(true)
161
161
 
@@ -211,7 +211,7 @@ describe PuppetSyntax::Manifests do
211
211
  PuppetSyntax.future_parser = true
212
212
  }
213
213
 
214
- if Puppet::Util::Package.versioncmp(Puppet.version, '3.2') >= 0 and Puppet::PUPPETVERSION.to_i < 4
214
+ if Puppet::Util::Package.versioncmp(Puppet.version, '3.2') >= 0 and Puppet.version.to_i < 4
215
215
  context 'Puppet >= 3.2 < 4' do
216
216
  it 'should pass with future option set to true on future manifest' do
217
217
  files = fixture_manifests(['future_syntax.pp'])
@@ -67,7 +67,7 @@ describe PuppetSyntax::Templates do
67
67
  expect(res).to match([])
68
68
  end
69
69
 
70
- if Puppet::PUPPETVERSION.to_f < 3.7
70
+ if Puppet.version.to_f < 3.7
71
71
  context 'on Puppet < 3.7' do
72
72
  it 'should throw an exception when parsing EPP files' do
73
73
  file = fixture_templates('pass.epp')
@@ -87,7 +87,7 @@ describe PuppetSyntax::Templates do
87
87
  end
88
88
  end
89
89
 
90
- if Puppet::PUPPETVERSION.to_f >= 3.7
90
+ if Puppet.version.to_f >= 3.7
91
91
  context 'on Puppet >= 3.7' do
92
92
  it 'should return nothing from a valid file' do
93
93
  files = fixture_templates('pass.epp')
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe PuppetSyntax do
4
4
  after do
5
5
  PuppetSyntax.exclude_paths = []
6
- PuppetSyntax.app_management = false
6
+ PuppetSyntax.app_management = false if Puppet.version.to_i < 5
7
7
  end
8
8
 
9
9
  it 'should default exclude_paths to empty array' do
@@ -30,6 +30,10 @@ describe PuppetSyntax do
30
30
  expect(PuppetSyntax.app_management).to eq(true)
31
31
  end
32
32
 
33
+ it 'should raise error when app_management is disabled on 5.x', :if => (Puppet.version.to_i >= 5) do
34
+ expect { PuppetSyntax.app_management = false }.to raise_error(/app_management cannot be disabled on Puppet 5 or higher/)
35
+ end
36
+
33
37
  it 'should support a fail_on_deprecation_notices setting' do
34
38
  PuppetSyntax.fail_on_deprecation_notices = false
35
39
  expect(PuppetSyntax.fail_on_deprecation_notices).to eq(false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-syntax
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.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: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rb-readline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: gem_publisher
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +108,9 @@ files:
80
108
  - spec/fixtures/hiera/data/test/hiera_4.eyaml
81
109
  - spec/fixtures/hiera/hiera_bad.yaml
82
110
  - spec/fixtures/hiera/hiera_bad_18.yaml
111
+ - spec/fixtures/hiera/hiera_badkey.yaml
83
112
  - spec/fixtures/hiera/hiera_good.yaml
113
+ - spec/fixtures/hiera/hiera_key_empty.yaml
84
114
  - spec/fixtures/test_module/manifests/deprecation_notice.pp
85
115
  - spec/fixtures/test_module/manifests/fail_error.pp
86
116
  - spec/fixtures/test_module/manifests/fail_warning.pp
@@ -136,7 +166,9 @@ test_files:
136
166
  - spec/fixtures/hiera/data/test/hiera_4.eyaml
137
167
  - spec/fixtures/hiera/hiera_bad.yaml
138
168
  - spec/fixtures/hiera/hiera_bad_18.yaml
169
+ - spec/fixtures/hiera/hiera_badkey.yaml
139
170
  - spec/fixtures/hiera/hiera_good.yaml
171
+ - spec/fixtures/hiera/hiera_key_empty.yaml
140
172
  - spec/fixtures/test_module/manifests/deprecation_notice.pp
141
173
  - spec/fixtures/test_module/manifests/fail_error.pp
142
174
  - spec/fixtures/test_module/manifests/fail_warning.pp