puppet-parse 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -3
- data/lib/puppet-parse/configuration.rb +170 -0
- data/lib/puppet-parse/parser.rb +1 -1
- data/lib/puppet-parse/puppet-parse.rb +5 -2
- data/lib/puppet-parse/runner.rb +1 -1
- data/lib/puppet-parse/version.rb +2 -2
- data/lib/puppet-parse.rb +16 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -10,24 +10,48 @@ Analyse puppet manifests and report what classes and defines are specified, and
|
|
10
10
|
|
11
11
|
## Requirements
|
12
12
|
|
13
|
-
rdoc
|
13
|
+
rdoc >=3.12, <4.0
|
14
14
|
facter
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
18
|
### By hand
|
19
19
|
|
20
|
-
You can
|
20
|
+
You can report on one or more manifests by running
|
21
21
|
|
22
22
|
puppet-parse <path(s) to file(s)>
|
23
23
|
|
24
|
-
### Rake
|
24
|
+
### Rake task
|
25
25
|
|
26
26
|
If you want to parse your entire modules directory, you can add
|
27
27
|
`require 'puppet-parse/puppet-parse' to your Rakefile and then run
|
28
28
|
|
29
29
|
rake parse
|
30
30
|
|
31
|
+
If you need to ignore certain paths from being parsed:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
PuppetParse.configuration.ignore_paths = ["vendor/**/*.pp"]
|
35
|
+
```
|
36
|
+
|
37
|
+
## Sample Output
|
38
|
+
|
39
|
+
---
|
40
|
+
ntp:
|
41
|
+
parameters:
|
42
|
+
enabled: true
|
43
|
+
present: true
|
44
|
+
enableboot: true
|
45
|
+
docs:
|
46
|
+
enabled:
|
47
|
+
- "Set to 'false' to stop service"
|
48
|
+
present:
|
49
|
+
- "Set to 'false' to remove package"
|
50
|
+
enableboot:
|
51
|
+
- "Set to 'false' to prevent service starting at boot"
|
52
|
+
|
53
|
+
|
54
|
+
|
31
55
|
## Contributing
|
32
56
|
|
33
57
|
You can do any of these:
|
@@ -0,0 +1,170 @@
|
|
1
|
+
class PuppetParse
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
# Code blatently stolen from https://github.com/rodjek/puppet-lint
|
5
|
+
|
6
|
+
# Internal: Add helper methods for a new check to the
|
7
|
+
# PuppetParse::Configuration object.
|
8
|
+
#
|
9
|
+
# check - The String name of the check.
|
10
|
+
#
|
11
|
+
# Returns nothing.
|
12
|
+
#
|
13
|
+
# Signature
|
14
|
+
#
|
15
|
+
# <check>_enabled?
|
16
|
+
# disable_<check>
|
17
|
+
# enable_<check>
|
18
|
+
def self.add_check(check)
|
19
|
+
# Public: Determine if the named check is enabled.
|
20
|
+
#
|
21
|
+
# Returns true if the check is enabled, otherwise return false.
|
22
|
+
define_method("#{check}_enabled?") do
|
23
|
+
settings["#{check}_disabled"] == true ? false : true
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Disable the named check.
|
27
|
+
#
|
28
|
+
# Returns nothing.
|
29
|
+
define_method("disable_#{check}") do
|
30
|
+
settings["#{check}_disabled"] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# Public: Enable the named check.
|
34
|
+
#
|
35
|
+
# Returns nothing.
|
36
|
+
define_method("enable_#{check}") do
|
37
|
+
settings["#{check}_disabled"] = false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Public: Catch situations where options are being set for the first time
|
42
|
+
# and create the necessary methods to get & set the option in the future.
|
43
|
+
#
|
44
|
+
# args[0] - The value to set the option to.
|
45
|
+
#
|
46
|
+
# Returns nothing.
|
47
|
+
#
|
48
|
+
# Signature
|
49
|
+
#
|
50
|
+
# <option>=(value)
|
51
|
+
def method_missing(method, *args, &block)
|
52
|
+
if method.to_s =~ /^(\w+)=$/
|
53
|
+
option = $1
|
54
|
+
add_option(option.to_s) if settings[option].nil?
|
55
|
+
settings[option] = args[0]
|
56
|
+
else
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Internal: Add options to the PuppetParse::Configuration object from inside
|
62
|
+
# the class.
|
63
|
+
#
|
64
|
+
# option - The String name of the option.
|
65
|
+
#
|
66
|
+
# Returns nothing.
|
67
|
+
#
|
68
|
+
# Signature
|
69
|
+
#
|
70
|
+
# <option>
|
71
|
+
# <option>=(value)
|
72
|
+
def add_option(option)
|
73
|
+
self.class.add_option(option)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Public: Add an option to the PuppetParse::Configuration object from
|
77
|
+
# outside the class.
|
78
|
+
#
|
79
|
+
# option - The String name of the option.
|
80
|
+
#
|
81
|
+
# Returns nothing.
|
82
|
+
#
|
83
|
+
# Signature
|
84
|
+
#
|
85
|
+
# <option>
|
86
|
+
# <option>=(value)
|
87
|
+
def self.add_option(option)
|
88
|
+
# Public: Set the value of the named option.
|
89
|
+
#
|
90
|
+
# value - The value to set the option to.
|
91
|
+
#
|
92
|
+
# Returns nothing.
|
93
|
+
define_method("#{option}=") do |value|
|
94
|
+
settings[option] = value
|
95
|
+
end
|
96
|
+
|
97
|
+
# Public: Get the value of the named option.
|
98
|
+
#
|
99
|
+
# Returns the value of the option.
|
100
|
+
define_method(option) do
|
101
|
+
settings[option]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Internal: Register a new check.
|
106
|
+
#
|
107
|
+
# check - The String name of the check
|
108
|
+
# b - The Block containing the logic of the check
|
109
|
+
#
|
110
|
+
# Returns nothing.
|
111
|
+
def add_check(check, &b)
|
112
|
+
self.class.add_check(check)
|
113
|
+
check_method[check] = b
|
114
|
+
end
|
115
|
+
|
116
|
+
# Internal: Register a new check helper method.
|
117
|
+
#
|
118
|
+
# name - The String name of the method.
|
119
|
+
# b - The Block containing the logic of the helper.
|
120
|
+
#
|
121
|
+
# Returns nothing.
|
122
|
+
def add_helper(name, &b)
|
123
|
+
helper_method[name] = b
|
124
|
+
end
|
125
|
+
|
126
|
+
# Internal: Access the internal storage for settings.
|
127
|
+
#
|
128
|
+
# Returns a Hash containing all the settings.
|
129
|
+
def settings
|
130
|
+
@settings ||= {}
|
131
|
+
end
|
132
|
+
|
133
|
+
# Internal: Access the internal storage for check method blocks.
|
134
|
+
#
|
135
|
+
# Returns a Hash containing all the check blocks.
|
136
|
+
def check_method
|
137
|
+
@check_method ||= {}
|
138
|
+
end
|
139
|
+
|
140
|
+
# Public: Get a list of all the defined checks.
|
141
|
+
#
|
142
|
+
# Returns an Array of String check names.
|
143
|
+
def checks
|
144
|
+
check_method.keys
|
145
|
+
end
|
146
|
+
|
147
|
+
# Internal: Access the internal storage for helper method blocks.
|
148
|
+
#
|
149
|
+
# Returns a Hash containing all the helper blocks.
|
150
|
+
def helper_method
|
151
|
+
@helper_method ||= {}
|
152
|
+
end
|
153
|
+
|
154
|
+
# Public: Get a list of all the helper methods.
|
155
|
+
#
|
156
|
+
# Returns an Array of String method names.
|
157
|
+
def helpers
|
158
|
+
helper_method.keys
|
159
|
+
end
|
160
|
+
|
161
|
+
# Public: Clear the PuppetParse::Configuration storage and set some sane
|
162
|
+
# default values.
|
163
|
+
#
|
164
|
+
# Returns nothing.
|
165
|
+
def defaults
|
166
|
+
settings.clear
|
167
|
+
end
|
168
|
+
|
169
|
+
end # class Configuration
|
170
|
+
end # module PuppetParse
|
data/lib/puppet-parse/parser.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
|
2
|
-
$LOAD_PATH.unshift File.expand_path('/vagrant/puppet-parser/lib')
|
3
|
-
|
4
2
|
require 'puppet-parse'
|
5
3
|
require 'rake'
|
6
4
|
require 'rake/tasklib'
|
@@ -8,6 +6,11 @@ require 'rake/tasklib'
|
|
8
6
|
desc 'Run puppet-parse'
|
9
7
|
task :parse do
|
10
8
|
matched_files = FileList['**/*.pp']
|
9
|
+
|
10
|
+
if ignore_paths = PuppetParse.configuration.ignore_paths
|
11
|
+
matched_files = matched_files.exclude(*ignore_paths)
|
12
|
+
end
|
13
|
+
|
11
14
|
run = PuppetParse::Runner.new
|
12
15
|
puts run.run(matched_files.to_a).to_yaml
|
13
16
|
end
|
data/lib/puppet-parse/runner.rb
CHANGED
data/lib/puppet-parse/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class PuppetParse
|
2
|
+
VERSION = "0.0.6"
|
3
3
|
end
|
data/lib/puppet-parse.rb
CHANGED
@@ -4,5 +4,21 @@ require 'puppet-parse/version'
|
|
4
4
|
require 'puppet-parse/parser'
|
5
5
|
require 'puppet-parse/runner'
|
6
6
|
require 'puppet-parse/hash'
|
7
|
+
require 'puppet-parse/configuration'
|
7
8
|
require 'rdoc'
|
8
9
|
|
10
|
+
class PuppetParse
|
11
|
+
# Public: Access PuppetParse's configuration from outside the class.
|
12
|
+
#
|
13
|
+
# Returns a PuppetParse::Configuration object.
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= PuppetParse::Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Access PuppetParse's configuration from inside the class.
|
19
|
+
#
|
20
|
+
# Returns a PuppetParse::Configuration object.
|
21
|
+
def configuration
|
22
|
+
self.class.configuration
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-parse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- bin/puppet-parse
|
99
99
|
- lib/puppet-parse.rb
|
100
|
+
- lib/puppet-parse/configuration.rb
|
100
101
|
- lib/puppet-parse/hash.rb
|
101
102
|
- lib/puppet-parse/parser.rb
|
102
103
|
- lib/puppet-parse/puppet-parse.rb
|