puppet-syntax 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/lib/puppet-syntax.rb +13 -0
- data/lib/puppet-syntax/manifests.rb +35 -0
- data/lib/puppet-syntax/tasks/puppet-syntax.rb +33 -0
- data/lib/puppet-syntax/templates.rb +32 -0
- data/lib/puppet-syntax/version.rb +3 -0
- data/puppet-syntax.gemspec +26 -0
- data/spec/puppet-syntax_spec.rb +12 -0
- data/spec/spec_helper.rb +7 -0
- metadata +132 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dan Carley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Puppet::Syntax
|
2
|
+
|
3
|
+
Syntax checks for Puppet manifests and templates
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Include the following in your `Rakefile`:
|
8
|
+
|
9
|
+
require 'puppet-syntax/tasks/puppet-syntax'
|
10
|
+
|
11
|
+
Paths can be excluded with:
|
12
|
+
|
13
|
+
PuppetSyntax.exclude_paths = ["vendor/**/*"]
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'puppet-syntax'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install puppet-syntax
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
require 'puppet/face'
|
3
|
+
|
4
|
+
module PuppetSyntax
|
5
|
+
class Manifests
|
6
|
+
def validate_manifest(file)
|
7
|
+
Puppet::Face[:parser, '0.0.1'].validate(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def check
|
11
|
+
errors = []
|
12
|
+
|
13
|
+
# Catch syntax warnings.
|
14
|
+
Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(errors))
|
15
|
+
Puppet::Util::Log.level = :warning
|
16
|
+
|
17
|
+
matched_files = FileList["**/*.pp"].exclude(*PuppetSyntax.exclude_paths)
|
18
|
+
matched_files.each do |puppet_file|
|
19
|
+
begin
|
20
|
+
validate_manifest(puppet_file)
|
21
|
+
rescue => error
|
22
|
+
errors << error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Exported resources will raise warnings when outside a puppetmaster.
|
27
|
+
Puppet::Util::Log.close_all
|
28
|
+
errors.reject! { |e|
|
29
|
+
e.to_s =~ /^You cannot collect( exported resources)? without storeconfigs being set/
|
30
|
+
}
|
31
|
+
|
32
|
+
errors
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'puppet-syntax'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module PuppetSyntax
|
6
|
+
class RakeTask < ::Rake::TaskLib
|
7
|
+
def initialize(*args)
|
8
|
+
desc 'Syntax check Puppet manifests and templates'
|
9
|
+
task :syntax => [
|
10
|
+
:manifests,
|
11
|
+
:templates,
|
12
|
+
]
|
13
|
+
|
14
|
+
namespace :syntax do
|
15
|
+
desc 'Syntax check Puppet manifests'
|
16
|
+
task :manifests do
|
17
|
+
c = PuppetSyntax::Manifests.new
|
18
|
+
errors = c.check
|
19
|
+
fail errors.join("\n") unless errors.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Syntax check Puppet templates'
|
23
|
+
task :templates do
|
24
|
+
c = PuppetSyntax::Templates.new
|
25
|
+
errors = c.check
|
26
|
+
fail errors.join("\n") unless errors.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
PuppetSyntax::RakeTask.new
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module PuppetSyntax
|
5
|
+
class Templates
|
6
|
+
def check
|
7
|
+
# We now have to redirect STDERR in order to capture warnings.
|
8
|
+
$stderr = warnings = StringIO.new()
|
9
|
+
errors = []
|
10
|
+
|
11
|
+
# Templates don't have to have a .erb extension
|
12
|
+
matched_files = FileList["*/templates/**/*"].exclude(*PuppetSyntax.exclude_paths)
|
13
|
+
matched_files.reject! { |f| File.directory?(f) }
|
14
|
+
matched_files.each do |erb_file|
|
15
|
+
begin
|
16
|
+
erb = ERB.new(File.read(erb_file), nil, '-')
|
17
|
+
erb.filename = erb_file
|
18
|
+
erb.result
|
19
|
+
rescue NameError
|
20
|
+
# This is normal because we don't have the variables that would
|
21
|
+
# ordinarily be bound by the parent Puppet manifest.
|
22
|
+
rescue StandardError, SyntaxError => error
|
23
|
+
errors << error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
$stderr = STDERR
|
28
|
+
errors << warnings.string unless warnings.string.empty?
|
29
|
+
errors
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'puppet-syntax/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "puppet-syntax"
|
8
|
+
spec.version = PuppetSyntax::VERSION
|
9
|
+
spec.authors = ["Dan Carley"]
|
10
|
+
spec.email = ["dan.carley@gmail.com"]
|
11
|
+
spec.description = %q{Syntax checks for Puppet manifests and templates}
|
12
|
+
spec.summary = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "puppet", ">= 2.7.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetSyntax do
|
4
|
+
it 'should default exclude_paths to empty array' do
|
5
|
+
PuppetSyntax.exclude_paths.should be_empty
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should support setting exclude_paths' do
|
9
|
+
PuppetSyntax.exclude_paths = ["foo", "bar/baz"]
|
10
|
+
PuppetSyntax.exclude_paths.should == ["foo", "bar/baz"]
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-syntax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Carley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: puppet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.7.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.7.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Syntax checks for Puppet manifests and templates
|
79
|
+
email:
|
80
|
+
- dan.carley@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/puppet-syntax.rb
|
92
|
+
- lib/puppet-syntax/manifests.rb
|
93
|
+
- lib/puppet-syntax/tasks/puppet-syntax.rb
|
94
|
+
- lib/puppet-syntax/templates.rb
|
95
|
+
- lib/puppet-syntax/version.rb
|
96
|
+
- puppet-syntax.gemspec
|
97
|
+
- spec/puppet-syntax_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: ''
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: 1593358507914963117
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: 1593358507914963117
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.23
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: ''
|
130
|
+
test_files:
|
131
|
+
- spec/puppet-syntax_spec.rb
|
132
|
+
- spec/spec_helper.rb
|