puppet-validator 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +117 -5
- data/config.ru +1 -0
- data/lib/puppet-validator.rb +13 -1
- data/public/scripts.js +10 -0
- data/public/styles.css +18 -6
- data/views/index.erb +8 -1
- data/views/result.erb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 505eaa74e80d90d673367e5237c3dc6dee2f9b86
|
4
|
+
data.tar.gz: 3ee36dd07b1cc6019d596f0eab88a07b47fb0067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95dc142ef8c243b021dc156267da2820e24d2cdc2bf68d31c1f14c19f3dc5ce7b0e36bcb8449bc4a5b0205d2f6a4a0134183423dc6aade720a428943cb347ef9
|
7
|
+
data.tar.gz: e944ffdf8cb3d6d555b3c58ad0fd89973a7b32bef5f32577633c953fd5e72fc6ea17a5a754eb8e0502bc6f95cfd2c5bceea3e390d063d36ac56ab49904f6b5cc
|
data/README.md
CHANGED
@@ -16,11 +16,11 @@ Puppet Validator is completely themeable, albeit rather primitively.
|
|
16
16
|
|
17
17
|
This is the simplest way to run Puppet Validator. It has no external dependencies, other
|
18
18
|
than the handful of gems it uses. This command will start the service. It will
|
19
|
-
not daemonize itself, though a `systemd` init script is provided
|
20
|
-
care of that for you. It will default to running on port 9000,
|
21
|
-
content directly out of its installation directory. You can
|
22
|
-
the web content by passing the `-t` or `--theme`
|
23
|
-
[Creating your own theme](#creating-your-own-theme) below.
|
19
|
+
not daemonize itself, though a [`systemd` init script is provided](#running-standalone-with-systemd)
|
20
|
+
that will take care of that for you. It will default to running on port 9000,
|
21
|
+
and will serve content directly out of its installation directory. You can
|
22
|
+
override and customize the web content by passing the `-t` or `--theme`
|
23
|
+
command-line argument. See [Creating your own theme](#creating-your-own-theme) below.
|
24
24
|
|
25
25
|
Options:
|
26
26
|
|
@@ -77,8 +77,10 @@ require 'puppet-validator'
|
|
77
77
|
logger = Logger.new('/var/log/puppet-validator')
|
78
78
|
logger.level = Logger::WARN
|
79
79
|
|
80
|
+
PuppetValidator.set :puppet_versions, Dir.glob('*').select {|f| File.symlink? f and File.readlink(f) == '.' }
|
80
81
|
PuppetValidator.set :root, File.dirname(__FILE__)
|
81
82
|
PuppetValidator.set :logger, logger
|
83
|
+
PuppetValidator.set :disabled_lint_checks, ['80chars']
|
82
84
|
|
83
85
|
run PuppetValidator
|
84
86
|
```
|
@@ -147,3 +149,113 @@ And loading the disabled checks from a file would look like:
|
|
147
149
|
PuppetValidator.set :disabled_lint_checks, '/etc/puppet-validator/disabled_checks'
|
148
150
|
|
149
151
|
```
|
152
|
+
|
153
|
+
#### Validating code against multiple Puppet versions
|
154
|
+
|
155
|
+
It is not very straightforward to load multiple versions of a library gem in Ruby.
|
156
|
+
This makes it virtually impossible to validate multiple versions of the language
|
157
|
+
directly in the tool. However, Passenger has allowed you to load different Ruby
|
158
|
+
versions in different `Location` blocks since version 4.0 by loading separate
|
159
|
+
threads for each.
|
160
|
+
|
161
|
+
We can take advantage of that by configuring multiple Ruby environments using `rvm`
|
162
|
+
or `rbenv` and installing different gemsets. A simple Puppet module to do this
|
163
|
+
is included in the repository, with the caveat that it was designed to fully own
|
164
|
+
a single-purpose VM and has so far only been tested on CentOS 7.
|
165
|
+
|
166
|
+
If configuring manually, you'll need to create a gemset for each Puppet version
|
167
|
+
you want to validate, with something like the following.
|
168
|
+
|
169
|
+
root@master:~ # rvm install ruby-1.9.3-p551
|
170
|
+
Searching for binary rubies, this might take some time.
|
171
|
+
[...]
|
172
|
+
root@master:~ # rvm use 1.9
|
173
|
+
Using /usr/local/rvm/gems/ruby-1.9.3-p551
|
174
|
+
root@master:~ # rvm gemset create puppet2.7.4
|
175
|
+
ruby-1.9.3-p551 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4
|
176
|
+
ruby-1.9.3-p551 - #generating puppet2.7.4 wrappers........
|
177
|
+
root@master:~ # rvm gemset use puppet2.7.4
|
178
|
+
Using ruby-1.9.3-p551 with gemset puppet2.7.4
|
179
|
+
root@master:~ # gem install puppet -v 2.7.4
|
180
|
+
[...]
|
181
|
+
root@master:~ # gem install puppet-validator
|
182
|
+
[...]
|
183
|
+
root@master:~ # passenger-config --ruby-command
|
184
|
+
passenger-config was invoked through the following Ruby interpreter:
|
185
|
+
Command: /usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4/wrappers/ruby
|
186
|
+
Version: ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
|
187
|
+
To use in Apache: PassengerRuby /usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4/wrappers/ruby
|
188
|
+
To use in Nginx : passenger_ruby /usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4/wrappers/ruby
|
189
|
+
To use with Standalone: /usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4/wrappers/ruby /usr/bin/passenger start
|
190
|
+
|
191
|
+
|
192
|
+
## Notes for RVM users
|
193
|
+
Do you want to know which command to use for a different Ruby interpreter? 'rvm use' that Ruby interpreter, then re-run 'passenger-config about ruby-command'.
|
194
|
+
|
195
|
+
Make a note of the `PassengerRuby` command for each gemset. You'll use it in the next step.
|
196
|
+
|
197
|
+
You will need a `Location` block in your Apache `VirtualHost` for each versioned
|
198
|
+
Puppet gemset you created above. The example file below shows blocks for three
|
199
|
+
Puppet versions with the current version installed into the default directory.
|
200
|
+
|
201
|
+
``` Apache
|
202
|
+
<VirtualHost *:80>
|
203
|
+
ServerName vhost.example.com
|
204
|
+
DocumentRoot "/var/www/puppet-validator/public"
|
205
|
+
|
206
|
+
# The default root will validate against the current Puppet version
|
207
|
+
<Directory "/var/www/puppet-validator/public">
|
208
|
+
Options -MultiViews
|
209
|
+
AllowOverride All
|
210
|
+
Require all granted
|
211
|
+
</Directory>
|
212
|
+
|
213
|
+
Alias /2.7.4 /var/www/puppet-validator/2.7.4/public
|
214
|
+
<Location /2.7.4>
|
215
|
+
PassengerBaseURI /2.7.4
|
216
|
+
PassengerAppRoot /var/www/puppet-validator/2.7.4
|
217
|
+
PassengerRuby "/usr/local/rvm/gems/ruby-1.9.3-p551@puppet2.7.4/wrappers/ruby"
|
218
|
+
</Location>
|
219
|
+
|
220
|
+
Alias /3.6.2 /var/www/puppet-validator/3.6.2/public
|
221
|
+
<Location /3.6.2>
|
222
|
+
PassengerBaseURI /3.6.2
|
223
|
+
PassengerAppRoot /var/www/puppet-validator/3.6.2
|
224
|
+
PassengerRuby "/usr/local/rvm/gems/ruby-1.9.3-p551@puppet3.6.2/wrappers/ruby"
|
225
|
+
</Location>
|
226
|
+
|
227
|
+
## Logging
|
228
|
+
ErrorLog "/var/log/httpd/vhost.example.com_error.log"
|
229
|
+
ServerSignature Off
|
230
|
+
CustomLog "/var/log/httpd/vhost.example.com_access.log" combined
|
231
|
+
</VirtualHost>
|
232
|
+
```
|
233
|
+
|
234
|
+
There is one final trick. Passenger requires a unique filesystem location for its
|
235
|
+
`AppRoot`. However, it will respect symlinks, so let's create one for each version:
|
236
|
+
|
237
|
+
root@master:~ # cd /var/www/puppet-validator
|
238
|
+
root@master:~ # ln -s . 2.7.4
|
239
|
+
root@master:~ # ln -s . 3.6.2
|
240
|
+
|
241
|
+
Now restart Apache and you're all gravy.
|
242
|
+
|
243
|
+
#### Running standalone with `systemd`
|
244
|
+
|
245
|
+
A simple `systemd` init script might look something like:
|
246
|
+
|
247
|
+
# /usr/lib/systemd/system/puppet-validator.service
|
248
|
+
[Unit]
|
249
|
+
Description=Puppet Validator
|
250
|
+
After=network.target
|
251
|
+
|
252
|
+
[Service]
|
253
|
+
ExecStart=puppet-validator
|
254
|
+
Restart=on-failure
|
255
|
+
KillSignal=SIGINT
|
256
|
+
|
257
|
+
[Install]
|
258
|
+
WantedBy=multi-user.target
|
259
|
+
|
260
|
+
Customize the command line as needed. You might include a `--theme` or `--port`
|
261
|
+
argument, or you might provide the full path to an `rvm` installed gem.
|
data/config.ru
CHANGED
@@ -4,6 +4,7 @@ require 'puppet-validator'
|
|
4
4
|
logger = Logger.new('/var/log/puppet-validator')
|
5
5
|
logger.level = Logger::WARN
|
6
6
|
|
7
|
+
PuppetValidator.set :puppet_versions, Dir.glob('*').select {|f| File.symlink? f and File.readlink(f) == '.' }
|
7
8
|
PuppetValidator.set :root, File.dirname(__FILE__)
|
8
9
|
PuppetValidator.set :logger, logger
|
9
10
|
PuppetValidator.set :disabled_lint_checks, ['80chars']
|
data/lib/puppet-validator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'logger'
|
2
3
|
require 'sinatra/base'
|
3
4
|
require 'puppet'
|
@@ -19,7 +20,7 @@ class PuppetValidator < Sinatra::Base
|
|
19
20
|
def initialize(app=nil)
|
20
21
|
super(app)
|
21
22
|
|
22
|
-
Puppet.initialize_settings if Puppet.version.to_i
|
23
|
+
Puppet.initialize_settings if Puppet.version.to_i == 3 and Puppet.settings[:confdir].nil?
|
23
24
|
|
24
25
|
# there must be a better way
|
25
26
|
if settings.respond_to? :disabled_lint_checks
|
@@ -44,9 +45,19 @@ class PuppetValidator < Sinatra::Base
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
if settings.respond_to? :puppet_versions
|
49
|
+
# put our supported versions in reverse semver order
|
50
|
+
settings.puppet_versions = settings.puppet_versions.sort_by { |v| Gem::Version.new(v) }.reverse
|
51
|
+
else
|
52
|
+
def settings.puppet_versions
|
53
|
+
[]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
47
57
|
end
|
48
58
|
|
49
59
|
get '/' do
|
60
|
+
@versions = [Puppet.version] + settings.puppet_versions
|
50
61
|
@disabled = settings.disabled_lint_checks
|
51
62
|
@checks = puppet_lint_checks
|
52
63
|
|
@@ -62,6 +73,7 @@ class PuppetValidator < Sinatra::Base
|
|
62
73
|
lint = lint(params['code'], params['checks']) if params['lint'] == 'on'
|
63
74
|
lint ||= {} # but make sure we have a data object to iterate
|
64
75
|
|
76
|
+
@version = Puppet.version
|
65
77
|
@code = params['code']
|
66
78
|
@message = result[:message]
|
67
79
|
@status = result[:status] ? :success : :fail
|
data/public/scripts.js
CHANGED
@@ -34,4 +34,14 @@ $( document ).ready(function() {
|
|
34
34
|
}
|
35
35
|
});
|
36
36
|
|
37
|
+
if ($('select#versions option').length == 1) {
|
38
|
+
$('select#versions').attr('disabled', true);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
$('select#versions').change(function() {
|
42
|
+
var action = ('/' + $( this ).val() + '/validate').replace(/^\/+/, '/');
|
43
|
+
$('form').attr('action', action );
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
37
47
|
});
|
data/public/styles.css
CHANGED
@@ -40,28 +40,35 @@ div.line-highlight.with-tooltip {
|
|
40
40
|
display: block;
|
41
41
|
}
|
42
42
|
|
43
|
-
|
43
|
+
.results {
|
44
44
|
width: 65%;
|
45
45
|
border: 1px solid black;
|
46
46
|
border-radius: 0.25em;
|
47
47
|
padding: 0.5em;
|
48
48
|
margin: 0 auto;
|
49
49
|
}
|
50
|
-
|
50
|
+
.results legend {
|
51
|
+
text-align: right;
|
52
|
+
padding: 3px;
|
53
|
+
background-color: #dedede;
|
54
|
+
border: 1px solid #ccc;
|
55
|
+
border-radius: 3px;
|
56
|
+
}
|
57
|
+
.results.success {
|
51
58
|
background-color: #61ff6e;
|
52
59
|
}
|
53
|
-
|
60
|
+
.results.fail {
|
54
61
|
background-color: #ffb6b6;
|
55
62
|
}
|
56
63
|
|
57
|
-
|
64
|
+
.results p {
|
58
65
|
margin: 0;
|
59
66
|
}
|
60
|
-
|
67
|
+
.results div.row:first-of-type {
|
61
68
|
margin-top: 0.5em;
|
62
69
|
}
|
63
70
|
|
64
|
-
|
71
|
+
.results span.label {
|
65
72
|
width: 7em;
|
66
73
|
font-weight: bold;
|
67
74
|
display: inline-block;
|
@@ -87,6 +94,11 @@ div.entry {
|
|
87
94
|
width: 100%;
|
88
95
|
}
|
89
96
|
|
97
|
+
input#validate,
|
98
|
+
select#versions {
|
99
|
+
margin-right: 2em;
|
100
|
+
}
|
101
|
+
|
90
102
|
a.button {
|
91
103
|
font-size: small;
|
92
104
|
background-color: #fff;
|
data/views/index.erb
CHANGED
@@ -11,7 +11,14 @@
|
|
11
11
|
<form action="/validate" method="post">
|
12
12
|
<div class="entry">
|
13
13
|
<textarea name="code" id="code" cols="65" rows="25"></textarea>
|
14
|
-
<input type="submit" value="Validate">
|
14
|
+
<input type="submit" value="Validate" id="validate">
|
15
|
+
Puppet version
|
16
|
+
<select id="versions">
|
17
|
+
<% version = @versions.shift %><option value='/'><%= version %></option>
|
18
|
+
<% @versions.each do |version| %>
|
19
|
+
<option><%= version %></option>
|
20
|
+
<% end %>
|
21
|
+
</select>
|
15
22
|
<label><input type="checkbox" name="lint" id="lint" onchange="toggleChecks();">Include <code>puppet-lint</code> style checks.</label>
|
16
23
|
<a class="button" href="#" onclick="toggleMenu();">customize ▾</a>
|
17
24
|
<fieldset id="checks-menu" class="menu">
|
data/views/result.erb
CHANGED
@@ -8,7 +8,8 @@
|
|
8
8
|
</head>
|
9
9
|
<body>
|
10
10
|
<h1>Validation Results</h1>
|
11
|
-
<
|
11
|
+
<fieldset class="results <%= @status %>">
|
12
|
+
<legend>Puppet version <%= @version %></legend>
|
12
13
|
<p><%= @message %></p>
|
13
14
|
<% if @line %>
|
14
15
|
<div class="row">
|
@@ -24,7 +25,7 @@
|
|
24
25
|
<hr />
|
25
26
|
<p>See inline <code>puppet-lint</code> warnings.</p>
|
26
27
|
<% end %>
|
27
|
-
</
|
28
|
+
</fieldset>
|
28
29
|
<pre data-line='<%= @highlights %>' class="line-numbers language-puppet"><code class="line-numbers language-puppet"><%= @code %></code></pre>
|
29
30
|
<div class="links"><a href="javascript:history.back();">Try Again</a> • <a href="/">Validate More Code</a></div>
|
30
31
|
<p class="info">
|
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.5
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|