puppet-syntax-3.1.0/0000755000004100000410000000000013704151232014402 5ustar www-datawww-datapuppet-syntax-3.1.0/.travis.yml0000644000004100000410000000222213704151232016511 0ustar www-datawww-data--- os: linux dist: bionic language: ruby # Workaround https://github.com/bundler/bundler/issues/3558 before_install: gem install bundler install: bundle install --jobs 4 --retry 2 --without development release script: bundle exec rake rvm: - 2.4.4 - 2.5.1 - 2.6.5 - 2.7 env: - PUPPET_VERSION="~> 5.5.10" - PUPPET_VERSION="~> 6.5" - PUPPET_VERSION=">= 0" - PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master" jobs: exclude: - rvm: 2.7 env: PUPPET_VERSION="~> 5.5.10" allow_failures: - env: PUPPET_VERSION=">= 0" - env: PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master" deploy: provider: rubygems api_key: secure: "kwxryZZ/t9EkWuYxhz3G1v+U3ZK4WdsiN0UFHDjijnAGPxqe/n+oBcNA8hOiNhjZeTFo8bADEZkL7JtdKQo9RvgStipyaS5gDHB/C1c4LOBWv4Tga21NNCAuBcE2CDtAH3+TzrZV5vv2+SpOrhKZpzZoAoR6PR1MWVWMUie/rE0=" gem: puppet-syntax on: rvm: 2.5.1 condition: '"$PUPPET_VERSION" = "~> 5.5.10"' tags: true all_branches: true repo: voxpupuli/puppet-syntax notifications: email: false irc: on_success: always on_failure: always channels: - "chat.freenode.org#voxpupuli-notifications" puppet-syntax-3.1.0/README.md0000644000004100000410000001034613704151232015665 0ustar www-datawww-data[![Build Status](https://travis-ci.org/voxpupuli/puppet-syntax.svg?branch=master)](https://travis-ci.org/voxpupuli/puppet-syntax) [![Gem Version](https://img.shields.io/gem/v/puppet-syntax.svg)](https://rubygems.org/gems/puppet-syntax) [![Gem Downloads](https://img.shields.io/gem/dt/puppet-syntax.svg)](https://rubygems.org/gems/puppet-syntax) # Puppet::Syntax Puppet::Syntax checks for correct syntax in Puppet manifests, templates, and Hiera YAML. ## Version support Puppet::Syntax is supported with: - Puppet >= 5.0 that provides the `validate` face. - Ruby >= 2.4 For the specific versions that we test against, see the [TravisCI config](.travis.yml). ## Installation To install Puppet::Syntax, either add it to your module's Gemfile or install the gem manually. * To install with the Gemfile, add: ```ruby gem 'puppet-syntax' ``` And then execute: ```sh bundle install ``` * To install the gem yourself, run: ```sh gem install puppet-syntax ``` ## Configuration To configure Puppet::Syntax, add any of the following settings to your `Rakefile`. * To exclude certain paths from the syntax checks, set: ```ruby PuppetSyntax.exclude_paths = ["vendor/**/*"] ``` * To configure specific paths for the Hiera syntax check, specify `hieradata_paths`. This is useful if you use Hiera data inside your module. ```ruby PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"] ``` * To configure specific paths for the Puppet syntax checks or for the templates checks, specify `manifests_paths` or `templates_paths` respectively. This is useful if you want to check specific paths only. ```ruby PuppetSyntax.manifests_paths = ["**/environments/future/*.pp"] PuppetSyntax.templates_paths = ["**/modules/**/templates/*.erb"] ``` * To ignore deprecation warnings, disable `fail_on_deprecation_notices`. By default, `puppet-syntax` fails if it encounters Puppet deprecation notices. If you are working with a legacy code base and want to ignore such non-fatal warnings, you might want to override the default behavior. ```ruby PuppetSyntax.fail_on_deprecation_notices = false ``` * To enable a syntax check on Hiera keys, set: ```ruby PuppetSyntax.check_hiera_keys = true ``` This reports common mistakes in key names in Hiera files, such as: * Leading `::` in keys, such as: `::notsotypical::warning2: true`. * Single colon scope separators, such as: `:picky::warning5: true`. * Invalid camel casing, such as: `noCamelCase::warning3: true`. * Use of hyphens, such as: `no-hyphens::warning4: true`. ## Usage * To enable Puppet::Syntax, include the following in your module's `Rakefile`: ```ruby require 'puppet-syntax/tasks/puppet-syntax' ``` For Continuous Integration, use Puppet::Syntax in conjunction with `puppet-lint` and spec tests. Add the following to your module's `Rakefile`: ```ruby task :test => [ :syntax, :lint, :spec, ] ``` * To test all manifests and templates, relative to the location of the `Rakefile`, run: ``` $ bundle exec rake syntax ---> syntax:manifests ---> syntax:templates ---> syntax:hiera:yaml ``` * To return a non-zero exit code and an error message on any failures, run: ``` $ bundle exec rake syntax ---> syntax:manifests rake aborted! Could not parse for environment production: Syntax error at end of file at demo.pp:2 Tasks: TOP => syntax => syntax:manifests (See full trace by running task with --trace) ``` ## Checks Puppet::Syntax makes the following checks in the directories and subdirectories of the module, relative to the location of the `Rakefile`. ### Hiera Checks `.yaml` files for syntax errors. By default, this rake task looks for all `.yaml` files in a single module under: * `**/data/**/*.yaml` * `hieradata/**/*.yaml` * `hiera*.yaml` ### manifests Checks all `.pp` files in the module for syntax errors. ### templates #### erb Checks `.erb` files in the module for syntax errors. #### epp Checks `.epp` files in the module for syntax errors. EPP checks are supported in Puppet 4 or greater, or in Puppet 3 with the future parser enabled. ## Contributing 1. Fork the repo. 2. Create your feature branch (`git checkout -b my-new-feature`). 3. Commit your changes (`git commit -am 'Add some feature'`). 4. Push to the branch (`git push origin my-new-feature`). 5. Create new Pull Request. puppet-syntax-3.1.0/spec/0000755000004100000410000000000013704151232015334 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/0000755000004100000410000000000013704151232017205 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/test_module/0000755000004100000410000000000013704151232021531 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/test_module/manifests/0000755000004100000410000000000013704151232023522 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/test_module/manifests/fail_warning.pp0000644000004100000410000000020213704151232026515 0ustar www-datawww-dataclass warning_puppet_module { notify { 'this should raise a warning': message => "because of \[\] escape characters", } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/test_app.pp0000644000004100000410000000003213704151232025675 0ustar www-datawww-dataapplication test_app { } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/future_syntax.pp0000644000004100000410000000006213704151232027001 0ustar www-datawww-dataclass module_with_future_syntax { $a = $b = 10 } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/pass.pp0000644000004100000410000000015213704151232025027 0ustar www-datawww-dataclass normal_puppet_module { notify { 'should should pass': message => 'with flying colours', } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/pass_storeconfigs.pp0000644000004100000410000000006713704151232027621 0ustar www-datawww-dataclass uses_storeconfigs { @@notify { 'exported': } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/deprecation_notice.pp0000644000004100000410000000024513704151232027722 0ustar www-datawww-datanode test inherits default { import 'pass.pp' notify { 'this should give a deprecation notice': message => 'inheritance is gone in the future parser', } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/tag_notice.pp0000644000004100000410000000016113704151232026175 0ustar www-datawww-dataclass tag_parameter_test ($tag=undef){ notify { 'tag_should pass': message => 'with flying colours', } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/schedule_notice.pp0000644000004100000410000000020013704151232027210 0ustar www-datawww-dataclass schedule_parameter_test ($schedule=undef){ notify { 'schedule_should pass': message => 'with flying colours', } } puppet-syntax-3.1.0/spec/fixtures/test_module/manifests/fail_error.pp0000644000004100000410000000010413704151232026202 0ustar www-datawww-dataclass failing_puppet_module { this is not a valid resource name } puppet-syntax-3.1.0/spec/fixtures/test_module/templates/0000755000004100000410000000000013704151232023527 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/test_module/templates/fail_error_also.epp0000644000004100000410000000006313704151232027376 0ustar www-datawww-dataThis is plain text <% } %> This is also plain text puppet-syntax-3.1.0/spec/fixtures/test_module/templates/pass.erb0000644000004100000410000000007113704151232025165 0ustar www-datawww-data<% valid = 'valid' -%> This is a <%= valid -%> template. puppet-syntax-3.1.0/spec/fixtures/test_module/templates/typeerror_shouldwin.erb0000644000004100000410000000012613704151232030347 0ustar www-datawww-data#this is valid syntax <%= File.dirname(@the_path_of_the_file_you_first_thought_of) %> puppet-syntax-3.1.0/spec/fixtures/test_module/templates/pass_also.epp0000644000004100000410000000011713704151232026220 0ustar www-datawww-data<%# VALID COMMENT %> <% $valid = 'valid' -%> This is a <%= $valid %> template. puppet-syntax-3.1.0/spec/fixtures/test_module/templates/fail_error.epp0000644000004100000410000000010713704151232026357 0ustar www-datawww-dataThis is plain text <% This is not valid EPP %> This is also plain text puppet-syntax-3.1.0/spec/fixtures/test_module/templates/fail_warning.erb0000644000004100000410000000010313704151232026653 0ustar www-datawww-dataAssignment in condition should warn. <%= "oh yes" if foo = true %> puppet-syntax-3.1.0/spec/fixtures/test_module/templates/ignore.tpl0000644000004100000410000000011013704151232025523 0ustar www-datawww-dataThis is plain text <% This is not valid Ruby %> This is also plain text puppet-syntax-3.1.0/spec/fixtures/test_module/templates/pass_unbound_var.erb0000644000004100000410000000005013704151232027564 0ustar www-datawww-data<%= this_variable_has_not_been_bound %> puppet-syntax-3.1.0/spec/fixtures/test_module/templates/fail_error.erb0000644000004100000410000000011013704151232026335 0ustar www-datawww-dataThis is plain text <% This is not valid Ruby %> This is also plain text puppet-syntax-3.1.0/spec/fixtures/test_module/templates/pass.epp0000644000004100000410000000011713704151232025202 0ustar www-datawww-data<%# VALID COMMENT %> <% $valid = 'valid' -%> This is a <%= $valid %> template. puppet-syntax-3.1.0/spec/fixtures/hiera/0000755000004100000410000000000013704151232020275 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/0000755000004100000410000000000013704151232021206 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/test/0000755000004100000410000000000013704151232022165 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/test/hiera_4.eyaml0000644000004100000410000000000013704151232024517 0ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/test/hiera_3.yaml0000644000004100000410000000000013704151232024351 0ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/hiera_1.yaml0000644000004100000410000000000013704151232023370 0ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/data/hiera_2.eyaml0000644000004100000410000000000013704151232023536 0ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/hiera_badkey.yaml0000644000004100000410000000034213704151232023567 0ustar www-datawww-data--- this_is_ok: 0 this_is_ok::too: 0 th1s_is_ok::two3: 0 :eventhis: 0 typical:typo::warning1: true ::notsotypical::warning2: true noCamelCase::warning3: true no-hyphens::warning4: true :picky::warning5: true puppet-syntax-3.1.0/spec/fixtures/hiera/hiera_key_empty.yaml0000644000004100000410000000000013704151232024325 0ustar www-datawww-datapuppet-syntax-3.1.0/spec/fixtures/hiera/hiera_bad.yaml0000644000004100000410000000001113704151232023047 0ustar www-datawww-data%YAMLBAD puppet-syntax-3.1.0/spec/fixtures/hiera/hiera_good.yaml0000644000004100000410000000012513704151232023257 0ustar www-datawww-data--- :backends: - yaml :yaml: :datadir: './hieradata/good' :hierarchy: - common puppet-syntax-3.1.0/spec/fixtures/hiera/hiera_bad_18.yaml0000644000004100000410000000001713704151232023365 0ustar www-datawww-data--- !!!str foo puppet-syntax-3.1.0/spec/fixtures/hiera/hiera_bad.eyaml0000644000004100000410000000106713704151232023230 0ustar www-datawww-data--- acme::warning1: ENC[unknown-method,aGVsbG8sIHdvcmxk] acme::warning2: ENC[PKCS7,aGVsbG8sIHdvcmxk acme::warning3: ENC[PKCS7,aGVsbG8sIHdvcmxk==] acme::warning4: ENC[PKCS7,aGVs!!!!bG8sIHdvcmxk] acme::warning5: key1: foo key2: ENC[PKCS7,aGVs!!!!bG8sIHdvcmxk] acme::warning6: hash_key: - element1 - > ENC[PKCS7, aGVsbG8sIHdvcmxk ] - > ENC[PKCS7, aGVs!!!!bG8sIHdvcmxk ] acme::good1: > ENC[PKCS7, aGVsbG8sIHdvcmxk] acme::good2: ENC[GPG,aGVsbG8sIHdvcmxkIQ==] acme::good3: ENC[GPG,aGVsbG8sIHdvcmxkISE=] puppet-syntax-3.1.0/spec/puppet-syntax_spec.rb0000644000004100000410000000243613704151232021541 0ustar www-datawww-datarequire 'spec_helper' describe PuppetSyntax do after do PuppetSyntax.exclude_paths = [] end it 'should default exclude_paths to include the pkg directory' do expect(PuppetSyntax.exclude_paths).to include('pkg/**/*') end it 'should support setting exclude_paths' do PuppetSyntax.exclude_paths = ["foo", "bar/baz"] expect(PuppetSyntax.exclude_paths).to eq(["foo", "bar/baz"]) end it 'should support appending exclude_paths' do PuppetSyntax.exclude_paths << "foo" expect(PuppetSyntax.exclude_paths).to eq(["foo"]) end it 'should support a fail_on_deprecation_notices setting' do PuppetSyntax.fail_on_deprecation_notices = false expect(PuppetSyntax.fail_on_deprecation_notices).to eq(false) end it 'should support forcing EPP only templates' do PuppetSyntax.epp_only = true expect(PuppetSyntax.epp_only).to eq(true) end it 'should support setting paths for manifests, templates and hiera' do PuppetSyntax.hieradata_paths = [] expect(PuppetSyntax.hieradata_paths).to eq([]) PuppetSyntax.manifests_paths = ["**/environments/production/**/*.pp"] expect(PuppetSyntax.manifests_paths).to eq(["**/environments/production/**/*.pp"]) PuppetSyntax.templates_paths = [] expect(PuppetSyntax.templates_paths).to eq([]) end end puppet-syntax-3.1.0/spec/puppet-syntax/0000755000004100000410000000000013704151232020175 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/puppet-syntax/templates_spec.rb0000644000004100000410000000730713704151232023541 0ustar www-datawww-datarequire 'spec_helper' describe PuppetSyntax::Templates do let(:subject) { PuppetSyntax::Templates.new } let(:conditional_warning_regex) do if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') %r{2: warning: found `= literal' in conditional} else %r{2: warning: found = in conditional} end end it 'should expect an array of files' do expect { subject.check(nil) }.to raise_error(/Expected an array of files/) end it 'should return nothing from a valid file' do files = fixture_templates('pass.erb') res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should ignore NameErrors from unbound variables' do files = fixture_templates('pass_unbound_var.erb') res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should catch SyntaxError' do files = fixture_templates('fail_error.erb') res = subject.check(files) expect(res[:errors].size).to eq(1) expect(res[:errors][0]).to match(/2: syntax error, unexpected/) end it 'should catch Ruby warnings' do files = fixture_templates('fail_warning.erb') res = subject.check(files) expect(res[:warnings].size).to eq(1) expect(res[:warnings][0]).to match(conditional_warning_regex) end it 'should read more than one valid file' do files = fixture_templates(['pass.erb', 'pass_unbound_var.erb']) res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should continue after finding an error in the first file' do files = fixture_templates(['fail_error.erb', 'fail_warning.erb']) res = subject.check(files) expect(res[:warnings].size).to eq(1) expect(res[:errors].size).to eq(1) expect(res[:errors][0]).to match(/2: syntax error, unexpected/) expect(res[:warnings][0]).to match(conditional_warning_regex) end it 'should ignore a TypeError' do files = fixture_templates('typeerror_shouldwin.erb') res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should ignore files without .erb extension' do files = fixture_templates('ignore.tpl') res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should return nothing from a valid file' do files = fixture_templates('pass.epp') res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should catch SyntaxError' do files = fixture_templates('fail_error.epp') res = subject.check(files) expect(res[:errors].size).to eq(1) expect(res[:errors][0]).to match(/This Type-Name has no effect/) end it 'should read more than one valid file' do files = fixture_templates(['pass.epp', 'pass_also.epp']) res = subject.check(files) expect(res[:warnings]).to match([]) expect(res[:errors]).to match([]) end it 'should continue after finding an error in the first file' do files = fixture_templates(['fail_error.epp', 'fail_error_also.epp']) res = subject.check(files) expect(res[:errors].size).to eq(2) expect(res[:errors][0]).to match(/This Type-Name has no effect/) expect(res[:errors][1]).to match(/Syntax error at '}' \(file: \S*\/fail_error_also.epp, line: 2, column: 4\)/) end context "when the 'epp_only' options is set" do before(:each) { PuppetSyntax.epp_only = true } it 'should process an ERB as EPP and find an error' do files = fixture_templates('pass.erb') res = subject.check(files) expect(res[:errors].size).to eq(1) end end end puppet-syntax-3.1.0/spec/puppet-syntax/tasks/0000755000004100000410000000000013704151232021322 5ustar www-datawww-datapuppet-syntax-3.1.0/spec/puppet-syntax/tasks/puppet-syntax_spec.rb0000644000004100000410000000256713704151232025534 0ustar www-datawww-datarequire 'spec_helper' require 'puppet-syntax/tasks/puppet-syntax' known_pp = 'spec/fixtures/test_module/manifests/pass.pp' known_erb = 'spec/fixtures/test_module/templates/pass.erb' known_yaml = 'spec/fixtures/hiera/data/hiera_1.yaml' known_eyaml = 'spec/fixtures/hiera/data/hiera_2.eyaml' known_yaml_subdir = 'spec/fixtures/hiera/data/test/hiera_3.yaml' known_eyaml_subdir = 'spec/fixtures/hiera/data/test/hiera_4.eyaml' describe 'PuppetSyntax rake tasks' do it 'should filter directories' do list = PuppetSyntax::RakeTask.new.filelist(['**/lib', known_pp]) expect(list.count).to eq 1 expect(list).to include(known_pp) end it 'should generate FileList of manifests relative to Rakefile' do list = PuppetSyntax::RakeTask.new.filelist_manifests expect(list).to include(known_pp) expect(list.count).to eq 9 end it 'should generate FileList of templates relative to Rakefile' do list = PuppetSyntax::RakeTask.new.filelist_templates expect(list).to include(known_erb) expect(list.count).to eq 9 end it 'should generate FileList of Hiera yaml files relative to Rakefile' do list = PuppetSyntax::RakeTask.new.filelist_hiera_yaml expect(list).to include(known_yaml) expect(list).to include(known_eyaml) expect(list).to include(known_yaml_subdir) expect(list).to include(known_eyaml_subdir) expect(list.count).to eq 4 end end puppet-syntax-3.1.0/spec/puppet-syntax/manifests_spec.rb0000644000004100000410000000636213704151232023534 0ustar www-datawww-datarequire 'spec_helper' require 'puppet' describe PuppetSyntax::Manifests do let(:subject) { PuppetSyntax::Manifests.new } it 'should expect an array of files' do expect { subject.check(nil) }.to raise_error(/Expected an array of files/) end it 'should return nothing from a valid file' do files = fixture_manifests('pass.pp') output, has_errors = subject.check(files) expect(output).to eq([]) expect(has_errors).to eq(false) end it 'should return nothing from a valid file with a class using tag parameter' do files = fixture_manifests('tag_notice.pp') output, has_errors = subject.check(files) expect(output).to eq([]) expect(has_errors).to eq(false) end it 'should return nothing from a valid file with a class using schedule parameter' do files = fixture_manifests('schedule_notice.pp') output, has_errors = subject.check(files) expect(output).to eq([]) expect(has_errors).to eq(false) end it 'should return an error from an invalid file' do files = fixture_manifests('fail_error.pp') output, has_errors = subject.check(files) expect(output.size).to eq(3) expect(output[2]).to match(/2 errors. Giving up/) expect(has_errors).to eq(true) end it 'should return a warning from an invalid file' do files = fixture_manifests('fail_warning.pp') output, has_errors = subject.check(files) expect(output.size).to eq(2) expect(has_errors).to eq(true) expect(output[0]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/) expect(output[1]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/) end it 'should ignore warnings about storeconfigs' do files = fixture_manifests('pass_storeconfigs.pp') output, has_errors = subject.check(files) expect(output).to eq([]) expect(has_errors).to eq(false) end it 'should read more than one valid file' do files = fixture_manifests(['pass.pp', 'pass_storeconfigs.pp']) output, has_errors = subject.check(files) expect(output).to eq([]) expect(has_errors).to eq(false) end it 'should continue after finding an error in the first file' do files = fixture_manifests(['fail_error.pp', 'fail_warning.pp']) output, has_errors = subject.check(files) expect(has_errors).to eq(true) expect(output.size).to eq(5) 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 \(file: \S*\/fail_error.pp, line: 2, column: 32\)$/) expect(output[1]).to match(/This Name has no effect. A value was produced and then forgotten \(one or more preceding expressions may have the wrong form\) \(file: \S*\/fail_error.pp, line: 2, column: 3\)$/) expect(output[2]).to match('2 errors. Giving up') expect(output[3]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/) expect(output[4]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/) end describe 'deprecation notices' do it 'should instead be failures' do files = fixture_manifests('deprecation_notice.pp') output, has_errors = subject.check(files) expect(has_errors).to eq(true) expect(output.size).to eq(1) expect(output[0]).to match (/Node inheritance is not supported in Puppet >= 4.0.0/) end end end puppet-syntax-3.1.0/spec/puppet-syntax/hiera_spec.rb0000644000004100000410000000526413704151232022633 0ustar www-datawww-datarequire 'spec_helper' describe PuppetSyntax::Hiera do let(:subject) { PuppetSyntax::Hiera.new } it 'should expect an array of files' do expect { subject.check(nil) }.to raise_error(/Expected an array of files/) end it "should return nothing from valid YAML" do files = fixture_hiera('hiera_good.yaml') res = subject.check(files) expect(res).to be == [] end it "should return an error from invalid YAML" do hiera_yaml = RUBY_VERSION =~ /1.8/ ? 'hiera_bad_18.yaml' : 'hiera_bad.yaml' files = fixture_hiera(hiera_yaml) expected = /ERROR: Failed to parse #{files[0]}:/ res = subject.check(files) expect(res.size).to be == 1 expect(res.first).to match(expected) end context 'check_hiera_keys = true' do before(:each) { PuppetSyntax.check_hiera_keys = true } it "should return warnings for invalid keys" do hiera_yaml = 'hiera_badkey.yaml' examples = 5 files = fixture_hiera(hiera_yaml) res = subject.check(files) (1..examples).each do |n| expect(res).to include(/::warning#{n}/) end expect(res.size).to be == examples expect(res[0]).to match('Key :typical:typo::warning1: Looks like a missing colon') expect(res[1]).to match('Key ::notsotypical::warning2: Puppet automatic lookup will not use leading \'::\'') expect(res[2]).to match('Key :noCamelCase::warning3: Not a valid Puppet variable name for automatic lookup') expect(res[3]).to match('Key :no-hyphens::warning4: Not a valid Puppet variable name for automatic lookup') expect(res[4]).to match('Key :picky::warning5: Puppet automatic lookup will not look up symbols') end it "should return warnings for bad eyaml values" do hiera_yaml = 'hiera_bad.eyaml' examples = 6 files = fixture_hiera(hiera_yaml) res = subject.check(files) (1..examples).each do |n| expect(res).to include(/::warning#{n}/) end expect(res.size).to be == examples expect(res[0]).to match('Key acme::warning1 has unknown eyaml method unknown-method') expect(res[1]).to match('Key acme::warning2 has unterminated eyaml value') expect(res[2]).to match('Key acme::warning3 has unpadded or truncated base64 data') expect(res[3]).to match('Key acme::warning4 has corrupt base64 data') expect(res[4]).to match('Key acme::warning5\[\'key2\'\] has corrupt base64 data') expect(res[5]).to match('Key acme::warning6\[\'hash_key\'\]\[2\] has corrupt base64 data') end it "should handle empty files" do hiera_yaml = 'hiera_key_empty.yaml' files = fixture_hiera(hiera_yaml) res = subject.check(files) expect(res).to be_empty end end end puppet-syntax-3.1.0/spec/spec_helper.rb0000644000004100000410000000075113704151232020155 0ustar www-datawww-datarequire 'rspec' require 'puppet-syntax' def fixture_hiera(list) fixture_files(list, 'hiera') end def fixture_templates(list) fixture_files(list, 'test_module/templates') end def fixture_manifests(list) fixture_files(list, 'test_module/manifests') end def fixture_files(list, path) list = [list].flatten list.map { |f| File.expand_path("../fixtures/#{path}/#{f}", __FILE__) } end RSpec.configure do |config| config.color = true config.formatter = 'documentation' end puppet-syntax-3.1.0/CHANGELOG.md0000644000004100000410000002224013704151232016213 0ustar www-datawww-data# Changelog All notable changes to this project will be documented in this file. ## [v3.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v3.1.0) (2020-06-24) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.1...v3.1.0) **Implemented enhancements:** - print actual template errors on $stderr [\#125](https://github.com/voxpupuli/puppet-syntax/pull/125) ([foxxx0](https://github.com/foxxx0)) **Merged pull requests:** - Add ruby2.7 testing, replacing multiple obsolete puppet6 versions [\#124](https://github.com/voxpupuli/puppet-syntax/pull/124) ([DavidS](https://github.com/DavidS)) ## [v3.0.1](https://github.com/voxpupuli/puppet-syntax/tree/v3.0.1) (2020-05-27) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.0...v3.0.1) **Merged pull requests:** - Avoid failure on schedule metaparameter warning [\#122](https://github.com/voxpupuli/puppet-syntax/pull/122) ([ffapitalle](https://github.com/ffapitalle)) ## [v3.0.0](https://github.com/voxpupuli/puppet-syntax/tree/v3.0.0) (2020-05-09) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.6.1...v3.0.0) **Breaking changes:** - Drop legacy code to support Puppet \< 5 and Ruby \< 2.4 [\#120](https://github.com/voxpupuli/puppet-syntax/pull/120) ([ekohl](https://github.com/ekohl)) **Implemented enhancements:** - Migrate Changelog to GCG [\#93](https://github.com/voxpupuli/puppet-syntax/issues/93) **Merged pull requests:** - cleanup README.md / fix markdown linter warnings [\#119](https://github.com/voxpupuli/puppet-syntax/pull/119) ([bastelfreak](https://github.com/bastelfreak)) ## [v2.6.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.1) (2020-01-11) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.6.0...v2.6.1) **Fixed bugs:** - Add `puppet` gem as runtime dependency [\#116](https://github.com/voxpupuli/puppet-syntax/pull/116) ([bastelfreak](https://github.com/bastelfreak)) **Merged pull requests:** - traivs: run tests on Ubuntu 18.04 [\#117](https://github.com/voxpupuli/puppet-syntax/pull/117) ([bastelfreak](https://github.com/bastelfreak)) - travis: enable irc / disable email notifications [\#114](https://github.com/voxpupuli/puppet-syntax/pull/114) ([bastelfreak](https://github.com/bastelfreak)) ## [v2.6.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.0) (2019-10-05) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.5.0...v2.6.0) **Implemented enhancements:** - add support for validating puppet plans \(fixes \#95, fixes \#96\) [\#97](https://github.com/voxpupuli/puppet-syntax/pull/97) ([slauger](https://github.com/slauger)) - Allow specifying file paths for manifests and templates too [\#87](https://github.com/voxpupuli/puppet-syntax/pull/87) ([lavagetto](https://github.com/lavagetto)) **Merged pull requests:** - Test on ruby 2.6 [\#111](https://github.com/voxpupuli/puppet-syntax/pull/111) ([alexjfisher](https://github.com/alexjfisher)) - Adding KMS tags to allowed EYAML methods [\#105](https://github.com/voxpupuli/puppet-syntax/pull/105) ([craigwatson](https://github.com/craigwatson)) ## [v2.5.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.5.0) (2019-07-07) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.3...v2.5.0) **Implemented enhancements:** - Support puppet 6.5 [\#106](https://github.com/voxpupuli/puppet-syntax/pull/106) ([alexjfisher](https://github.com/alexjfisher)) ## [v2.4.3](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.3) (2019-02-09) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.2...v2.4.3) **Fixed bugs:** - Revert "search manifests in manifests directory" [\#102](https://github.com/voxpupuli/puppet-syntax/pull/102) ([alexjfisher](https://github.com/alexjfisher)) ## [v2.4.2](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.2) (2019-02-08) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.1...v2.4.2) - Search manifests in manifests directory - Allow .yml as an extension for YAML files. - Ensure the pkg directory is always excluded - Check consistency of ENC blobs in eyaml data ## [v2.4.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.1) (2017-06-29) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.0...v2.4.1) - Fix to ensure namespace scope is inherited. - Cleanly exits when syntax warnings/errors are found instead of failing. ## [v2.4.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.0) (2017-03-14) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.3.0...v2.4.0) - Add check_hiera_keys flag for deep checking of Hiera key name correctness. Thanks @petems. - Fix Puppet version comparisons for compatibility with Puppet 4.10. - Fix app_management setting compatibility with Puppet 5. - Refactor PUPPETVERSION usage to Puppet.version public API. ## [v2.3.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.3.0) (2017-02-01) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.2.0...v2.3.0) - Add app_management flag for Puppet application orchestration support. Thanks @ipcrm. - Check all *yaml file extensions, including eyaml. thanks @kjetilho, @rjw1. - Only test ERB syntax in files with an *.erb extension. Thanks @alexiri. - Extend README to list specific files and checks implemented. Thanks @petems. - Refactor Rake filelist generation, add tests. Thanks @kjetilho, @rjw1. ## [v2.2.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.2.0) (2016-12-02) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.1.1...v2.2.0) - Replace Puppet.initialize_settings with Puppet::Test::TestHelper. Thanks @domcleal #60 This clears out caches on every test so increases runtime. ## [v2.1.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.1.1) (2016-10-21) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.1.0...v2.1.1) - Use `$stderr.puts` rather than `warn` and `info` (thanks @mmckinst) - Allow latest 3.x to validate EPP files (thanks @DavidS) ## [v2.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.1.0) (2016-01-18) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.0.0...v2.1.0) - Support Puppet 4. Many thanks to @DavidS - Support validation of EPP templates. Thanks to @trlinkin - Test improvements and refactoring, including Travis CI tests against Puppet 4. Thanks to @trlinkin - Don't error when a tag metaparameter is present. Thank you @dhardy92 - Report the filename of invalid hiera data files. Thanks @danzilio ## [v2.0.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.0.0) (2015-02-26) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.4.1...v2.0.0) - Removed support for Puppet version 2.7.x - New option, fail_on_deprecation_notices, which defaults to true (compatible with previous behaviour); thanks @pcfens - PuppetSyntax::Manifests#check now has two return arguments ## [v1.4.1](https://github.com/voxpupuli/puppet-syntax/tree/v1.4.1) (2015-01-08) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.4.0...v1.4.1) - Support appending to config arrays, thanks @domcleal ## [v1.4.0](https://github.com/voxpupuli/puppet-syntax/tree/v1.4.0) (2014-12-18) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.3.0...v1.4.0) - Rspec 3 is now supported, thanks @tuxmea - Build error fixed where gem_publisher was used prematurely - Lazy load Puppet only when it's required, thanks @logicminds ## [v1.3.0](https://github.com/voxpupuli/puppet-syntax/tree/v1.3.0) (2014-08-07) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.3...v1.3.0) - Add the ability to pass hieradata_paths array of globs to check - Check hieradata in modules ('**/data/**/*.yaml') by default ## [v1.2.3](https://github.com/voxpupuli/puppet-syntax/tree/v1.2.3) (2014-08-06) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.2...v1.2.3) - Fix puppetlabs_spec_helper warning on Ruby 1.8 ## [v1.2.2](https://github.com/voxpupuli/puppet-syntax/tree/v1.2.2) (2014-07-31) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.0...v1.2.2) - Check and document conflicts with puppetlabs_spec_helper <= 0.7.0 ## v1.2.1 (2014-07-23) - Remove dependency on Puppet from Gemspec (for Puppet Entreprise users). ## v1.2.0 (2014-03-28) - Optional support for Puppet's future parser. ## v1.1.1 (2014-03-17) - Ignore exit(1) from Puppet 3.4 - Don't use hardcoded version of parser face. ## v1.1.0 (2013-09-06) - Syntax checks for Hiera YAML files. - Improved documentation. ## v1.0.0 (2013-07-04) - Refactor code to make it easier to test. - Implement spec tests for syntax checks. - Pending spec tests for FileList matching. - Matrix tests for other Ruby/Puppet versions. - Improve usage example in README. ## v0.0.4 (2013-06-14) - Fix `$confdir` error for Puppet 3.x ## v0.0.3 (2013-06-11) - List rake as a dependency. - Output names of tasks to STDERR. - Match template paths correctly. - Add pending spec tests, not yet working. ## v0.0.2 (2013-06-10) - Fix namespacing of rake tasks. ## v0.0.1 (2013-06-10) - Initial release \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* puppet-syntax-3.1.0/.gitignore0000644000004100000410000000026213704151232016372 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp vendor/ .idea/ .vendor/ puppet-syntax-3.1.0/Rakefile0000644000004100000410000000145313704151232016052 0ustar www-datawww-datarequire 'rspec/core/rake_task' RSpec::Core::RakeTask.new('spec') task :publish_gem do require 'gem_publisher' gem = GemPublisher.publish_if_updated('puppet-syntax.gemspec', :rubygems) puts "Published #{gem}" if gem end task :default => [:spec] begin require 'github_changelog_generator/task' require 'puppet-syntax/version' GitHubChangelogGenerator::RakeTask.new :changelog do |config| version = PuppetSyntax::VERSION config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file." config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} config.user = 'voxpupuli' config.project = 'puppet-syntax' end rescue LoadError end puppet-syntax-3.1.0/lib/0000755000004100000410000000000013704151232015150 5ustar www-datawww-datapuppet-syntax-3.1.0/lib/puppet-syntax/0000755000004100000410000000000013704151232020011 5ustar www-datawww-datapuppet-syntax-3.1.0/lib/puppet-syntax/version.rb0000644000004100000410000000005413704151232022022 0ustar www-datawww-datamodule PuppetSyntax VERSION = '3.1.0' end puppet-syntax-3.1.0/lib/puppet-syntax/tasks/0000755000004100000410000000000013704151232021136 5ustar www-datawww-datapuppet-syntax-3.1.0/lib/puppet-syntax/tasks/puppet-syntax.rb0000644000004100000410000000425113704151232024326 0ustar www-datawww-datarequire 'puppet-syntax' require 'rake' require 'rake/tasklib' module PuppetSyntax class RakeTask < ::Rake::TaskLib def filelist(paths) excludes = PuppetSyntax.exclude_paths excludes.push('pkg/**/*') files = FileList[paths] files.reject! { |f| File.directory?(f) } files.exclude(*excludes) end def filelist_manifests filelist(PuppetSyntax.manifests_paths) end def filelist_templates filelist(PuppetSyntax.templates_paths) end def filelist_hiera_yaml filelist(PuppetSyntax.hieradata_paths) end def initialize(*args) desc 'Syntax check Puppet manifests and templates' task :syntax => [ 'syntax:manifests', 'syntax:templates', 'syntax:hiera', ] namespace :syntax do desc 'Syntax check Puppet manifests' task :manifests do |t| $stderr.puts "---> #{t.name}" c = PuppetSyntax::Manifests.new output, has_errors = c.check(filelist_manifests) $stdout.puts "#{output.join("\n")}\n" unless output.empty? exit 1 if has_errors || ( output.any? && PuppetSyntax.fail_on_deprecation_notices ) end desc 'Syntax check Puppet templates' task :templates do |t| $stderr.puts "---> #{t.name}" c = PuppetSyntax::Templates.new result = c.check(filelist_templates) unless result[:warnings].empty? $stdout.puts "WARNINGS:" $stdout.puts result[:warnings].join("\n") end unless result[:errors].empty? $stderr.puts "ERRORS:" $stderr.puts result[:errors].join("\n") exit 1 end end desc 'Syntax check Hiera config files' task :hiera => [ 'syntax:hiera:yaml', ] namespace :hiera do task :yaml do |t| $stderr.puts "---> #{t.name}" c = PuppetSyntax::Hiera.new errors = c.check(filelist_hiera_yaml) $stdout.puts "#{errors.join("\n")}\n" unless errors.empty? exit 1 unless errors.empty? end end end end end end PuppetSyntax::RakeTask.new puppet-syntax-3.1.0/lib/puppet-syntax/templates.rb0000644000004100000410000000532413704151232022340 0ustar www-datawww-datarequire 'erb' require 'puppet' require 'stringio' module PuppetSyntax class Templates def check(filelist) raise "Expected an array of files" unless filelist.is_a?(Array) # We now have to redirect STDERR in order to capture warnings. $stderr = warnings = StringIO.new() result = { warnings: [], errors: [] } filelist.each do |file| if File.extname(file) == '.epp' or PuppetSyntax.epp_only tmp = validate_epp(file) elsif File.extname(file) == '.erb' tmp = validate_erb(file) end result.merge!(tmp) { |k, a, b| a.concat(b) } unless tmp.nil? end $stderr = STDERR result[:warnings] << warnings.string unless warnings.string.empty? result[:errors].map! { |e| e.to_s } result[:warnings].map! { |w| w.to_s } result end def validate_epp(filename) require 'puppet/pops' result = { warnings: [], errors: [] } formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new evaluating_parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new() parser = evaluating_parser.parser() begin parse_result = parser.parse_file(filename) validation_result = evaluating_parser.validate(parse_result.model) # print out any warnings validation_result.warnings.each do |warn| message = formatter.format_message(warn) file = warn.file line = warn.source_pos.line column = warn.source_pos.pos result[:warnings] << "#{file}:#{line}:#{column}: #{message}" end # collect errors and return them in order to indicate validation failure validation_result.errors.each do |err| message = formatter.format_message(err) file = err.file line = err.source_pos.line column = err.source_pos.pos result[:errors] << "#{file}:#{line}:#{column}: #{message}" end rescue Puppet::ParseError, SyntaxError => exc result[:errors] << exc rescue => exc result[:errors] << exc end result end def validate_erb(filename) result = { warnings: [], errors: [] } begin erb = ERB.new(File.read(filename), nil, '-') erb.filename = filename erb.result rescue NameError => error # This is normal because we don't have the variables that would # ordinarily be bound by the parent Puppet manifest. rescue TypeError # This is normal because we don't have the variables that would # ordinarily be bound by the parent Puppet manifest. rescue SyntaxError => error result[:errors] << error end result end end end puppet-syntax-3.1.0/lib/puppet-syntax/manifests.rb0000644000004100000410000000420413704151232022327 0ustar www-datawww-datamodule PuppetSyntax class Manifests def check(filelist) raise "Expected an array of files" unless filelist.is_a?(Array) require 'puppet' require 'puppet/face' require 'puppet/test/test_helper' output = [] Puppet::Test::TestHelper.initialize Puppet::Test::TestHelper.before_all_tests called_before_all_tests = true # Catch syntax warnings. Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(output)) Puppet::Util::Log.level = :warning filelist.each do |puppet_file| Puppet::Test::TestHelper.before_each_test begin error = validate_manifest(puppet_file) if error.is_a?(Hash) # Puppet 6.5.0 onwards output << error.values.first unless error.empty? end rescue SystemExit # Disregard exit(1) from face. # This is how puppet < 6.5.0 `validate_manifest` worked. rescue => error output << error ensure Puppet::Test::TestHelper.after_each_test end end Puppet::Util::Log.close_all output.map! { |e| e.to_s } # Exported resources will raise warnings when outside a puppetmaster. output.reject! { |e| e =~ /^You cannot collect( exported resources)? without storeconfigs being set/ } # tag and schedule parameters in class raise warnings notice in output that prevent from succeed output.reject! { |e| e =~ /^(tag|schedule) is a metaparam; this value will inherit to all contained resources in the / } deprecations = output.select { |e| e =~ /^Deprecation notice:|is deprecated/ } # Errors exist if there is any output that isn't a deprecation notice. has_errors = (output != deprecations) return output, has_errors ensure Puppet::Test::TestHelper.after_all_tests if called_before_all_tests end private def validate_manifest(file) Puppet[:tasks] = true if Puppet::Util::Package.versioncmp(Puppet.version, '5.4.0') >= 0 and file.match(/.*plans\/.*\.pp$/) Puppet::Face[:parser, :current].validate(file) end end end puppet-syntax-3.1.0/lib/puppet-syntax/hiera.rb0000644000004100000410000000556213704151232021436 0ustar www-datawww-datarequire 'yaml' require 'base64' module PuppetSyntax class Hiera def check_hiera_key(key) if key.is_a? Symbol if key.to_s.start_with?(':') return "Puppet automatic lookup will not use leading '::'" elsif key !~ /^[a-z]+$/ # we allow Hiera's own configuration return "Puppet automatic lookup will not look up symbols" end elsif key !~ /^[a-z][a-z0-9_]+(::[a-z][a-z0-9_]+)*$/ if key =~ /[^:]:[^:]/ # be extra helpful return "Looks like a missing colon" else return "Not a valid Puppet variable name for automatic lookup" end end end # Recurse through complex data structures. Return on first error. def check_eyaml_data(name, val) error = nil if val.is_a? String err = check_eyaml_blob(val) error = "Key #{name} #{err}" if err elsif val.is_a? Array val.each_with_index do |v, idx| error = check_eyaml_data("#{name}[#{idx}]", v) break if error end elsif val.is_a? Hash val.each do |k,v| error = check_eyaml_data("#{name}['#{k}']", v) break if error end end error end def check_eyaml_blob(val) return unless val =~ /^ENC\[/ val.sub!('ENC[', '') val.gsub!(/\s+/, '') if val !~ /\]$/ return "has unterminated eyaml value" else val.sub!(/\]$/, '') method, base64 = val.split(/,/) if base64 == nil base64 = method method = 'PKCS7' end return "has unknown eyaml method #{method}" unless ['PKCS7','GPG','GKMS','KMS'].include? method return "has unpadded or truncated base64 data" unless base64.length % 4 == 0 # Base64#decode64 will silently ignore characters outside the alphabet, # so we check resulting length of binary data instead pad_length = base64.gsub(/[^=]/, '').length if Base64.decode64(base64).length != base64.length * 3/4 - pad_length return "has corrupt base64 data" end end end def check(filelist) raise "Expected an array of files" unless filelist.is_a?(Array) errors = [] filelist.each do |hiera_file| begin yamldata = YAML.load_file(hiera_file) rescue Exception => error errors << "ERROR: Failed to parse #{hiera_file}: #{error}" next end if yamldata yamldata.each do |k,v| if PuppetSyntax.check_hiera_keys key_msg = check_hiera_key(k) errors << "WARNING: #{hiera_file}: Key :#{k}: #{key_msg}" if key_msg end eyaml_msg = check_eyaml_data(k, v) errors << "WARNING: #{hiera_file}: #{eyaml_msg}" if eyaml_msg end end end errors.map! { |e| e.to_s } errors end end end puppet-syntax-3.1.0/lib/puppet-syntax.rb0000644000004100000410000000142513704151232020340 0ustar www-datawww-datarequire "puppet-syntax/version" require "puppet-syntax/manifests" require "puppet-syntax/templates" require "puppet-syntax/hiera" require "puppet/version" module PuppetSyntax @exclude_paths = [] @hieradata_paths = [ "**/data/**/*.*{yaml,yml}", "hieradata/**/*.*{yaml,yml}", "hiera*.*{yaml,yml}" ] @manifests_paths = [ '**/*.pp' ] @templates_paths = [ '**/templates/**/*.erb', '**/templates/**/*.epp' ] @fail_on_deprecation_notices = true @check_hiera_keys = false class << self attr_accessor :exclude_paths, :hieradata_paths, :manifests_paths, :templates_paths, :fail_on_deprecation_notices, :epp_only, :check_hiera_keys end end puppet-syntax-3.1.0/puppet-syntax.gemspec0000644000004100000410000000211113704151232020603 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppet-syntax/version' Gem::Specification.new do |spec| spec.name = "puppet-syntax" spec.version = PuppetSyntax::VERSION spec.authors = ["Vox Pupuli"] spec.email = ["voxpupuli@groups.io"] spec.description = %q{Syntax checks for Puppet manifests and templates} spec.summary = %q{Syntax checks for Puppet manifests, templates, and Hiera YAML} spec.homepage = "https://github.com/voxpupuli/puppet-syntax" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.4" spec.add_dependency "rake" spec.add_dependency "puppet", ">= 5" spec.add_development_dependency "pry" spec.add_development_dependency "rb-readline" spec.add_development_dependency "gem_publisher", "~> 1.3" end puppet-syntax-3.1.0/Gemfile0000644000004100000410000000212313704151232015673 0ustar www-datawww-datasource 'https://rubygems.org' # Find a location or specific version for a gem. place_or_version can be a # version, which is most often used. It can also be git, which is specified as # `git://somewhere.git#branch`. You can also use a file source location, which # is specified as `file://some/location/on/disk`. def location_for(place_or_version, fake_version = nil) if place_or_version =~ /^(git[:@][^#]*)#(.*)/ [fake_version, { :git => $1, :branch => $2, :require => false }].compact elsif place_or_version =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else [place_or_version, { :require => false }] end end # Specify your gem's dependencies in puppet-syntax.gemspec gemspec # Override gemspec for CI matrix builds. # But only if the environment variable is set gem 'puppet', *location_for(ENV['PUPPET_VERSION'] || '>= 5') if ENV['PUPPET_VERSION'] group :test do gem 'rspec' end group :release do gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' end puppet-syntax-3.1.0/HISTORY.md0000644000004100000410000001243713704151232016074 0ustar www-datawww-data## [v2.4.2](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.2) (2019-02-08) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.1...v2.4.2) - Search manifests in manifests directory - Allow .yml as an extension for YAML files. - Ensure the pkg directory is always excluded - Check consistency of ENC blobs in eyaml data ## [v2.4.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.1) (2017-06-29) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.0...v2.4.1) - Fix to ensure namespace scope is inherited. - Cleanly exits when syntax warnings/errors are found instead of failing. ## [v2.4.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.4.0) (2017-03-14) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.3.0...v2.4.0) - Add check_hiera_keys flag for deep checking of Hiera key name correctness. Thanks @petems. - Fix Puppet version comparisons for compatibility with Puppet 4.10. - Fix app_management setting compatibility with Puppet 5. - Refactor PUPPETVERSION usage to Puppet.version public API. ## [v2.3.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.3.0) (2017-02-01) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.2.0...v2.3.0) - Add app_management flag for Puppet application orchestration support. Thanks @ipcrm. - Check all *yaml file extensions, including eyaml. thanks @kjetilho, @rjw1. - Only test ERB syntax in files with an *.erb extension. Thanks @alexiri. - Extend README to list specific files and checks implemented. Thanks @petems. - Refactor Rake filelist generation, add tests. Thanks @kjetilho, @rjw1. ## [v2.2.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.2.0) (2016-12-02) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.1.1...v2.2.0) - Replace Puppet.initialize_settings with Puppet::Test::TestHelper. Thanks @domcleal #60 This clears out caches on every test so increases runtime. ## [v2.1.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.1.1) (2016-10-21) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.1.0...v2.1.1) - Use `$stderr.puts` rather than `warn` and `info` (thanks @mmckinst) - Allow latest 3.x to validate EPP files (thanks @DavidS) ## [v2.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.1.0) (2016-01-18) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.0.0...v2.1.0) - Support Puppet 4. Many thanks to @DavidS - Support validation of EPP templates. Thanks to @trlinkin - Test improvements and refactoring, including Travis CI tests against Puppet 4. Thanks to @trlinkin - Don't error when a tag metaparameter is present. Thank you @dhardy92 - Report the filename of invalid hiera data files. Thanks @danzilio ## [v2.0.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.0.0) (2015-02-26) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.4.1...v2.0.0) - Removed support for Puppet version 2.7.x - New option, fail_on_deprecation_notices, which defaults to true (compatible with previous behaviour); thanks @pcfens - PuppetSyntax::Manifests#check now has two return arguments ## [v1.4.1](https://github.com/voxpupuli/puppet-syntax/tree/v1.4.1) (2015-01-08) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.4.0...v1.4.1) - Support appending to config arrays, thanks @domcleal ## [v1.4.0](https://github.com/voxpupuli/puppet-syntax/tree/v1.4.0) (2014-12-18) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.3.0...v1.4.0) - Rspec 3 is now supported, thanks @tuxmea - Build error fixed where gem_publisher was used prematurely - Lazy load Puppet only when it's required, thanks @logicminds ## [v1.3.0](https://github.com/voxpupuli/puppet-syntax/tree/v1.3.0) (2014-08-07) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.3...v1.3.0) - Add the ability to pass hieradata_paths array of globs to check - Check hieradata in modules ('**/data/**/*.yaml') by default ## [v1.2.3](https://github.com/voxpupuli/puppet-syntax/tree/v1.2.3) (2014-08-06) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.2...v1.2.3) - Fix puppetlabs_spec_helper warning on Ruby 1.8 ## [v1.2.2](https://github.com/voxpupuli/puppet-syntax/tree/v1.2.2) (2014-07-31) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v1.2.0...v1.2.2) - Check and document conflicts with puppetlabs_spec_helper <= 0.7.0 ## v1.2.1 (2014-07-23) - Remove dependency on Puppet from Gemspec (for Puppet Entreprise users). ## v1.2.0 (2014-03-28) - Optional support for Puppet's future parser. ## v1.1.1 (2014-03-17) - Ignore exit(1) from Puppet 3.4 - Don't use hardcoded version of parser face. ## v1.1.0 (2013-09-06) - Syntax checks for Hiera YAML files. - Improved documentation. ## v1.0.0 (2013-07-04) - Refactor code to make it easier to test. - Implement spec tests for syntax checks. - Pending spec tests for FileList matching. - Matrix tests for other Ruby/Puppet versions. - Improve usage example in README. ## v0.0.4 (2013-06-14) - Fix `$confdir` error for Puppet 3.x ## v0.0.3 (2013-06-11) - List rake as a dependency. - Output names of tasks to STDERR. - Match template paths correctly. - Add pending spec tests, not yet working. ## v0.0.2 (2013-06-10) - Fix namespacing of rake tasks. ## v0.0.1 (2013-06-10) - Initial release puppet-syntax-3.1.0/LICENSE.txt0000644000004100000410000000205313704151232016225 0ustar www-datawww-dataCopyright (c) 2013 Dan Carley MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.