knife-syntax-check 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +51 -0
- data/knife-syntax-check.gemspec +21 -0
- data/lib/chef/knife/syntax-check.rb +107 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd958ad4bc92747d2898c277d05f993f0567e2a2
|
4
|
+
data.tar.gz: 99f7083bdd67246c0c47e6e946c701f80dae7d9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8dec8d8f4962ef0c244f80fbcfbc2455e9954965f4dce7ccb62a1d56871773ccc18fbc9fd6b4276e0b1ff44ccab26a585a191a0c4e47479b51a3aab98614a603
|
7
|
+
data.tar.gz: a9e45c9a83e45bbf0f725b3ba2ad80b5ca641a9c5bee8fafdf17fd30b66fb5dd4084801c54d8cf53b2bc3f2c4e91dc6a27e9d55cdfc44d8e14dab100088b361f
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
knife-syntax-check
|
2
|
+
==============
|
3
|
+
|
4
|
+
A small knife plugin to allow you to easily syntax check your ruby and/or json code for your cookbooks, roles, environments, databags, and nodes.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
=====
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
$ knife syntax-check --help
|
11
|
+
knife syntax-check
|
12
|
+
-a, --all Test syntax of all roles, environments, nodes, databags and cookbooks
|
13
|
+
-c, --cookbooks Test only cookbook syntax
|
14
|
+
-D, --databags Test only databag syntax
|
15
|
+
-e, --environments Test only environment syntax
|
16
|
+
-n, --nodes Test only node syntax
|
17
|
+
-r, --roles Test only role syntax
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
Installation
|
21
|
+
============
|
22
|
+
|
23
|
+
Simply copy the syntax-check.rb [script to your .chef/plugins/knife/ folder](http://wiki.opscode.com/display/chef/Knife+Plugins).
|
24
|
+
Depends on the ['yajl-ruby' gem](https://github.com/brianmario/yajl-ruby) for json syntax checking.
|
25
|
+
|
26
|
+
How it works
|
27
|
+
============
|
28
|
+
|
29
|
+
Basically this plugin just piggy backs on existing knife commands when checking cookbooks.
|
30
|
+
|
31
|
+
However for nodes, environments, roles, and databags, syntax is checked as follows:
|
32
|
+
* JSON - checked using the yajl-ruby gem
|
33
|
+
* Ruby - checked using the 'ruby -c' command
|
34
|
+
|
35
|
+
Disclaimer
|
36
|
+
==========
|
37
|
+
|
38
|
+
This has ONLY been tested against hosted chef. Bugs may and probably do exist. If you find a bug or want a feature, please feel free to contact me or fork the repo, fix it yourself and issue a pull request.
|
39
|
+
|
40
|
+
License
|
41
|
+
=======
|
42
|
+
|
43
|
+
MIT
|
44
|
+
|
45
|
+
Copyright (C) 2013 Chris Doughty cdoughty77@gmail.com
|
46
|
+
|
47
|
+
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:
|
48
|
+
|
49
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
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.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'knife-syntax-check'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.authors = ['Chris Doughty']
|
8
|
+
s.email = ['cdoughty77@gmail.com']
|
9
|
+
s.homepage = 'https://github.com/cdoughty77/knife-syntax-check'
|
10
|
+
s.summary = %q{Chef Knife plugin to check Ruby file syntax}
|
11
|
+
s.description = s.summary
|
12
|
+
s.license = 'MIT/BSD'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
|
16
|
+
s.add_dependency 'yajl-ruby', '~> 1.2.0'
|
17
|
+
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifePlugin
|
4
|
+
class SyntaxCheck < Chef::Knife
|
5
|
+
|
6
|
+
banner "knife syntax-check"
|
7
|
+
|
8
|
+
option :environments,
|
9
|
+
:short => '-e',
|
10
|
+
:long => '--environments',
|
11
|
+
:boolean => true,
|
12
|
+
:description => "Test only environment syntax"
|
13
|
+
option :roles,
|
14
|
+
:short => '-r',
|
15
|
+
:long => '--roles',
|
16
|
+
:boolean => true,
|
17
|
+
:description => "Test only role syntax"
|
18
|
+
option :nodes,
|
19
|
+
:short => '-n',
|
20
|
+
:long => '--nodes',
|
21
|
+
:boolean => true,
|
22
|
+
:description => "Test only node syntax"
|
23
|
+
option :databags,
|
24
|
+
:short => '-D',
|
25
|
+
:long => '--databags',
|
26
|
+
:boolean => true,
|
27
|
+
:description => "Test only databag syntax"
|
28
|
+
option :cookbooks,
|
29
|
+
:short => '-c',
|
30
|
+
:long => '--cookbooks',
|
31
|
+
:boolean => true,
|
32
|
+
:description => "Test only cookbook syntax"
|
33
|
+
option :all,
|
34
|
+
:short => '-a',
|
35
|
+
:long => '--all',
|
36
|
+
:boolean => true,
|
37
|
+
:description => "Test syntax of all roles, environments, nodes, databags and cookbooks"
|
38
|
+
|
39
|
+
deps do
|
40
|
+
require 'yajl'
|
41
|
+
require 'pathname'
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
if config[:roles]
|
46
|
+
test_object("roles/*", "role")
|
47
|
+
elsif config[:environments]
|
48
|
+
test_object("environments/*", "environment")
|
49
|
+
elsif config[:nodes]
|
50
|
+
test_object("nodes/*", "node")
|
51
|
+
elsif config[:databags]
|
52
|
+
test_databag("data_bags/*", "data bag")
|
53
|
+
elsif config[:cookbooks]
|
54
|
+
test_cookbooks()
|
55
|
+
elsif config[:all]
|
56
|
+
test_object("roles/*", "role")
|
57
|
+
test_object("environments/*", "environment")
|
58
|
+
test_object("nodes/*", "node")
|
59
|
+
test_databag("data_bags/*", "data bag")
|
60
|
+
test_cookbooks()
|
61
|
+
else
|
62
|
+
ui.msg("Usage: knife syntax-check --help")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Test all cookbooks
|
67
|
+
def test_cookbooks()
|
68
|
+
ui.msg("Testing all cookbooks...")
|
69
|
+
result = `knife cookbook test --all`
|
70
|
+
ui.msg(result)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Test object syntax
|
74
|
+
def test_object(dirname,type)
|
75
|
+
ui.msg("Finding type #{type} to test from #{dirname}")
|
76
|
+
check_syntax(dirname,nil,type)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Test databag syntax
|
80
|
+
def test_databag(dirname, type)
|
81
|
+
ui.msg("Finding type #{type} to test from #{dirname}")
|
82
|
+
dirs = Dir.glob(dirname).select { |d| File.directory?(d) }
|
83
|
+
dirs.each do |directory|
|
84
|
+
dir = Pathname.new(directory).basename
|
85
|
+
check_syntax("#{directory}/*", dir, type)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Common method to test file syntax
|
90
|
+
def check_syntax(dirpath, dir = nil, type)
|
91
|
+
files = Dir.glob("#{dirpath}").select { |f| File.file?(f) }
|
92
|
+
files.each do |file|
|
93
|
+
fname = Pathname.new(file).basename
|
94
|
+
if ("#{fname}".end_with?('.json'))
|
95
|
+
ui.msg("Testing file #{file}")
|
96
|
+
json = File.new(file, 'r')
|
97
|
+
parser = Yajl::Parser.new
|
98
|
+
hash = parser.parse(json)
|
99
|
+
elsif("#{fname}".end_with?('.rb'))
|
100
|
+
ui.msg("Testing file #{file}")
|
101
|
+
result = `ruby -c #{file}`
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-syntax-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Doughty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yajl-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
description: Chef Knife plugin to check Ruby file syntax
|
28
|
+
email:
|
29
|
+
- cdoughty77@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- knife-syntax-check.gemspec
|
36
|
+
- lib/chef/knife/syntax-check.rb
|
37
|
+
homepage: https://github.com/cdoughty77/knife-syntax-check
|
38
|
+
licenses:
|
39
|
+
- MIT/BSD
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.2.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Chef Knife plugin to check Ruby file syntax
|
61
|
+
test_files: []
|