kafo_parsers 0.0.3 → 0.0.5
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 +4 -4
- data/README.md +2 -0
- data/lib/kafo_parsers/puppet_module_parser.rb +27 -14
- data/lib/kafo_parsers/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1a2df4e35b7096729a5d26772b6d88b8facbfd1
|
4
|
+
data.tar.gz: d0ddc6bd2ed3172db9b512f01d62646e138484fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da03223bc048295fc11d518c143b836d135dff0f9715e0865b756f0b8086082a59429b01dc9d5220068e41787788aa58f5ed8581314419ebc902e20a0eabf219
|
7
|
+
data.tar.gz: b99099b7a24d1cd34acdd7ce99e296b936f5086c141d64d11e249c4ca8005799755095fbf273680e69c7a8b0c98ab6900897888755acb9b5fb2e985277da3a9b
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@ to do is provide a path to manifest file you want to be parsed.
|
|
7
7
|
The library is used in [Kafo](https://github.com/theforeman/kafo), which can
|
8
8
|
be used to get an idea of what's possible to build on top of this library.
|
9
9
|
|
10
|
+
Currently puppet classes and types (definitions) are supported.
|
11
|
+
|
10
12
|
## Installation
|
11
13
|
|
12
14
|
Add this line to your application's Gemfile:
|
@@ -8,6 +8,8 @@ module KafoParsers
|
|
8
8
|
# have to be defined in puppet DSL and vice versa, we just gather all info
|
9
9
|
# we can read from the whole manifest
|
10
10
|
class PuppetModuleParser
|
11
|
+
@@puppet_initialized = false
|
12
|
+
|
11
13
|
# You can call this method to get all supported information from a given manifest
|
12
14
|
#
|
13
15
|
# @param [ String ] manifest file path to parse
|
@@ -28,19 +30,28 @@ module KafoParsers
|
|
28
30
|
def initialize(file)
|
29
31
|
@file = file
|
30
32
|
raise ModuleName, "File not found #{file}, check your answer file" unless File.exists?(file)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
|
34
|
+
unless @@puppet_initialized
|
35
|
+
if Puppet::PUPPETVERSION.to_i >= 3
|
36
|
+
Puppet.initialize_settings
|
37
|
+
else
|
38
|
+
Puppet.parse_config
|
39
|
+
end
|
40
|
+
@@puppet_initialized = true
|
36
41
|
end
|
42
|
+
|
43
|
+
env = Puppet::Node::Environment.new
|
37
44
|
parser = Puppet::Parser::Parser.new(env)
|
38
45
|
parser.import(@file)
|
39
46
|
|
40
47
|
# Find object corresponding to class defined in init.pp in list of hostclasses
|
41
|
-
parser.environment.known_resource_types.hostclasses.
|
42
|
-
|
43
|
-
|
48
|
+
ast_types = parser.environment.known_resource_types.hostclasses.map(&:last)
|
49
|
+
@object = ast_types.find { |ast_type| ast_type.file == file }
|
50
|
+
|
51
|
+
# Find object in list of definitions if not found among hostclasses
|
52
|
+
if @object.nil?
|
53
|
+
ast_types = parser.environment.known_resource_types.definitions.map(&:last)
|
54
|
+
@object = ast_types.find { |ast_type| ast_type.file == file }
|
44
55
|
end
|
45
56
|
|
46
57
|
parser
|
@@ -65,17 +76,19 @@ module KafoParsers
|
|
65
76
|
# :types => { $param1 => 'boolean'},
|
66
77
|
# :groups => { $param1 => ['Parameters', 'Advanced']},
|
67
78
|
# :conditions => { $param1 => '$db_type == "mysql"'},
|
79
|
+
# :object_type => 'hostclass' # or definition
|
68
80
|
# }
|
69
81
|
def docs
|
70
|
-
data = { :docs => {}, :types => {}, :groups => {}, :conditions => {} }
|
82
|
+
data = { :docs => {}, :types => {}, :groups => {}, :conditions => {}, :object_type => '' }
|
71
83
|
if @object.nil?
|
72
84
|
raise DocParseError, "no documentation found for manifest #{@file}, parsing error?"
|
73
85
|
elsif !@object.doc.nil?
|
74
|
-
parser
|
75
|
-
data[:docs]
|
76
|
-
data[:groups]
|
77
|
-
data[:types]
|
78
|
-
data[:conditions]
|
86
|
+
parser = DocParser.new(@object.doc).parse
|
87
|
+
data[:docs] = parser.docs
|
88
|
+
data[:groups] = parser.groups
|
89
|
+
data[:types] = parser.types
|
90
|
+
data[:conditions] = parser.conditions
|
91
|
+
data[:object_type] = @object.type.to_s
|
79
92
|
end
|
80
93
|
data
|
81
94
|
end
|
data/lib/kafo_parsers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kafo_parsers
|
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
|
- Marek Hulan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - <
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.9'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - <
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.9'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ci_reporter
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.9.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.9.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: puppet
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,14 +116,14 @@ executables: []
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
-
-
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/kafo_parsers.rb
|
120
123
|
- lib/kafo_parsers/doc_parser.rb
|
121
124
|
- lib/kafo_parsers/exceptions.rb
|
125
|
+
- lib/kafo_parsers/puppet_module_parser.rb
|
122
126
|
- lib/kafo_parsers/version.rb
|
123
|
-
- lib/kafo_parsers.rb
|
124
|
-
- LICENSE.txt
|
125
|
-
- Rakefile
|
126
|
-
- README.md
|
127
127
|
homepage: https://github.com/theforeman/kafo_parsers
|
128
128
|
licenses:
|
129
129
|
- GPLv3+
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.4.6
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Puppet module parsers
|