pdk 1.14.1 → 1.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -2
  3. data/lib/pdk.rb +28 -19
  4. data/lib/pdk/answer_file.rb +2 -95
  5. data/lib/pdk/bolt.rb +19 -0
  6. data/lib/pdk/cli.rb +4 -5
  7. data/lib/pdk/cli/bundle.rb +5 -1
  8. data/lib/pdk/cli/config.rb +3 -1
  9. data/lib/pdk/cli/config/get.rb +3 -1
  10. data/lib/pdk/cli/console.rb +1 -1
  11. data/lib/pdk/cli/convert.rb +16 -10
  12. data/lib/pdk/cli/exec.rb +2 -1
  13. data/lib/pdk/cli/exec/command.rb +45 -4
  14. data/lib/pdk/cli/exec_group.rb +78 -43
  15. data/lib/pdk/cli/get.rb +20 -0
  16. data/lib/pdk/cli/get/config.rb +24 -0
  17. data/lib/pdk/cli/module/build.rb +1 -1
  18. data/lib/pdk/cli/module/generate.rb +1 -1
  19. data/lib/pdk/cli/new/class.rb +2 -2
  20. data/lib/pdk/cli/new/defined_type.rb +2 -2
  21. data/lib/pdk/cli/new/provider.rb +2 -2
  22. data/lib/pdk/cli/new/task.rb +2 -2
  23. data/lib/pdk/cli/new/test.rb +2 -2
  24. data/lib/pdk/cli/new/transport.rb +2 -2
  25. data/lib/pdk/cli/release.rb +192 -0
  26. data/lib/pdk/cli/release/prep.rb +39 -0
  27. data/lib/pdk/cli/release/publish.rb +40 -0
  28. data/lib/pdk/cli/remove.rb +20 -0
  29. data/lib/pdk/cli/remove/config.rb +80 -0
  30. data/lib/pdk/cli/set.rb +20 -0
  31. data/lib/pdk/cli/set/config.rb +119 -0
  32. data/lib/pdk/cli/update.rb +18 -8
  33. data/lib/pdk/cli/util.rb +7 -3
  34. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  35. data/lib/pdk/cli/validate.rb +26 -44
  36. data/lib/pdk/config.rb +265 -8
  37. data/lib/pdk/config/ini_file.rb +183 -0
  38. data/lib/pdk/config/ini_file_setting.rb +39 -0
  39. data/lib/pdk/config/namespace.rb +26 -6
  40. data/lib/pdk/config/setting.rb +3 -2
  41. data/lib/pdk/context.rb +99 -0
  42. data/lib/pdk/context/control_repo.rb +60 -0
  43. data/lib/pdk/context/module.rb +28 -0
  44. data/lib/pdk/context/none.rb +22 -0
  45. data/lib/pdk/control_repo.rb +90 -0
  46. data/lib/pdk/generate.rb +1 -0
  47. data/lib/pdk/generate/defined_type.rb +25 -32
  48. data/lib/pdk/generate/module.rb +42 -35
  49. data/lib/pdk/generate/provider.rb +16 -65
  50. data/lib/pdk/generate/puppet_class.rb +25 -31
  51. data/lib/pdk/generate/puppet_object.rb +84 -189
  52. data/lib/pdk/generate/resource_api_object.rb +55 -0
  53. data/lib/pdk/generate/task.rb +28 -46
  54. data/lib/pdk/generate/transport.rb +21 -75
  55. data/lib/pdk/module.rb +1 -1
  56. data/lib/pdk/module/build.rb +38 -25
  57. data/lib/pdk/module/convert.rb +61 -42
  58. data/lib/pdk/module/metadata.rb +1 -3
  59. data/lib/pdk/module/release.rb +254 -0
  60. data/lib/pdk/module/update.rb +24 -16
  61. data/lib/pdk/module/update_manager.rb +8 -1
  62. data/lib/pdk/report.rb +18 -12
  63. data/lib/pdk/report/event.rb +6 -3
  64. data/lib/pdk/template.rb +59 -0
  65. data/lib/pdk/template/fetcher.rb +98 -0
  66. data/lib/pdk/template/fetcher/git.rb +85 -0
  67. data/lib/pdk/template/fetcher/local.rb +28 -0
  68. data/lib/pdk/template/renderer.rb +96 -0
  69. data/lib/pdk/template/renderer/v1.rb +25 -0
  70. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
  71. data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
  72. data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
  73. data/lib/pdk/template/template_dir.rb +67 -0
  74. data/lib/pdk/tests/unit.rb +5 -0
  75. data/lib/pdk/util.rb +55 -45
  76. data/lib/pdk/util/bundler.rb +9 -9
  77. data/lib/pdk/util/changelog_generator.rb +120 -0
  78. data/lib/pdk/util/env.rb +28 -11
  79. data/lib/pdk/util/filesystem.rb +62 -2
  80. data/lib/pdk/util/git.rb +60 -8
  81. data/lib/pdk/util/json_finder.rb +84 -0
  82. data/lib/pdk/util/puppet_strings.rb +3 -3
  83. data/lib/pdk/util/puppet_version.rb +4 -5
  84. data/lib/pdk/util/ruby_version.rb +9 -6
  85. data/lib/pdk/util/template_uri.rb +60 -48
  86. data/lib/pdk/util/version.rb +4 -4
  87. data/lib/pdk/validate.rb +79 -25
  88. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  89. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  90. data/lib/pdk/validate/external_command_validator.rb +208 -0
  91. data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
  92. data/lib/pdk/validate/invokable_validator.rb +215 -0
  93. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
  94. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
  95. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  96. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
  97. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  98. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
  99. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
  100. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
  101. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  102. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
  103. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
  104. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  105. data/lib/pdk/validate/validator.rb +118 -0
  106. data/lib/pdk/validate/validator_group.rb +104 -0
  107. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
  108. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  109. data/lib/pdk/version.rb +1 -1
  110. data/locales/pdk.pot +755 -319
  111. metadata +66 -24
  112. data/lib/pdk/module/templatedir.rb +0 -391
  113. data/lib/pdk/template_file.rb +0 -96
  114. data/lib/pdk/validate/base_validator.rb +0 -215
  115. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
  116. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
  117. data/lib/pdk/validate/metadata_validator.rb +0 -26
  118. data/lib/pdk/validate/puppet/puppet_epp.rb +0 -137
  119. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
  120. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -137
  121. data/lib/pdk/validate/puppet_validator.rb +0 -26
  122. data/lib/pdk/validate/ruby/rubocop.rb +0 -72
  123. data/lib/pdk/validate/ruby_validator.rb +0 -26
  124. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
  125. data/lib/pdk/validate/tasks/name.rb +0 -90
  126. data/lib/pdk/validate/tasks_validator.rb +0 -29
  127. data/lib/pdk/validate/yaml/syntax.rb +0 -125
  128. 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.respond_to?(:puppet_strings_type) && !gen.puppet_strings_type.nil?
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.puppet_strings_type]] }.reject do |_, obj|
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.respond_to?(:puppet_strings_type) && gen.puppet_strings_type == type
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 File.exist? puppet_dev_path
61
- File.delete(puppet_dev_path) if File.file? puppet_dev_path
62
- FileUtils.rm_rf(puppet_dev_path) if File.directory? puppet_dev_path
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
- FileUtils.mkdir_p puppet_dev_path
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
- Dir[ruby_basedir].sort.map { |ruby_dir|
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
- # TODO: There must be a better way to do this than shelling out to
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 = Dir[File.join(gem_home, 'specifications', '**', 'puppet*.gemspec')]
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 += Dir[File.join(path, 'specifications', '**', 'puppet*.gemspec')]
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 self.class.packaged_template?(uri)
46
- self.class.default_template_uri(ref).uri
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
- self.class.first_valid_uri(self.class.templates(opts_or_uri))
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 self.class.packaged_template?(git_remote)
70
- self.class.human_readable("pdk-default##{git_ref}")
71
- else
72
- self.class.human_readable(@uri.to_s)
73
- end
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
- # This is the url without a fragment, suitable for git clones.
79
- #
82
+ # Returns the fragment of the URI, of the default template's ref if one does not exist
80
83
  # @returns String
81
- def git_remote
82
- self.class.git_remote(@uri)
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 self.git_remote(uri)
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 String
102
- def git_ref
103
- @uri.fragment || self.class.default_template_ref(self)
104
- end
125
+ # @returns PDK::Util::TemplateURI
126
+ def self.default_template_uri
127
+ require 'pdk/util'
128
+ require 'addressable'
105
129
 
106
- def git_ref=(ref)
107
- @uri.fragment = ref
130
+ PDK::Util::TemplateURI.new(default_template_addressable_uri)
108
131
  end
109
132
 
110
- # @returns PDK::Util::TemplateURI
111
- def self.default_template_uri(ref = nil)
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
- PDK::Util::TemplateURI.new(Addressable::URI.new(scheme: 'file', host: '', path: File.join(PDK::Util.package_cachedir, 'pdk-templates.git'), fragment: ref))
140
+ Addressable::URI.new(scheme: 'file', host: '', path: File.join(PDK::Util.package_cachedir, 'pdk-templates.git'))
117
141
  else
118
- PDK::Util::TemplateURI.new(Addressable::URI.new(scheme: 'https', host: 'github.com', path: '/puppetlabs/pdk-templates', fragment: ref))
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 && File.file?(File.join(PDK::Util.module_root, 'metadata.json'))
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
- answers_uri = if [PACKAGED_TEMPLATE_KEYWORD, DEPRECATED_TEMPLATE_URL].include?(PDK.answers['template-url'])
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 PDK.answers['template-url']
210
- new(uri_safe(PDK.answers['template-url'])).uri
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?(git_remote(template[:uri]))
258
-
269
+ return true if PDK::Util::Git.repo?(bare_uri(template[:uri]))
259
270
  path = human_readable(template[:uri].path)
260
- if File.directory?(path)
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::Module::TemplateDir.new(path) {}
263
- return true
264
- rescue ArgumentError
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
@@ -15,8 +15,8 @@ module PDK
15
15
  end
16
16
 
17
17
  def self.pkg_sha
18
- if version_file && File.exist?(version_file)
19
- ver = File.read(version_file)
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(File.expand_path('../../..', File.dirname(__FILE__)), '.git')
28
+ source_git_dir = File.join(PDK::Util::Filesystem.expand_path('../../..', File.dirname(__FILE__)), '.git')
29
29
 
30
- return unless File.directory?(source_git_dir)
30
+ return unless PDK::Util::Filesystem.directory?(source_git_dir)
31
31
 
32
32
  PDK::Util::Git.describe(source_git_dir)
33
33
  end
@@ -2,37 +2,91 @@ require 'pdk'
2
2
 
3
3
  module PDK
4
4
  module Validate
5
- # TODO: Fix validator namespacing
6
- autoload :BaseValidator, 'pdk/validate/base_validator'
7
- autoload :MetadataJSONLint, 'pdk/validate/metadata/metadata_json_lint'
8
- autoload :MetadataSyntax, 'pdk/validate/metadata/metadata_syntax'
9
- autoload :MetadataValidator, 'pdk/validate/metadata_validator'
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
- class Tasks
20
- autoload :Name, 'pdk/validate/tasks/name'
21
- autoload :MetadataLint, 'pdk/validate/tasks/metadata_lint'
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
- class YAML
25
- autoload :Syntax, 'pdk/validate/yaml/syntax'
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
- @validators ||= [
30
- MetadataValidator,
31
- YAMLValidator,
32
- PuppetValidator,
33
- RubyValidator,
34
- TasksValidator,
35
- ].freeze
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