puppet-itemize 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +10 -0
- data/README.md +37 -1
- data/bin/puppet-itemize +8 -0
- data/lib/puppet/face/parser/itemize.rb +4 -0
- data/lib/puppet_x/binford2k/itemize/parser.rb +0 -1
- data/lib/puppet_x/binford2k/itemize/runner.rb +37 -3
- data/lib/puppet_x/binford2k/itemize/version.rb +1 -1
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1625c1cacf7bc9c0373f02357fdef0d912ed642896c30c0fd372a38f84116924
|
4
|
+
data.tar.gz: 7dc10c68119882e62bb4587361a4d1f6b71ee2b94bd36a03af43c4f821863eee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c18bb2c71c6ba444d2f11177c273a3ea7b7872ac1999c91d6d044ed90b9a80eb9fb3032ffbbeb6a3f6241bfbe496065f321af1292dee8c03eac8e2c353b642e5
|
7
|
+
data.tar.gz: ad95bc731049ae6d803e4961ab2cd1979e06c9adfb71e2d4a76c81c8ae8e0aa309205a99e6daa14c723bad30cfea83319eb7f811244f4d6299d0730adda7667b
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ $ gem install puppet-itemize
|
|
18
18
|
Or as a Puppet module:
|
19
19
|
|
20
20
|
```
|
21
|
-
$ puppet module install binford2k/
|
21
|
+
$ puppet module install binford2k/itemize
|
22
22
|
```
|
23
23
|
|
24
24
|
## Usage
|
@@ -54,6 +54,34 @@ $ puppet parser itemize manifests/init.pp
|
|
54
54
|
$ puppet parser itemize manifests/init.pp manifests/example/path.pp
|
55
55
|
```
|
56
56
|
|
57
|
+
### Module dependency validation
|
58
|
+
|
59
|
+
If the tool can identify that you're running this on manifests within a Puppet
|
60
|
+
module, then it will validate the dependencies listed in the `metadata.json`.
|
61
|
+
By default, it will print out warnings for resources or classes that come from
|
62
|
+
modules that aren't declared as dependencies. Facts and Puppet 3.x style functions
|
63
|
+
aren't namespaced in the same way, so they cannot be identified, but Puppet 4.x
|
64
|
+
namespaced functions will trigger the same validation.
|
65
|
+
|
66
|
+
You can also use the `--external` argument. This will filter the output to only
|
67
|
+
show elements which are either global or from other modules. This can be used to
|
68
|
+
help identify how dependencies are being used.
|
69
|
+
|
70
|
+
|
71
|
+
### Programatic use
|
72
|
+
|
73
|
+
You can choose to render the output in either JSON or YAML for consumption by
|
74
|
+
other tools or testing pipelines by simply passing the `--render-as` argument:
|
75
|
+
|
76
|
+
```
|
77
|
+
$ puppet parser itemize ~/Projects/puppetlabs-apache/manifests/ --render-as json
|
78
|
+
$ puppet parser itemize ~/Projects/puppetlabs-apache/manifests/ --render-as yaml
|
79
|
+
```
|
80
|
+
|
81
|
+
It's also reasonably easy to invoke this as a library from Ruby tools. See the
|
82
|
+
`bin/puppet-itemize` script for an example.
|
83
|
+
|
84
|
+
|
57
85
|
### Example output:
|
58
86
|
|
59
87
|
Because this is static analysis prior to compilation, no variables can be
|
@@ -63,6 +91,12 @@ below in the class list as `apache::mod::<??>`.
|
|
63
91
|
|
64
92
|
```
|
65
93
|
$ puppet parser itemize ~/Projects/puppetlabs-apache/manifests/
|
94
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
95
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
96
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
97
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
98
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
99
|
+
Warning: Undeclared module dependancy: portage::makeconf
|
66
100
|
Warning: create_resources detected. Please update to use iteration instead.
|
67
101
|
Resource usage analysis:
|
68
102
|
=======================================
|
@@ -176,6 +210,7 @@ Resource usage analysis:
|
|
176
210
|
create_resources | 1
|
177
211
|
```
|
178
212
|
|
213
|
+
|
179
214
|
## Limitations
|
180
215
|
|
181
216
|
This is super early in development and has not yet been battle tested.
|
@@ -185,6 +220,7 @@ This is super early in development and has not yet been battle tested.
|
|
185
220
|
|
186
221
|
I take no liability for the use of this tool.
|
187
222
|
|
223
|
+
|
188
224
|
Contact
|
189
225
|
-------
|
190
226
|
|
data/bin/puppet-itemize
CHANGED
@@ -17,6 +17,10 @@ directories containing manifests. If omitted, it will default to inspecting all
|
|
17
17
|
manifests in the manifests directory, so you can just run this in the root of a
|
18
18
|
Puppet module and it will do the right thing.
|
19
19
|
|
20
|
+
If this is run from the root of a Puppet module or the `manifests` directory of
|
21
|
+
a Puppet module, and the `--external` argument is passed, then it will only
|
22
|
+
output elements that come from other modules (or are global).
|
23
|
+
|
20
24
|
"
|
21
25
|
|
22
26
|
opts.on('-r', '--render-as FORMAT', 'Render the output as human, json, or yaml') do |val|
|
@@ -33,6 +37,10 @@ Puppet module and it will do the right thing.
|
|
33
37
|
options[:debug] = true
|
34
38
|
end
|
35
39
|
|
40
|
+
opts.on('-x', '--external', 'Show external elements only') do
|
41
|
+
options[:debug] = true
|
42
|
+
end
|
43
|
+
|
36
44
|
opts.on('--shell', 'Open a pry shell for debugging (must have Pry installed)') do
|
37
45
|
options[:shell] = true
|
38
46
|
end
|
@@ -14,6 +14,10 @@ manifests in the manifests directory, so you can just run this in the root of a
|
|
14
14
|
Puppet module and it will do the right thing.
|
15
15
|
EOT
|
16
16
|
|
17
|
+
option('--external') do
|
18
|
+
summary 'Show external elements only.'
|
19
|
+
end
|
20
|
+
|
17
21
|
option('--shell') do
|
18
22
|
summary 'Start a debugging shell (requires Pry).'
|
19
23
|
end
|
@@ -1,9 +1,37 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
require 'puppet/util/logging'
|
3
|
+
require 'json'
|
4
|
+
|
1
5
|
class Puppet_X::Binford2k::Itemize::Runner
|
2
6
|
attr_reader :results
|
3
7
|
def initialize(options = {})
|
4
|
-
|
5
|
-
|
6
|
-
@
|
8
|
+
Puppet::Util::Log.newdestination(:console)
|
9
|
+
|
10
|
+
@paths = expand(Array(options[:manifests]))
|
11
|
+
@options = options
|
12
|
+
@results = {}
|
13
|
+
|
14
|
+
if options[:manifests].size == 1
|
15
|
+
root = options[:manifests].first
|
16
|
+
path = [File.expand_path("#{root}/metadata.json"),
|
17
|
+
File.expand_path("#{root}/../metadata.json")].select { |p| File.exist? p }.first
|
18
|
+
|
19
|
+
if path
|
20
|
+
@metadata = JSON.parse(File.read(File.expand_path("#{path}/../metadata.json")))
|
21
|
+
author = @metadata['author']
|
22
|
+
@namespace = @metadata['name'].sub(/^#{author}-/, '')
|
23
|
+
|
24
|
+
# we can only use the module name part of this, not the user namespace
|
25
|
+
@dependencies = @metadata['dependencies'].map do |dep|
|
26
|
+
dep['name'].split(/[-\/]/).last
|
27
|
+
end
|
28
|
+
# inject a few mocked dependencies that we can assume will always exist
|
29
|
+
@dependencies << @namespace
|
30
|
+
@dependencies << 'puppet_enterprise'
|
31
|
+
else
|
32
|
+
# what error to display here?
|
33
|
+
end
|
34
|
+
end
|
7
35
|
end
|
8
36
|
|
9
37
|
def expand(paths)
|
@@ -27,6 +55,12 @@ class Puppet_X::Binford2k::Itemize::Runner
|
|
27
55
|
@results[kind] ||= {}
|
28
56
|
|
29
57
|
counts.each do |name, count|
|
58
|
+
segments = name.split('::')
|
59
|
+
if @dependencies and segments.size > 1
|
60
|
+
Puppet.warning "Undeclared module dependancy: #{name}" unless @dependencies.include? segments.first
|
61
|
+
end
|
62
|
+
next if @options[:external] and segments.first == @namespace
|
63
|
+
|
30
64
|
@results[kind][name] ||= 0
|
31
65
|
@results[kind][name] += count
|
32
66
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-itemize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: puppet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.10'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '4.10'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
27
33
|
description: |2
|
28
34
|
Run this command with a space separated list of either manifest file paths, or
|
29
35
|
directories containing manifests. If omitted, it will default to inspecting all
|
@@ -35,6 +41,7 @@ executables:
|
|
35
41
|
extensions: []
|
36
42
|
extra_rdoc_files: []
|
37
43
|
files:
|
44
|
+
- CHANGELOG.md
|
38
45
|
- LICENSE
|
39
46
|
- README.md
|
40
47
|
- bin/puppet-itemize
|
@@ -44,7 +51,7 @@ files:
|
|
44
51
|
- lib/puppet_x/binford2k/itemize/parser.rb
|
45
52
|
- lib/puppet_x/binford2k/itemize/runner.rb
|
46
53
|
- lib/puppet_x/binford2k/itemize/version.rb
|
47
|
-
homepage: https://github.com/binford2k/
|
54
|
+
homepage: https://github.com/binford2k/binford2k-itemize
|
48
55
|
licenses:
|
49
56
|
- Apache-2.0
|
50
57
|
metadata: {}
|
@@ -64,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
71
|
version: '0'
|
65
72
|
requirements: []
|
66
73
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.7.7
|
68
75
|
signing_key:
|
69
76
|
specification_version: 4
|
70
77
|
summary: Count the number of types, classes, functions used in Puppet manifest(s).
|