pdk 1.14.1 → 1.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +155 -2
- data/lib/pdk.rb +28 -19
- data/lib/pdk/answer_file.rb +2 -95
- data/lib/pdk/bolt.rb +19 -0
- data/lib/pdk/cli.rb +4 -5
- data/lib/pdk/cli/bundle.rb +5 -1
- data/lib/pdk/cli/config.rb +3 -1
- data/lib/pdk/cli/config/get.rb +3 -1
- data/lib/pdk/cli/console.rb +1 -1
- data/lib/pdk/cli/convert.rb +16 -10
- data/lib/pdk/cli/exec.rb +2 -1
- data/lib/pdk/cli/exec/command.rb +45 -4
- data/lib/pdk/cli/exec_group.rb +78 -43
- data/lib/pdk/cli/get.rb +20 -0
- data/lib/pdk/cli/get/config.rb +24 -0
- data/lib/pdk/cli/module/build.rb +1 -1
- data/lib/pdk/cli/module/generate.rb +1 -1
- data/lib/pdk/cli/new/class.rb +2 -2
- data/lib/pdk/cli/new/defined_type.rb +2 -2
- data/lib/pdk/cli/new/provider.rb +2 -2
- data/lib/pdk/cli/new/task.rb +2 -2
- data/lib/pdk/cli/new/test.rb +2 -2
- data/lib/pdk/cli/new/transport.rb +2 -2
- data/lib/pdk/cli/release.rb +192 -0
- data/lib/pdk/cli/release/prep.rb +39 -0
- data/lib/pdk/cli/release/publish.rb +40 -0
- data/lib/pdk/cli/remove.rb +20 -0
- data/lib/pdk/cli/remove/config.rb +80 -0
- data/lib/pdk/cli/set.rb +20 -0
- data/lib/pdk/cli/set/config.rb +119 -0
- data/lib/pdk/cli/update.rb +18 -8
- data/lib/pdk/cli/util.rb +7 -3
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/validate.rb +26 -44
- data/lib/pdk/config.rb +265 -8
- data/lib/pdk/config/ini_file.rb +183 -0
- data/lib/pdk/config/ini_file_setting.rb +39 -0
- data/lib/pdk/config/namespace.rb +26 -6
- data/lib/pdk/config/setting.rb +3 -2
- data/lib/pdk/context.rb +99 -0
- data/lib/pdk/context/control_repo.rb +60 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/control_repo.rb +90 -0
- data/lib/pdk/generate.rb +1 -0
- data/lib/pdk/generate/defined_type.rb +25 -32
- data/lib/pdk/generate/module.rb +42 -35
- data/lib/pdk/generate/provider.rb +16 -65
- data/lib/pdk/generate/puppet_class.rb +25 -31
- data/lib/pdk/generate/puppet_object.rb +84 -189
- data/lib/pdk/generate/resource_api_object.rb +55 -0
- data/lib/pdk/generate/task.rb +28 -46
- data/lib/pdk/generate/transport.rb +21 -75
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/module/build.rb +38 -25
- data/lib/pdk/module/convert.rb +61 -42
- data/lib/pdk/module/metadata.rb +1 -3
- data/lib/pdk/module/release.rb +254 -0
- data/lib/pdk/module/update.rb +24 -16
- data/lib/pdk/module/update_manager.rb +8 -1
- data/lib/pdk/report.rb +18 -12
- data/lib/pdk/report/event.rb +6 -3
- data/lib/pdk/template.rb +59 -0
- data/lib/pdk/template/fetcher.rb +98 -0
- data/lib/pdk/template/fetcher/git.rb +85 -0
- data/lib/pdk/template/fetcher/local.rb +28 -0
- data/lib/pdk/template/renderer.rb +96 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/tests/unit.rb +5 -0
- data/lib/pdk/util.rb +55 -45
- data/lib/pdk/util/bundler.rb +9 -9
- data/lib/pdk/util/changelog_generator.rb +120 -0
- data/lib/pdk/util/env.rb +28 -11
- data/lib/pdk/util/filesystem.rb +62 -2
- data/lib/pdk/util/git.rb +60 -8
- data/lib/pdk/util/json_finder.rb +84 -0
- data/lib/pdk/util/puppet_strings.rb +3 -3
- data/lib/pdk/util/puppet_version.rb +4 -5
- data/lib/pdk/util/ruby_version.rb +9 -6
- data/lib/pdk/util/template_uri.rb +60 -48
- data/lib/pdk/util/version.rb +4 -4
- data/lib/pdk/validate.rb +79 -25
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +208 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
- data/lib/pdk/validate/invokable_validator.rb +215 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +118 -0
- data/lib/pdk/validate/validator_group.rb +104 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +755 -319
- metadata +66 -24
- data/lib/pdk/module/templatedir.rb +0 -391
- data/lib/pdk/template_file.rb +0 -96
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
- data/lib/pdk/validate/metadata_validator.rb +0 -26
- data/lib/pdk/validate/puppet/puppet_epp.rb +0 -137
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -137
- data/lib/pdk/validate/puppet_validator.rb +0 -26
- data/lib/pdk/validate/ruby/rubocop.rb +0 -72
- data/lib/pdk/validate/ruby_validator.rb +0 -26
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
- data/lib/pdk/validate/tasks/name.rb +0 -90
- data/lib/pdk/validate/tasks_validator.rb +0 -29
- data/lib/pdk/validate/yaml/syntax.rb +0 -125
- data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -92,12 +92,12 @@ module PDK
|
|
92
92
|
require 'pdk/generate'
|
93
93
|
|
94
94
|
generators = PDK::Generate.generators.select do |gen|
|
95
|
-
gen.
|
95
|
+
gen.const_defined?(:PUPPET_STRINGS_TYPE) && !gen::PUPPET_STRINGS_TYPE.nil?
|
96
96
|
end
|
97
97
|
|
98
98
|
known_objects = generate_hash
|
99
99
|
|
100
|
-
generators.map { |gen| [gen, known_objects[gen
|
100
|
+
generators.map { |gen| [gen, known_objects[gen::PUPPET_STRINGS_TYPE]] }.reject do |_, obj|
|
101
101
|
obj.nil? || obj.empty?
|
102
102
|
end
|
103
103
|
end
|
@@ -117,7 +117,7 @@ module PDK
|
|
117
117
|
require 'pdk/generate'
|
118
118
|
|
119
119
|
PDK::Generate.generators.find do |gen|
|
120
|
-
gen.
|
120
|
+
gen.const_defined?(:PUPPET_STRINGS_TYPE) && gen::PUPPET_STRINGS_TYPE == type
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -52,17 +52,16 @@ module PDK
|
|
52
52
|
return if options[:run] == :once && puppet_dev_fetched?
|
53
53
|
|
54
54
|
require 'pdk/util/git'
|
55
|
-
require 'fileutils'
|
56
55
|
|
57
56
|
# Check if the source is cloned and is a readable git repo
|
58
57
|
unless PDK::Util::Git.remote_repo? puppet_dev_path
|
59
58
|
# Check if the path has something in it already. Delete it and prepare for clone if so.
|
60
|
-
if
|
61
|
-
|
62
|
-
|
59
|
+
if PDK::Util::Filesystem.exist? puppet_dev_path
|
60
|
+
PDK::Util::Filesystem.delete(puppet_dev_path) if PDK::Util::Filesystem.file? puppet_dev_path
|
61
|
+
PDK::Util::Filesystem.rm_rf(puppet_dev_path) if PDK::Util::Filesystem.directory? puppet_dev_path
|
63
62
|
end
|
64
63
|
|
65
|
-
|
64
|
+
PDK::Util::Filesystem.mkdir_p puppet_dev_path
|
66
65
|
clone_result = PDK::Util::Git.git('clone', DEFAULT_PUPPET_DEV_URL, puppet_dev_path)
|
67
66
|
return if clone_result[:exit_code].zero?
|
68
67
|
|
@@ -44,7 +44,7 @@ module PDK
|
|
44
44
|
require 'pdk/util'
|
45
45
|
|
46
46
|
ruby_basedir = File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', '*')
|
47
|
-
|
47
|
+
PDK::Util::Filesystem.glob(ruby_basedir).sort.map { |ruby_dir|
|
48
48
|
version = File.basename(ruby_dir)
|
49
49
|
[version, version.split('.').take(2).concat(['0']).join('.')]
|
50
50
|
}.reverse.to_h
|
@@ -115,9 +115,7 @@ module PDK
|
|
115
115
|
else
|
116
116
|
# This allows the subprocess to find the 'bundler' gem, which isn't
|
117
117
|
# in GEM_HOME for gem installs.
|
118
|
-
|
119
|
-
# gem... Perhaps can be replaced with "Gem.path"?
|
120
|
-
[File.absolute_path(File.join(`gem which bundler`, '..', '..', '..', '..'))]
|
118
|
+
[File.absolute_path(File.join(bundler_basedir, '..', '..', '..'))]
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
@@ -128,6 +126,7 @@ module PDK
|
|
128
126
|
def gem_home
|
129
127
|
require 'pdk/util'
|
130
128
|
|
129
|
+
# TODO: bundle install --path is deprecated
|
131
130
|
# `bundle install --path` ignores all "system" installed gems and
|
132
131
|
# causes unnecessary package installs. `bundle install` (without
|
133
132
|
# --path) installs into GEM_HOME, which by default is non-user
|
@@ -142,10 +141,10 @@ module PDK
|
|
142
141
|
def available_puppet_versions
|
143
142
|
return @available_puppet_versions unless @available_puppet_versions.nil?
|
144
143
|
|
145
|
-
puppet_spec_files =
|
144
|
+
puppet_spec_files = PDK::Util::Filesystem.glob(File.join(gem_home, 'specifications', '**', 'puppet*.gemspec'))
|
146
145
|
|
147
146
|
gem_path.split(File::PATH_SEPARATOR).each do |path|
|
148
|
-
puppet_spec_files +=
|
147
|
+
puppet_spec_files += PDK::Util::Filesystem.glob(File.join(path, 'specifications', '**', 'puppet*.gemspec'))
|
149
148
|
end
|
150
149
|
|
151
150
|
puppet_specs = []
|
@@ -167,6 +166,10 @@ module PDK
|
|
167
166
|
def versions
|
168
167
|
self.class.versions
|
169
168
|
end
|
169
|
+
|
170
|
+
def bundler_basedir
|
171
|
+
Gem::Specification.latest_specs.find { |spec| spec.name.eql?('bundler') }.base_dir
|
172
|
+
end
|
170
173
|
end
|
171
174
|
end
|
172
175
|
end
|
@@ -7,6 +7,7 @@ module PDK
|
|
7
7
|
|
8
8
|
PACKAGED_TEMPLATE_KEYWORD = 'pdk-default'.freeze
|
9
9
|
DEPRECATED_TEMPLATE_URL = 'https://github.com/puppetlabs/pdk-module-template'.freeze
|
10
|
+
PDK_TEMPLATE_URL = 'https://github.com/puppetlabs/pdk-templates'.freeze
|
10
11
|
|
11
12
|
LEGACY_PACKAGED_TEMPLATE_PATHS = {
|
12
13
|
'windows' => 'file:///C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git',
|
@@ -35,15 +36,14 @@ module PDK
|
|
35
36
|
#
|
36
37
|
def initialize(opts_or_uri)
|
37
38
|
require 'addressable'
|
38
|
-
|
39
39
|
# If a uri string is passed, skip the valid uri finding code.
|
40
40
|
@uri = if opts_or_uri.is_a?(self.class)
|
41
41
|
opts_or_uri.uri
|
42
42
|
elsif opts_or_uri.is_a?(String)
|
43
43
|
begin
|
44
44
|
uri, ref = opts_or_uri.split('#', 2)
|
45
|
-
if
|
46
|
-
|
45
|
+
if PDK::Util::TemplateURI.packaged_template?(uri)
|
46
|
+
PDK::Util::TemplateURI.default_template_addressable_uri.tap { |default| default.fragment = ref unless ref.nil? || ref.empty? }
|
47
47
|
else
|
48
48
|
Addressable::URI.parse(opts_or_uri)
|
49
49
|
end
|
@@ -53,7 +53,7 @@ module PDK
|
|
53
53
|
elsif opts_or_uri.is_a?(Addressable::URI)
|
54
54
|
opts_or_uri.dup
|
55
55
|
else
|
56
|
-
|
56
|
+
PDK::Util::TemplateURI.first_valid_uri(PDK::Util::TemplateURI.templates(opts_or_uri))
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,28 +61,52 @@ module PDK
|
|
61
61
|
@uri == other.uri
|
62
62
|
end
|
63
63
|
|
64
|
+
def bare_uri
|
65
|
+
PDK::Util::TemplateURI.bare_uri(@uri)
|
66
|
+
end
|
67
|
+
|
64
68
|
# This is the URI represented in a format suitable for writing to
|
65
69
|
# metadata.
|
66
70
|
#
|
67
71
|
# @returns String
|
68
72
|
def metadata_format
|
69
|
-
if
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
@metadata_format ||= if PDK::Util::TemplateURI.packaged_template?(bare_uri)
|
74
|
+
PDK::Util::TemplateURI.human_readable("pdk-default##{uri_fragment}")
|
75
|
+
else
|
76
|
+
PDK::Util::TemplateURI.human_readable(@uri.to_s)
|
77
|
+
end
|
74
78
|
end
|
75
79
|
alias to_s metadata_format
|
76
80
|
alias to_str metadata_format
|
77
81
|
|
78
|
-
#
|
79
|
-
#
|
82
|
+
# Returns the fragment of the URI, of the default template's ref if one does not exist
|
80
83
|
# @returns String
|
81
|
-
|
82
|
-
|
84
|
+
# @api private
|
85
|
+
def uri_fragment
|
86
|
+
@uri.fragment || self.class.default_template_ref(self)
|
87
|
+
end
|
88
|
+
|
89
|
+
def uri_fragment=(fragment)
|
90
|
+
@uri.fragment = fragment
|
83
91
|
end
|
84
92
|
|
85
|
-
def
|
93
|
+
def default?
|
94
|
+
bare_uri == PDK::Util::TemplateURI.bare_uri(PDK::Util::TemplateURI.default_template_addressable_uri)
|
95
|
+
end
|
96
|
+
|
97
|
+
def default_ref?
|
98
|
+
uri_fragment == self.class.default_template_ref(self)
|
99
|
+
end
|
100
|
+
|
101
|
+
def puppetlabs_template?
|
102
|
+
self.class.packaged_template?(bare_uri) || bare_uri == PDK_TEMPLATE_URL
|
103
|
+
end
|
104
|
+
|
105
|
+
# Class Methods
|
106
|
+
|
107
|
+
# Remove the fragment off of URI. Useful for removing the branch
|
108
|
+
# for Git based URIs
|
109
|
+
def self.bare_uri(uri)
|
86
110
|
require 'addressable'
|
87
111
|
|
88
112
|
if uri.is_a?(Addressable::URI) && uri.fragment
|
@@ -98,37 +122,27 @@ module PDK
|
|
98
122
|
self.class.human_readable(@uri.path)
|
99
123
|
end
|
100
124
|
|
101
|
-
# @returns
|
102
|
-
def
|
103
|
-
|
104
|
-
|
125
|
+
# @returns PDK::Util::TemplateURI
|
126
|
+
def self.default_template_uri
|
127
|
+
require 'pdk/util'
|
128
|
+
require 'addressable'
|
105
129
|
|
106
|
-
|
107
|
-
@uri.fragment = ref
|
130
|
+
PDK::Util::TemplateURI.new(default_template_addressable_uri)
|
108
131
|
end
|
109
132
|
|
110
|
-
# @returns
|
111
|
-
|
133
|
+
# @returns Addressable::URI
|
134
|
+
# @api private
|
135
|
+
def self.default_template_addressable_uri
|
112
136
|
require 'pdk/util'
|
113
137
|
require 'addressable'
|
114
138
|
|
115
139
|
if PDK::Util.package_install?
|
116
|
-
|
140
|
+
Addressable::URI.new(scheme: 'file', host: '', path: File.join(PDK::Util.package_cachedir, 'pdk-templates.git'))
|
117
141
|
else
|
118
|
-
|
142
|
+
Addressable::URI.parse(PDK_TEMPLATE_URL)
|
119
143
|
end
|
120
144
|
end
|
121
145
|
|
122
|
-
def default?
|
123
|
-
git_remote == self.class.default_template_uri.git_remote
|
124
|
-
end
|
125
|
-
|
126
|
-
def ref_is_tag?
|
127
|
-
require 'pdk/util/git'
|
128
|
-
|
129
|
-
PDK::Util::Git.git('ls-remote', '--tags', '--exit-code', git_remote, git_ref)[:exit_code].zero?
|
130
|
-
end
|
131
|
-
|
132
146
|
# `C:...` urls are not URI-safe. They should be of the form `/C:...` to
|
133
147
|
# be URI-safe. scp-like urls like `user@host:/path` are not URI-safe
|
134
148
|
# either and so are subsequently converted to ssh:// URIs.
|
@@ -178,7 +192,6 @@ module PDK
|
|
178
192
|
# directory, and :allow_fallback contains a Boolean that specifies if
|
179
193
|
# the lookup process should proceed to the next template directory if
|
180
194
|
# the template file is not in this template directory.
|
181
|
-
#
|
182
195
|
def self.templates(opts)
|
183
196
|
require 'pdk/answer_file'
|
184
197
|
require 'pdk/util'
|
@@ -195,7 +208,7 @@ module PDK
|
|
195
208
|
else
|
196
209
|
explicit_uri = nil
|
197
210
|
end
|
198
|
-
metadata_uri = if PDK::Util.module_root &&
|
211
|
+
metadata_uri = if PDK::Util.module_root && PDK::Util::Filesystem.file?(File.join(PDK::Util.module_root, 'metadata.json'))
|
199
212
|
if PDK::Util.module_metadata['template-url']
|
200
213
|
new(uri_safe(PDK::Util.module_metadata['template-url'])).uri
|
201
214
|
else
|
@@ -204,10 +217,11 @@ module PDK
|
|
204
217
|
else
|
205
218
|
nil
|
206
219
|
end
|
207
|
-
|
220
|
+
default_template_url = PDK.config.get_within_scopes('module_defaults.template-url')
|
221
|
+
answers_uri = if [PACKAGED_TEMPLATE_KEYWORD, DEPRECATED_TEMPLATE_URL].include?(default_template_url)
|
208
222
|
Addressable::URI.parse(default_template_uri)
|
209
|
-
elsif
|
210
|
-
new(uri_safe(
|
223
|
+
elsif default_template_url
|
224
|
+
new(uri_safe(default_template_url)).uri
|
211
225
|
else
|
212
226
|
nil
|
213
227
|
end
|
@@ -246,22 +260,20 @@ module PDK
|
|
246
260
|
found_template[:uri]
|
247
261
|
end
|
248
262
|
|
249
|
-
def self.valid_template?(template)
|
263
|
+
def self.valid_template?(template, context = PDK.context)
|
250
264
|
require 'addressable'
|
251
|
-
require 'pdk/util/git'
|
252
|
-
require 'pdk/module/templatedir'
|
253
265
|
|
254
266
|
return false if template.nil? || !template.is_a?(Hash)
|
255
267
|
return false if template[:uri].nil? || !template[:uri].is_a?(Addressable::URI)
|
256
268
|
|
257
|
-
return true if PDK::Util::Git.repo?(
|
258
|
-
|
269
|
+
return true if PDK::Util::Git.repo?(bare_uri(template[:uri]))
|
259
270
|
path = human_readable(template[:uri].path)
|
260
|
-
if
|
271
|
+
if PDK::Util::Filesystem.directory?(path)
|
272
|
+
# We know that it's not a git repository, but it's a valid path on disk
|
261
273
|
begin
|
262
|
-
PDK::
|
263
|
-
return
|
264
|
-
rescue
|
274
|
+
renderer = PDK::Template::Renderer.instance(path, template[:uri], context)
|
275
|
+
return !renderer.nil?
|
276
|
+
rescue StandardError
|
265
277
|
nil
|
266
278
|
end
|
267
279
|
end
|
data/lib/pdk/util/version.rb
CHANGED
@@ -15,8 +15,8 @@ module PDK
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.pkg_sha
|
18
|
-
if version_file &&
|
19
|
-
ver =
|
18
|
+
if version_file && PDK::Util::Filesystem.exist?(version_file)
|
19
|
+
ver = PDK::Util::Filesystem.read_file(version_file)
|
20
20
|
sha = ver.strip.split('.')[5] unless ver.nil?
|
21
21
|
end
|
22
22
|
|
@@ -25,9 +25,9 @@ module PDK
|
|
25
25
|
|
26
26
|
def self.git_ref
|
27
27
|
require 'pdk/util/git'
|
28
|
-
source_git_dir = File.join(
|
28
|
+
source_git_dir = File.join(PDK::Util::Filesystem.expand_path('../../..', File.dirname(__FILE__)), '.git')
|
29
29
|
|
30
|
-
return unless
|
30
|
+
return unless PDK::Util::Filesystem.directory?(source_git_dir)
|
31
31
|
|
32
32
|
PDK::Util::Git.describe(source_git_dir)
|
33
33
|
end
|
data/lib/pdk/validate.rb
CHANGED
@@ -2,37 +2,91 @@ require 'pdk'
|
|
2
2
|
|
3
3
|
module PDK
|
4
4
|
module Validate
|
5
|
-
|
6
|
-
autoload :
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :PuppetEPP, 'pdk/validate/puppet/puppet_epp'
|
11
|
-
autoload :PuppetLint, 'pdk/validate/puppet/puppet_lint'
|
12
|
-
autoload :PuppetSyntax, 'pdk/validate/puppet/puppet_syntax'
|
13
|
-
autoload :PuppetValidator, 'pdk/validate/puppet_validator'
|
14
|
-
autoload :Rubocop, 'pdk/validate/ruby/rubocop'
|
15
|
-
autoload :RubyValidator, 'pdk/validate/ruby_validator'
|
16
|
-
autoload :TasksValidator, 'pdk/validate/tasks_validator'
|
17
|
-
autoload :YAMLValidator, 'pdk/validate/yaml_validator'
|
5
|
+
autoload :ExternalCommandValidator, 'pdk/validate/external_command_validator'
|
6
|
+
autoload :InternalRubyValidator, 'pdk/validate/internal_ruby_validator'
|
7
|
+
autoload :InvokableValidator, 'pdk/validate/invokable_validator'
|
8
|
+
autoload :Validator, 'pdk/validate/validator'
|
9
|
+
autoload :ValidatorGroup, 'pdk/validate/validator_group'
|
18
10
|
|
19
|
-
|
20
|
-
autoload :
|
21
|
-
autoload :
|
11
|
+
module ControlRepo
|
12
|
+
autoload :ControlRepoValidatorGroup, 'pdk/validate/control_repo/control_repo_validator_group'
|
13
|
+
autoload :EnvironmentConfValidator, 'pdk/validate/control_repo/environment_conf_validator'
|
22
14
|
end
|
23
15
|
|
24
|
-
|
25
|
-
autoload :
|
16
|
+
module Metadata
|
17
|
+
autoload :MetadataJSONLintValidator, 'pdk/validate/metadata/metadata_json_lint_validator'
|
18
|
+
autoload :MetadataSyntaxValidator, 'pdk/validate/metadata/metadata_syntax_validator'
|
19
|
+
autoload :MetadataValidatorGroup, 'pdk/validate/metadata/metadata_validator_group'
|
20
|
+
end
|
21
|
+
|
22
|
+
module Puppet
|
23
|
+
autoload :PuppetEPPValidator, 'pdk/validate/puppet/puppet_epp_validator'
|
24
|
+
autoload :PuppetLintValidator, 'pdk/validate/puppet/puppet_lint_validator'
|
25
|
+
autoload :PuppetSyntaxValidator, 'pdk/validate/puppet/puppet_syntax_validator'
|
26
|
+
autoload :PuppetValidatorGroup, 'pdk/validate/puppet/puppet_validator_group'
|
27
|
+
end
|
28
|
+
|
29
|
+
module Ruby
|
30
|
+
autoload :RubyRubocopValidator, 'pdk/validate/ruby/ruby_rubocop_validator'
|
31
|
+
autoload :RubyValidatorGroup, 'pdk/validate/ruby/ruby_validator_group'
|
32
|
+
end
|
33
|
+
|
34
|
+
module Tasks
|
35
|
+
autoload :TasksMetadataLintValidator, 'pdk/validate/tasks/tasks_metadata_lint_validator'
|
36
|
+
autoload :TasksNameValidator, 'pdk/validate/tasks/tasks_name_validator'
|
37
|
+
autoload :TasksValidatorGroup, 'pdk/validate/tasks/tasks_validator_group'
|
38
|
+
end
|
39
|
+
|
40
|
+
module YAML
|
41
|
+
autoload :YAMLSyntaxValidator, 'pdk/validate/yaml/yaml_syntax_validator'
|
42
|
+
autoload :YAMLValidatorGroup, 'pdk/validate/yaml/yaml_validator_group'
|
26
43
|
end
|
27
44
|
|
28
45
|
def self.validators
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
46
|
+
validator_hash.values
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.validator_names
|
50
|
+
validator_hash.keys
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
def self.validator_hash
|
55
|
+
# TODO: This isn't the most performant... But with only 6 items, it's fine
|
56
|
+
@validator_hash ||= [
|
57
|
+
ControlRepo::ControlRepoValidatorGroup,
|
58
|
+
Metadata::MetadataValidatorGroup,
|
59
|
+
Puppet::PuppetValidatorGroup,
|
60
|
+
Ruby::RubyValidatorGroup,
|
61
|
+
Tasks::TasksValidatorGroup,
|
62
|
+
YAML::YAMLValidatorGroup,
|
63
|
+
].map { |klass| [klass.new.name, klass] }.to_h.freeze
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.invoke_validators_by_name(context, names, parallel = false, options = {})
|
67
|
+
instances = names.select { |name| validator_names.include?(name) }
|
68
|
+
.map { |name| validator_hash[name].new(context, options) }
|
69
|
+
.select { |instance| instance.valid_in_context? }
|
70
|
+
.each { |instance| instance.prepare_invoke! }
|
71
|
+
report = PDK::Report.new
|
72
|
+
|
73
|
+
# Nothing to validate then nothing to do.
|
74
|
+
return [0, report] if instances.empty?
|
75
|
+
|
76
|
+
require 'pdk/cli/exec_group'
|
77
|
+
exec_group = PDK::CLI::ExecGroup.create(
|
78
|
+
_('Validating module using %{num_of_threads} threads' % { num_of_threads: instances.count }),
|
79
|
+
{ parallel: parallel },
|
80
|
+
options,
|
81
|
+
)
|
82
|
+
|
83
|
+
instances.each do |validator|
|
84
|
+
exec_group.register do
|
85
|
+
validator.invoke(report)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
[exec_group.exit_code, report]
|
36
90
|
end
|
37
91
|
|
38
92
|
class ParseOutputError < StandardError; end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Validate
|
5
|
+
module ControlRepo
|
6
|
+
class ControlRepoValidatorGroup < ValidatorGroup
|
7
|
+
def name
|
8
|
+
'control-repo'
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid_in_context?
|
12
|
+
context.is_a?(PDK::Context::ControlRepo)
|
13
|
+
end
|
14
|
+
|
15
|
+
def validators
|
16
|
+
[
|
17
|
+
EnvironmentConfValidator,
|
18
|
+
].freeze
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|