puppet-validator 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/puppet-validator +3 -3
- data/lib/puppet-validator.rb +36 -7
- data/public/scripts.js +37 -0
- data/public/styles.css +33 -0
- data/public/testing.html +11 -11
- data/views/index.erb +20 -8
- data/views/result.erb +5 -5
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b24ee105fe4fa68c0d60cf4593248232f523aef
|
4
|
+
data.tar.gz: f62cee3a178109d601c0612238fafbebcd366f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a671e7c893f4230cb78d4e8a51dd93a2cf75c5143e170042e30809bae8950649baf56731b42bfb9570964bf8bc20e04631fa31fbe67d01f58424356b9525048
|
7
|
+
data.tar.gz: f9efab3576309a27cb89a13ec5c4615acc8b13c4e42045801fc3436f8ec6ddd51836c71b65edc66e8aec3094e5fe5454021ac7287c278c2dd72da36d0cd44d92
|
data/bin/puppet-validator
CHANGED
@@ -16,11 +16,11 @@ loglevel = Logger::WARN
|
|
16
16
|
|
17
17
|
optparse = OptionParser.new { |opts|
|
18
18
|
opts.banner = "Usage : puppet-validator [-p <port>] [-l [logfile]] [-t <themedir>] [-d]
|
19
|
-
|
19
|
+
-- Runs the Puppet Validator code validation service.
|
20
20
|
|
21
21
|
puppet-validator init
|
22
|
-
|
23
|
-
|
22
|
+
-- Copies the files needed to create a puppet-validator theme into $CWD.
|
23
|
+
This will overwrite existing files.
|
24
24
|
|
25
25
|
"
|
26
26
|
|
data/lib/puppet-validator.rb
CHANGED
@@ -19,9 +19,10 @@ class PuppetValidator < Sinatra::Base
|
|
19
19
|
def initialize(app=nil)
|
20
20
|
super(app)
|
21
21
|
|
22
|
+
Puppet.initialize_settings if Puppet.version.to_i >= 3
|
23
|
+
|
22
24
|
# there must be a better way
|
23
25
|
if settings.respond_to? :disabled_lint_checks
|
24
|
-
|
25
26
|
# can pass in an array, a filename, or a list of checks
|
26
27
|
if settings.disabled_lint_checks.class == String
|
27
28
|
path = File.expand_path(settings.disabled_lint_checks)
|
@@ -46,6 +47,9 @@ class PuppetValidator < Sinatra::Base
|
|
46
47
|
end
|
47
48
|
|
48
49
|
get '/' do
|
50
|
+
@disabled = settings.disabled_lint_checks
|
51
|
+
@checks = puppet_lint_checks
|
52
|
+
|
49
53
|
erb :index
|
50
54
|
end
|
51
55
|
|
@@ -55,7 +59,7 @@ class PuppetValidator < Sinatra::Base
|
|
55
59
|
|
56
60
|
if request.body.size <= MAXSIZE
|
57
61
|
result = validate params['code']
|
58
|
-
lint = lint
|
62
|
+
lint = lint(params['code'], params['checks']) if params['lint'] == 'on'
|
59
63
|
lint ||= {} # but make sure we have a data object to iterate
|
60
64
|
|
61
65
|
@code = params['code']
|
@@ -95,10 +99,17 @@ class PuppetValidator < Sinatra::Base
|
|
95
99
|
|
96
100
|
def validate(data)
|
97
101
|
begin
|
102
|
+
Puppet.settings[:app_management] = true if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.3.2')
|
103
|
+
|
98
104
|
Puppet[:code] = data
|
99
|
-
validation_environment = Puppet.lookup(:current_environment)
|
100
105
|
|
101
|
-
|
106
|
+
if Puppet::Node::Environment.respond_to?(:create)
|
107
|
+
validation_environment = Puppet::Node::Environment.create(:production, [])
|
108
|
+
validation_environment.check_for_reparse
|
109
|
+
else
|
110
|
+
validation_environment = Puppet::Node::Environment.new(:production)
|
111
|
+
end
|
112
|
+
|
102
113
|
validation_environment.known_resource_types.clear
|
103
114
|
|
104
115
|
{:status => true, :message => 'Syntax OK'}
|
@@ -111,10 +122,24 @@ class PuppetValidator < Sinatra::Base
|
|
111
122
|
end
|
112
123
|
end
|
113
124
|
|
114
|
-
def lint(data)
|
125
|
+
def lint(data, checks=nil)
|
115
126
|
begin
|
116
|
-
|
117
|
-
|
127
|
+
if checks
|
128
|
+
logger.info "Disabling checks: #{(puppet_lint_checks - checks).inspect}"
|
129
|
+
|
130
|
+
checks.each do |check|
|
131
|
+
PuppetLint.configuration.send("enable_#{check}")
|
132
|
+
end
|
133
|
+
|
134
|
+
(puppet_lint_checks - checks).each do |check|
|
135
|
+
PuppetLint.configuration.send("disable_#{check}")
|
136
|
+
end
|
137
|
+
else
|
138
|
+
logger.info "Disabling checks: #{settings.disabled_lint_checks.inspect}"
|
139
|
+
|
140
|
+
settings.disabled_lint_checks.each do |check|
|
141
|
+
PuppetLint.configuration.send("disable_#{check}")
|
142
|
+
end
|
118
143
|
end
|
119
144
|
|
120
145
|
linter = PuppetLint.new
|
@@ -127,6 +152,10 @@ class PuppetValidator < Sinatra::Base
|
|
127
152
|
end
|
128
153
|
end
|
129
154
|
|
155
|
+
def puppet_lint_checks
|
156
|
+
# sanitize because reasonss
|
157
|
+
PuppetLint.configuration.checks.map {|check| check.to_s}
|
158
|
+
end
|
130
159
|
|
131
160
|
end
|
132
161
|
end
|
data/public/scripts.js
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
function toggleChecks() {
|
2
|
+
var enabled = $('input#lint').is(":checked");
|
3
|
+
|
4
|
+
$('ul#checks input').attr('disabled', ! enabled);
|
5
|
+
}
|
6
|
+
|
7
|
+
function toggleMenu() {
|
8
|
+
$('#checks-menu').slideToggle();
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
|
12
|
+
$( document ).ready(function() {
|
13
|
+
toggleChecks();
|
14
|
+
|
15
|
+
$("textarea#code").keydown(function(e) {
|
16
|
+
if(e.keyCode === 9) { // tab was pressed
|
17
|
+
// get caret position/selection
|
18
|
+
var start = this.selectionStart;
|
19
|
+
var end = this.selectionEnd;
|
20
|
+
|
21
|
+
var $this = $(this);
|
22
|
+
var value = $this.val();
|
23
|
+
|
24
|
+
// set textarea value to: text before caret + tab + text after caret
|
25
|
+
$this.val(value.substring(0, start)
|
26
|
+
+ "\t"
|
27
|
+
+ value.substring(end));
|
28
|
+
|
29
|
+
// put caret at right position again (add one for the tab)
|
30
|
+
this.selectionStart = this.selectionEnd = start + 1;
|
31
|
+
|
32
|
+
// prevent the loss of focus
|
33
|
+
e.preventDefault();
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
});
|
data/public/styles.css
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
body {
|
2
|
+
min-width: 690px;
|
2
3
|
padding: 0 2em;
|
3
4
|
}
|
4
5
|
|
6
|
+
/* keeps the tooltip from clipping to the pre */
|
7
|
+
pre[class*="language-"] {
|
8
|
+
overflow: visible;
|
9
|
+
}
|
5
10
|
div.line-highlight {
|
6
11
|
/* Cannot use opacity, because that affects tooltip children as well */
|
7
12
|
background-color: rgba(255, 181, 181, 0.25);
|
@@ -82,6 +87,34 @@ div.entry {
|
|
82
87
|
width: 100%;
|
83
88
|
}
|
84
89
|
|
90
|
+
a.button {
|
91
|
+
font-size: small;
|
92
|
+
background-color: #fff;
|
93
|
+
padding: 0 2px;
|
94
|
+
border: 1px solid #fff;
|
95
|
+
border-radius: 3px;
|
96
|
+
text-decoration: none;
|
97
|
+
}
|
98
|
+
a.button:hover {
|
99
|
+
background-color: #efefef;
|
100
|
+
border-color: #bbb;
|
101
|
+
}
|
102
|
+
fieldset.menu {
|
103
|
+
display: none;
|
104
|
+
border-radius: 0.5em;
|
105
|
+
}
|
106
|
+
fieldset.menu ul {
|
107
|
+
list-style-type: none;
|
108
|
+
padding: 0;
|
109
|
+
margin: 0;
|
110
|
+
-moz-column-count: 2;
|
111
|
+
-moz-column-gap: 20px;
|
112
|
+
-webkit-column-count: 2;
|
113
|
+
-webkit-column-gap: 20px;
|
114
|
+
column-count: 2;
|
115
|
+
column-gap: 20px;
|
116
|
+
}
|
117
|
+
|
85
118
|
p.info {
|
86
119
|
background: #fefefe url('info.png') no-repeat 5px 5px !important;
|
87
120
|
border: 1px solid #efefef;
|
data/public/testing.html
CHANGED
@@ -2,16 +2,15 @@
|
|
2
2
|
<head>
|
3
3
|
<title>Puppet Validator</title>
|
4
4
|
<link rel="stylesheet" href="styles.css">
|
5
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
5
6
|
</head>
|
6
7
|
<body>
|
7
8
|
<h1>Testing Puppet Code</h1>
|
8
9
|
<p>
|
9
|
-
This tool will validate the Puppet DSL syntax
|
10
|
-
any
|
11
|
-
|
12
|
-
|
13
|
-
<a href="https://docs.puppetlabs.com/puppet/latest/reference/lang_visual_index.html">Puppet Language Guide</a>
|
14
|
-
if you need help understanding the syntax.
|
10
|
+
This tool will validate the Puppet DSL syntax. It won't actually compile a catalog or
|
11
|
+
enforce any configuration state. This means that this <em>only validates syntax</em>.
|
12
|
+
There are many ways in which a Puppet manifest may have valid syntax but be completely
|
13
|
+
incorrect for your purposes and not do what you intend.
|
15
14
|
</p>
|
16
15
|
<p>
|
17
16
|
Some examples of flaws that will not be identified by this tool include:
|
@@ -24,13 +23,14 @@
|
|
24
23
|
</ul>
|
25
24
|
</p>
|
26
25
|
<p>
|
27
|
-
|
26
|
+
Many other resources exist which can help make sure your code actually works as intended.
|
28
27
|
Some examples are:
|
29
28
|
<ul>
|
30
|
-
<li><a href="https://
|
31
|
-
<li><a href="
|
32
|
-
<li><a href="
|
33
|
-
<li><a href="https://github.com/puppetlabs/
|
29
|
+
<li><a href="https://docs.puppetlabs.com/puppet/latest/reference/lang_visual_index.html">the Puppet Language Guide</a></li>
|
30
|
+
<li><a href="https://github.com/rodjek/puppet-lint">Puppet Lint</a> style validation</li>
|
31
|
+
<li><a href="http://rspec-puppet.com/tutorial/">rspec-puppet</a> unit testing framework</li>
|
32
|
+
<li><a href="https://github.com/puppetlabs/puppetlabs_spec_helper">Puppetlabs Spec Helper</a> for rspec-puppet</li>
|
33
|
+
<li><a href="https://github.com/puppetlabs/beaker">Beaker</a> testing automation platform</li>
|
34
34
|
</ul>
|
35
35
|
</p>
|
36
36
|
<div class="links"><a href="javascript:history.back();">Try Again</a> • <a href="/">Validate More Code</a></div>
|
data/views/index.erb
CHANGED
@@ -2,23 +2,35 @@
|
|
2
2
|
<head>
|
3
3
|
<title>Puppet Validator</title>
|
4
4
|
<link rel="stylesheet" href="styles.css">
|
5
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
6
|
+
<script src="scripts.js"></script>
|
5
7
|
</head>
|
6
8
|
<body>
|
7
9
|
<h1>Puppet Code Validator</h1>
|
8
10
|
<p>Paste Puppet code into the following textbox and check it for validity.</p>
|
9
|
-
<form
|
11
|
+
<form action="/validate" method="post">
|
10
12
|
<div class="entry">
|
11
|
-
<textarea name="code" id="
|
13
|
+
<textarea name="code" id="code" cols="65" rows="25"></textarea>
|
12
14
|
<input type="submit" value="Validate">
|
13
|
-
<input type="checkbox" name="lint">Include <code>puppet-lint</code> style checks
|
15
|
+
<label><input type="checkbox" name="lint" id="lint" onchange="toggleChecks();">Include <code>puppet-lint</code> style checks.</label>
|
16
|
+
<a class="button" href="#" onclick="toggleMenu();">customize ▾</a>
|
17
|
+
<fieldset id="checks-menu" class="menu">
|
18
|
+
<legend>Enabled Lint Checks</legend>
|
19
|
+
<ul id="checks">
|
20
|
+
<% @checks.each do |check| %>
|
21
|
+
<li><label>
|
22
|
+
<input type="checkbox" name="checks[]" value="<%= check %>" id="check_<%= check %>" <% unless @disabled.include? check %>checked<% end %>><%= check %></input>
|
23
|
+
</label></li>
|
24
|
+
<% end %>
|
25
|
+
</ul>
|
26
|
+
</fieldset>
|
14
27
|
</div>
|
15
28
|
</form>
|
16
29
|
<p class="info">
|
17
|
-
Be aware that this <em>only validates syntax</em>. It will not compile
|
18
|
-
catalog
|
19
|
-
identify
|
20
|
-
|
21
|
-
information on testing and validating Puppet code.</a>
|
30
|
+
Be aware that this <em>only validates syntax</em>. It will not compile or
|
31
|
+
enforce a catalog, which means that there are many mistakes that it cannot
|
32
|
+
identify. See <a href="/testing.html">more information on testing and
|
33
|
+
validating Puppet code.</a>
|
22
34
|
</p>
|
23
35
|
</body>
|
24
36
|
</html>
|
data/views/result.erb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
<title>Puppet Validator</title>
|
4
4
|
<link rel="stylesheet" href="prism-default.css">
|
5
5
|
<link rel="stylesheet" href="styles.css">
|
6
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
6
7
|
<script src="prism.js"></script>
|
7
8
|
</head>
|
8
9
|
<body>
|
@@ -27,11 +28,10 @@
|
|
27
28
|
<pre data-line='<%= @highlights %>' class="line-numbers language-puppet"><code class="line-numbers language-puppet"><%= @code %></code></pre>
|
28
29
|
<div class="links"><a href="javascript:history.back();">Try Again</a> • <a href="/">Validate More Code</a></div>
|
29
30
|
<p class="info">
|
30
|
-
Be aware that this has <em>only validated syntax</em>. It will not compile
|
31
|
-
catalog
|
32
|
-
identify
|
33
|
-
|
34
|
-
information on testing and validating Puppet code.</a>
|
31
|
+
Be aware that this has <em>only validated syntax</em>. It will not compile or
|
32
|
+
enforce a catalog, which means that there are many mistakes that it cannot
|
33
|
+
identify. See <a href="/testing.html">more information on testing and
|
34
|
+
validating Puppet code.</a>
|
35
35
|
</p>
|
36
36
|
</body>
|
37
37
|
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: puppet-lint
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- public/info.png
|
71
71
|
- public/prism-default.css
|
72
72
|
- public/prism.js
|
73
|
+
- public/scripts.js
|
73
74
|
- public/styles.css
|
74
75
|
- public/testing.html
|
75
76
|
- views/index.erb
|