puppet-validator 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ (function ( $ ) {
2
+ $.fn.RspecValidator = function(options) {
3
+ var settings = $.extend({
4
+ label: "Validate",
5
+ spec: null,
6
+ cols: 65,
7
+ rows: 25,
8
+ server: "",
9
+ }, options );
10
+
11
+ return this.each(function() {
12
+ var element = $(this);
13
+ var server = settings.server + "/api/v0/validate/rspec"
14
+ if(element.attr('data-spec')) {
15
+ settings.spec = element.attr('data-spec')
16
+
17
+ }
18
+
19
+ if (settings.spec == null) {
20
+ console.log("[FATAL] RspecValidator: spec is a required parameter.")
21
+ return;
22
+ }
23
+
24
+ var form = $("<form>", {
25
+ "action": server,
26
+ "method": "post",
27
+ "class": "validator",
28
+ });
29
+ var editor = $("<textarea>", {
30
+ "name": "code",
31
+ "cols": settings.cols,
32
+ "rows": settings.rows,
33
+ "class": "validator editor",
34
+ });
35
+ var spec = $("<input>", {
36
+ "name": "spec",
37
+ "type": "hidden",
38
+ "value": settings.spec,
39
+ });
40
+ var submit = $("<input>", {
41
+ "name": "submit",
42
+ "type": "submit",
43
+ "value": settings.label,
44
+ });
45
+
46
+ form.append(editor);
47
+ form.append(spec);
48
+ form.append(submit);
49
+ element.replaceWith(form);
50
+
51
+ // if we've got CodeMirror loaded, then make a pretty editor
52
+ if(typeof CodeMirror != 'undefined') {
53
+ var cmEditor = CodeMirror.fromTextArea(editor[0], {
54
+ lineNumbers: true,
55
+ smartIndent: true,
56
+ indentWithTabs: true,
57
+ mode: 'puppet',
58
+ });
59
+ }
60
+
61
+ submit.on('click', function(event){
62
+ event.preventDefault();
63
+
64
+ // propogates text to the textarea
65
+ if(typeof cmEditor != 'undefined') {
66
+ cmEditor.save();
67
+ }
68
+
69
+ var wrapper = $(this).parent('form');
70
+ var editor = $(this).siblings('textarea')
71
+ var code = editor.val();
72
+
73
+ $.post(server, {code: code, spec: settings.spec}, function(data) {
74
+ console.log(data);
75
+ var results = jQuery.parseJSON(data);
76
+ if(results.success) {
77
+ wrapper.addClass('validated');
78
+ wrapper.removeClass('failed');
79
+ alert('yay!');
80
+ }
81
+ else {
82
+ wrapper.addClass('failed');
83
+ wrapper.removeClass('validated');
84
+ alert("Failures:\n" + results.errors.join("\n"));
85
+ }
86
+ }).fail(function(jqXHR) {
87
+ alert("Unknown API error:\n" + jqXHR.responseText);
88
+ });
89
+ });
90
+
91
+ return this;
92
+ });
93
+ };
94
+
95
+ }(jQuery));
@@ -1,32 +1,52 @@
1
1
  <html>
2
2
  <head>
3
3
  <title>Puppet Validator</title>
4
- <link rel="stylesheet" href="styles.css">
4
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/codemirror.css">
5
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/addon/lint/lint.css">
6
+ <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
7
+ <link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.min.css">
8
+ <link rel="stylesheet" href="/styles.css">
9
+
5
10
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
6
- <script src="scripts.js"></script>
11
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/codemirror.js"></script>
13
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/mode/puppet/puppet.js"></script>
14
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/addon/lint/lint.js"></script>
15
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.31.0/addon/selection/active-line.js"></script>
16
+ <script src="/scripts.js"></script>
7
17
  </head>
8
18
  <body>
9
19
  <a href="https://github.com/puppetlabs/puppet-validator"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
10
20
  <h1>Puppet Code Validator</h1>
11
21
  <p>Paste Puppet code into the following textbox and check it for validity.</p>
22
+
23
+ <fieldset id="results" class="results hidden">
24
+ <legend>Validated for Puppet version <span id="version"></span></legend>
25
+ <img id="share" class="share_icon" title="Gist this validated code..." src="/gist.png" onclick="gist();" />
26
+ <i class="fa fa-spinner fa-pulse fa-2x" aria-hidden="true" id="spinner"></i>
27
+ <p id="message"></p>
28
+ </fieldset>
29
+
12
30
  <form action="/validate" method="post">
13
31
  <% if settings.csrf %><input name="_csrf", type="hidden" value="<%= session[:csrf] %>" /><% end %>
32
+ <div class="row">
33
+ <label>Validate a URL:</label><input type="text" name="location" id="location" value="<%= @location %>"><input type="submit" value="Load" id="load" name="load" />
34
+ </div>
14
35
  <div class="entry">
15
- <textarea name="code" id="code" cols="65" rows="25"></textarea>
36
+ <textarea name="code" id="code" cols="65" rows="25"><%= @code %></textarea>
16
37
  <div class="row">
17
38
  <input type="submit" value="Validate" id="validate">
18
39
  </div>
19
40
  <div class="row">
20
41
  Puppet version
21
- <select id="versions">
22
- <% version = @versions.shift %><option value='/'><%= version %></option>
42
+ <select id="versions" name="version">
23
43
  <% @versions.each do |version| %>
24
44
  <option><%= version %></option>
25
45
  <% end %>
26
46
  </select>
27
- <label><input type="checkbox" name="lint" id="lint" onchange="toggleChecks();">Include <code>puppet-lint</code> style checks.</label>
47
+ <label><input type="checkbox" name="lint" id="lint" checked="checked" onchange="toggleChecks();">Include <code>puppet-lint</code> style checks.</label>
28
48
  <a id="customize" class="button" href="javascript:toggleMenu();">customize &#9662;</a>
29
- <% if settings.graph %><label><input type="checkbox" name="relationships" id="relationships">Show relationships.</label><% end %>
49
+ <% if settings.graph %><input type="submit" name="relationships" id="relationships" value="Show relationships" /><% end %>
30
50
  </div>
31
51
  <fieldset id="checks-menu" class="menu">
32
52
  <legend>Enabled Lint Checks</legend>
@@ -40,7 +60,9 @@
40
60
  </fieldset>
41
61
  </div>
42
62
  </form>
63
+
43
64
  <div class="info">
65
+ <i class="fa fa-info-circle fa-3x" aria-hidden="true"></i>
44
66
  <p><strong>Be aware that valid syntax does not mean you have valid code.</strong></p>
45
67
  <p>
46
68
  The validator <em>only validates syntax</em> and doesn't actually compile or enforce
@@ -1,50 +1,46 @@
1
1
  <html>
2
2
  <head>
3
3
  <title>Puppet Validator</title>
4
- <link rel="stylesheet" href="prism-default.css">
5
- <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
4
+ <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
6
5
  <link rel="stylesheet" href="styles.css">
7
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
8
- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
9
- <script src="prism.js"></script>
10
- <script src="scripts.js"></script>
11
6
  </head>
12
7
  <body>
13
8
  <a href="https://github.com/puppetlabs/puppet-validator"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
14
9
  <h1>Validation Results</h1>
15
- <fieldset class="results <%= @status %>">
16
- <legend>Puppet version <%= @version %></legend>
17
- <p>
18
- <%= @message %>
19
- <% if @status == :success %>
20
- <img class="share_icon" title="Gist this validated code..." src="gist.png" onclick="gist();" />
21
- <% end %>
22
- </p>
23
- <% if @line %>
10
+ <fieldset class="results <%= @result[:status] %>">
11
+ <legend>Validated for Puppet version <%= @result[:version] %></legend>
12
+ <p><%= @result[:message] %></p>
13
+ <% if @result[:line] %>
24
14
  <div class="row">
25
- <span class="label">Line Number:</span><span class="message"><%= @line %></span>
15
+ <span class="label">Line Number:</span><span class="message"><%= @result[:line] %></span>
26
16
  </div>
27
17
  <% end %>
28
- <% if @column %>
18
+ <% if @result[:column] %>
29
19
  <div class="row">
30
- <span class="label">Column:</span><span class="message"><%= @column %></span>
20
+ <span class="label">Column:</span><span class="message"><%= @result[:column] %></span>
31
21
  </div>
32
22
  <% end %>
33
- <% if @lint_warnings %>
23
+ <% if @result[:messages] %>
34
24
  <hr />
35
- <p>See inline <code>puppet-lint</code> warnings.</p>
25
+ <ul>
26
+ <% @result[:messages].each do |message| %>
27
+ <% next if message[:severity] == 'error' %>
28
+ <li>Line <%= message[:from].first + 1 %>: <%= message[:message] %></li>
29
+ <% end %>
30
+ </ul>
36
31
  <% end %>
37
32
  </fieldset>
38
- <pre data-line='<%= @highlights %>' class="line-numbers language-puppet"><code id="code" class="line-numbers language-puppet"><%= @code %></code></pre>
39
- <% if @relationships %>
40
- <% if @relationships[:status] %>
41
- <div class="relationships"><%= @relationships[:data] %></div>
42
- <% else %>
43
- <div class="warning"><%= @relationships[:message] %></div>
33
+ <pre id="highlighted">
34
+ <% @result[:code].each_line do |line| %>
35
+ <code><%= line %></code>
44
36
  <% end %>
37
+ </pre>
38
+ <% if @result[:relationships] %>
39
+ <div class="relationships"><%= @result[:relationships] %></div>
45
40
  <% end %>
46
- <div class="links"><a href="javascript:history.back();">Try Again</a> &bull; <a href="/">Validate More Code</a></div>
41
+ <div class="links"><a href="/">Validate More Code</a></div>
47
42
  <div class="info">
43
+ <i class="fa fa-info-circle fa-3x" aria-hidden="true"></i>
48
44
  <p><strong>Be aware that valid syntax does not mean you have valid code.</strong></p>
49
45
  <p>
50
46
  The validator <em>only validates syntax</em> and doesn't actually compile or enforce
metadata CHANGED
@@ -1,101 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Ford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: puppet
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '2.7'
34
- - - <
35
- - !ruby/object:Gem::Version
36
- version: '5.0'
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '2.7'
44
- - - <
45
- - !ruby/object:Gem::Version
46
- version: '5.0'
47
27
  - !ruby/object:Gem::Dependency
48
28
  name: puppet-lint
49
29
  requirement: !ruby/object:Gem::Requirement
50
30
  requirements:
51
- - - ~>
31
+ - - "~>"
52
32
  - !ruby/object:Gem::Version
53
33
  version: '1.1'
54
34
  type: :runtime
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
37
  requirements:
58
- - - ~>
38
+ - - "~>"
59
39
  - !ruby/object:Gem::Version
60
40
  version: '1.1'
61
41
  - !ruby/object:Gem::Dependency
62
42
  name: nokogiri
63
43
  requirement: !ruby/object:Gem::Requirement
64
44
  requirements:
65
- - - ~>
45
+ - - "~>"
66
46
  - !ruby/object:Gem::Version
67
47
  version: '1.6'
68
- - - ! '>='
48
+ - - ">="
69
49
  - !ruby/object:Gem::Version
70
50
  version: 1.6.5
71
51
  type: :runtime
72
52
  prerelease: false
73
53
  version_requirements: !ruby/object:Gem::Requirement
74
54
  requirements:
75
- - - ~>
55
+ - - "~>"
76
56
  - !ruby/object:Gem::Version
77
57
  version: '1.6'
78
- - - ! '>='
58
+ - - ">="
79
59
  - !ruby/object:Gem::Version
80
60
  version: 1.6.5
81
61
  - !ruby/object:Gem::Dependency
82
62
  name: ruby-graphviz
83
63
  requirement: !ruby/object:Gem::Requirement
84
64
  requirements:
85
- - - ~>
65
+ - - "~>"
86
66
  - !ruby/object:Gem::Version
87
67
  version: '1.2'
88
68
  type: :runtime
89
69
  prerelease: false
90
70
  version_requirements: !ruby/object:Gem::Requirement
91
71
  requirements:
92
- - - ~>
72
+ - - "~>"
93
73
  - !ruby/object:Gem::Version
94
74
  version: '1.2'
95
- description: ! " Puppet Validator is a simple web service that accepts arbitrary
96
- code submissions and\n validates it the way `puppet parser validate` would. It
97
- can optionally also\n run `puppet-lint` checks on the code and display both results
98
- together.\n"
75
+ description: |2
76
+ Puppet Validator is a simple web service that accepts arbitrary code submissions and
77
+ validates it the way `puppet parser validate` would. It can optionally also
78
+ run `puppet-lint` checks on the code and display both results together.
99
79
  email: binford2k@gmail.com
100
80
  executables:
101
81
  - puppet-validator
@@ -104,18 +84,28 @@ extra_rdoc_files: []
104
84
  files:
105
85
  - LICENSE
106
86
  - README.md
107
- - bin/grapher
108
87
  - bin/puppet-validator
109
88
  - config.ru
110
89
  - lib/puppet-validator.rb
90
+ - lib/puppet-validator/helpers.rb
91
+ - lib/puppet-validator/validators.rb
92
+ - lib/puppet-validator/validators/lint.rb
93
+ - lib/puppet-validator/validators/rspec.rb
94
+ - lib/puppet-validator/validators/syntax.rb
95
+ - public/font-awesome-4.7.0/css/font-awesome.css
96
+ - public/font-awesome-4.7.0/css/font-awesome.min.css
97
+ - public/font-awesome-4.7.0/fonts/FontAwesome.otf
98
+ - public/font-awesome-4.7.0/fonts/fontawesome-webfont.eot
99
+ - public/font-awesome-4.7.0/fonts/fontawesome-webfont.svg
100
+ - public/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf
101
+ - public/font-awesome-4.7.0/fonts/fontawesome-webfont.woff
102
+ - public/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2
111
103
  - public/gist.png
112
- - public/info.png
113
- - public/prism-default.css
114
- - public/prism.js
115
104
  - public/relationships.html
116
105
  - public/scripts.js
117
106
  - public/styles.css
118
107
  - public/testing.html
108
+ - public/validation.js
119
109
  - views/index.erb
120
110
  - views/result.erb
121
111
  homepage: https://github.com/puppetlabs/puppet-validator/
@@ -128,17 +118,17 @@ require_paths:
128
118
  - lib
129
119
  required_ruby_version: !ruby/object:Gem::Requirement
130
120
  requirements:
131
- - - ! '>='
121
+ - - ">="
132
122
  - !ruby/object:Gem::Version
133
123
  version: '0'
134
124
  required_rubygems_version: !ruby/object:Gem::Requirement
135
125
  requirements:
136
- - - ! '>='
126
+ - - ">="
137
127
  - !ruby/object:Gem::Version
138
128
  version: '0'
139
129
  requirements: []
140
130
  rubyforge_project:
141
- rubygems_version: 2.6.11
131
+ rubygems_version: 2.6.10
142
132
  signing_key:
143
133
  specification_version: 4
144
134
  summary: Puppet code validator as a service
@@ -1,44 +0,0 @@
1
- #! /usr/bin/env ruby
2
- require 'puppet'
3
- require 'graphviz'
4
-
5
- Puppet.initialize_settings
6
-
7
- Puppet[:code] = <<-EOF
8
-
9
- notify { 'hello there':
10
- require => File['/tmp/foo'],
11
- }
12
- file { '/tmp/foo':
13
- ensure => file,
14
- }
15
- notify { 'goodbye':
16
- require => File['/tmp/nope'],
17
- }
18
-
19
- file{'/tmp/nope':}
20
-
21
- poodles{'oogles': }
22
-
23
- define poodles {}
24
- EOF
25
-
26
-
27
- node = Puppet::Node.indirection.find(Puppet[:node_name_value])
28
- catalog = Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node).to_ral
29
-
30
- #catalog.vertices.each { |v| catalog.remove_vertex! v if v.is_a? Puppet::Type::Stage }
31
- #catalog.vertices.each { |v| catalog.remove_vertex! v if v.is_a? Puppet::Type::Component }
32
-
33
- graph = catalog.relationship_graph.to_dot
34
-
35
- GraphViz.parse_string(graph) do |graph|
36
- graph[:label] = 'Resource Relationships'
37
-
38
- w = graph.get_node('Whit[Admissible_class[Main]]')
39
- w[:label] = 'Start'
40
-
41
- w = graph.get_node('Whit[Completed_class[Main]]')
42
- w[:label] = 'Finish'
43
-
44
- end.output(:svg => "sample.svg")