pdk 1.9.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +744 -711
  3. data/README.md +23 -21
  4. data/lib/pdk/answer_file.rb +3 -112
  5. data/lib/pdk/bolt.rb +20 -0
  6. data/lib/pdk/cli/build.rb +51 -54
  7. data/lib/pdk/cli/bundle.rb +33 -29
  8. data/lib/pdk/cli/console.rb +148 -0
  9. data/lib/pdk/cli/convert.rb +46 -37
  10. data/lib/pdk/cli/env.rb +51 -0
  11. data/lib/pdk/cli/errors.rb +4 -3
  12. data/lib/pdk/cli/exec/command.rb +285 -0
  13. data/lib/pdk/cli/exec/interactive_command.rb +109 -0
  14. data/lib/pdk/cli/exec.rb +32 -201
  15. data/lib/pdk/cli/exec_group.rb +79 -43
  16. data/lib/pdk/cli/get/config.rb +26 -0
  17. data/lib/pdk/cli/get.rb +22 -0
  18. data/lib/pdk/cli/new/class.rb +20 -22
  19. data/lib/pdk/cli/new/defined_type.rb +21 -21
  20. data/lib/pdk/cli/new/fact.rb +27 -0
  21. data/lib/pdk/cli/new/function.rb +27 -0
  22. data/lib/pdk/cli/new/module.rb +40 -29
  23. data/lib/pdk/cli/new/provider.rb +18 -18
  24. data/lib/pdk/cli/new/task.rb +23 -22
  25. data/lib/pdk/cli/new/test.rb +52 -0
  26. data/lib/pdk/cli/new/transport.rb +27 -0
  27. data/lib/pdk/cli/new.rb +15 -9
  28. data/lib/pdk/cli/release/prep.rb +39 -0
  29. data/lib/pdk/cli/release/publish.rb +46 -0
  30. data/lib/pdk/cli/release.rb +185 -0
  31. data/lib/pdk/cli/remove/config.rb +83 -0
  32. data/lib/pdk/cli/remove.rb +22 -0
  33. data/lib/pdk/cli/set/config.rb +121 -0
  34. data/lib/pdk/cli/set.rb +22 -0
  35. data/lib/pdk/cli/test/unit.rb +71 -69
  36. data/lib/pdk/cli/test.rb +9 -8
  37. data/lib/pdk/cli/update.rb +38 -21
  38. data/lib/pdk/cli/util/command_redirector.rb +13 -3
  39. data/lib/pdk/cli/util/interview.rb +25 -9
  40. data/lib/pdk/cli/util/option_normalizer.rb +6 -6
  41. data/lib/pdk/cli/util/option_validator.rb +19 -9
  42. data/lib/pdk/cli/util/spinner.rb +13 -0
  43. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  44. data/lib/pdk/cli/util.rb +105 -48
  45. data/lib/pdk/cli/validate.rb +96 -111
  46. data/lib/pdk/cli.rb +134 -87
  47. data/lib/pdk/config/errors.rb +5 -0
  48. data/lib/pdk/config/ini_file.rb +184 -0
  49. data/lib/pdk/config/ini_file_setting.rb +35 -0
  50. data/lib/pdk/config/json.rb +35 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +137 -0
  52. data/lib/pdk/config/json_schema_setting.rb +51 -0
  53. data/lib/pdk/config/json_with_schema.rb +47 -0
  54. data/lib/pdk/config/namespace.rb +362 -0
  55. data/lib/pdk/config/setting.rb +134 -0
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +31 -0
  58. data/lib/pdk/config/yaml.rb +41 -0
  59. data/lib/pdk/config/yaml_with_schema.rb +51 -0
  60. data/lib/pdk/config.rb +304 -0
  61. data/lib/pdk/context/control_repo.rb +61 -0
  62. data/lib/pdk/context/module.rb +28 -0
  63. data/lib/pdk/context/none.rb +22 -0
  64. data/lib/pdk/context.rb +98 -0
  65. data/lib/pdk/control_repo.rb +89 -0
  66. data/lib/pdk/generate/defined_type.rb +27 -33
  67. data/lib/pdk/generate/fact.rb +26 -0
  68. data/lib/pdk/generate/function.rb +49 -0
  69. data/lib/pdk/generate/module.rb +160 -153
  70. data/lib/pdk/generate/provider.rb +16 -69
  71. data/lib/pdk/generate/puppet_class.rb +27 -32
  72. data/lib/pdk/generate/puppet_object.rb +100 -159
  73. data/lib/pdk/generate/task.rb +34 -51
  74. data/lib/pdk/generate/transport.rb +34 -0
  75. data/lib/pdk/generate.rb +21 -8
  76. data/lib/pdk/logger.rb +24 -6
  77. data/lib/pdk/module/build.rb +125 -37
  78. data/lib/pdk/module/convert.rb +146 -65
  79. data/lib/pdk/module/metadata.rb +72 -71
  80. data/lib/pdk/module/release.rb +255 -0
  81. data/lib/pdk/module/update.rb +48 -37
  82. data/lib/pdk/module/update_manager.rb +75 -39
  83. data/lib/pdk/module.rb +10 -2
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +36 -48
  86. data/lib/pdk/report.rb +35 -22
  87. data/lib/pdk/template/fetcher/git.rb +84 -0
  88. data/lib/pdk/template/fetcher/local.rb +29 -0
  89. data/lib/pdk/template/fetcher.rb +100 -0
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +108 -0
  91. data/lib/pdk/template/renderer/v1/renderer.rb +131 -0
  92. data/lib/pdk/template/renderer/v1/template_file.rb +100 -0
  93. data/lib/pdk/template/renderer/v1.rb +25 -0
  94. data/lib/pdk/template/renderer.rb +97 -0
  95. data/lib/pdk/template/template_dir.rb +67 -0
  96. data/lib/pdk/template.rb +52 -0
  97. data/lib/pdk/tests/unit.rb +101 -51
  98. data/lib/pdk/util/bundler.rb +44 -42
  99. data/lib/pdk/util/changelog_generator.rb +138 -0
  100. data/lib/pdk/util/env.rb +48 -0
  101. data/lib/pdk/util/filesystem.rb +139 -2
  102. data/lib/pdk/util/git.rb +108 -8
  103. data/lib/pdk/util/json_finder.rb +86 -0
  104. data/lib/pdk/util/puppet_strings.rb +125 -0
  105. data/lib/pdk/util/puppet_version.rb +71 -87
  106. data/lib/pdk/util/ruby_version.rb +49 -25
  107. data/lib/pdk/util/template_uri.rb +283 -0
  108. data/lib/pdk/util/vendored_file.rb +34 -42
  109. data/lib/pdk/util/version.rb +11 -10
  110. data/lib/pdk/util/windows/api_types.rb +74 -44
  111. data/lib/pdk/util/windows/file.rb +31 -27
  112. data/lib/pdk/util/windows/process.rb +74 -0
  113. data/lib/pdk/util/windows/string.rb +19 -12
  114. data/lib/pdk/util/windows.rb +2 -0
  115. data/lib/pdk/util.rb +111 -124
  116. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  117. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  118. data/lib/pdk/validate/external_command_validator.rb +213 -0
  119. data/lib/pdk/validate/internal_ruby_validator.rb +101 -0
  120. data/lib/pdk/validate/invokable_validator.rb +238 -0
  121. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +84 -0
  122. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +76 -0
  123. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  124. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +131 -0
  125. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  126. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
  127. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +135 -0
  128. data/lib/pdk/validate/puppet/puppet_validator_group.rb +22 -0
  129. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +79 -0
  130. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  131. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +83 -0
  132. data/lib/pdk/validate/tasks/tasks_name_validator.rb +45 -0
  133. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  134. data/lib/pdk/validate/validator.rb +120 -0
  135. data/lib/pdk/validate/validator_group.rb +107 -0
  136. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +86 -0
  137. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  138. data/lib/pdk/validate.rb +86 -12
  139. data/lib/pdk/version.rb +2 -2
  140. data/lib/pdk.rb +60 -10
  141. metadata +138 -100
  142. data/lib/pdk/cli/module/build.rb +0 -14
  143. data/lib/pdk/cli/module/generate.rb +0 -45
  144. data/lib/pdk/cli/module.rb +0 -14
  145. data/lib/pdk/i18n.rb +0 -4
  146. data/lib/pdk/module/templatedir.rb +0 -321
  147. data/lib/pdk/template_file.rb +0 -95
  148. data/lib/pdk/validate/base_validator.rb +0 -215
  149. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -86
  150. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -109
  151. data/lib/pdk/validate/metadata_validator.rb +0 -30
  152. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -67
  153. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -112
  154. data/lib/pdk/validate/puppet_validator.rb +0 -30
  155. data/lib/pdk/validate/ruby/rubocop.rb +0 -77
  156. data/lib/pdk/validate/ruby_validator.rb +0 -29
  157. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -126
  158. data/lib/pdk/validate/tasks/name.rb +0 -88
  159. data/lib/pdk/validate/tasks_validator.rb +0 -33
  160. data/lib/pdk/validate/yaml/syntax.rb +0 -109
  161. data/lib/pdk/validate/yaml_validator.rb +0 -31
  162. data/locales/config.yaml +0 -21
  163. data/locales/pdk.pot +0 -1291
@@ -0,0 +1,45 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Tasks
6
+ class TasksNameValidator < InternalRubyValidator
7
+ INVALID_TASK_MSG = 'Invalid task name. Task names must start with a lowercase letter and can only contain lowercase letters, numbers, and underscores.'.freeze
8
+
9
+ def name
10
+ 'task-name'
11
+ end
12
+
13
+ def pattern
14
+ contextual_pattern('tasks/**/*')
15
+ end
16
+
17
+ def spinner_text
18
+ format('Checking task names (%{pattern}).', pattern: pattern.join(' '))
19
+ end
20
+
21
+ def validate_target(report, target)
22
+ task_name = File.basename(target, File.extname(target))
23
+ if PDK::CLI::Util::OptionValidator.valid_task_name?(task_name)
24
+ report.add_event(
25
+ file: target,
26
+ source: name,
27
+ state: :passed,
28
+ severity: 'ok'
29
+ )
30
+ 0
31
+ else
32
+ report.add_event(
33
+ file: target,
34
+ source: name,
35
+ state: :failure,
36
+ severity: 'error',
37
+ message: INVALID_TASK_MSG
38
+ )
39
+ 1
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Tasks
6
+ class TasksValidatorGroup < ValidatorGroup
7
+ def name
8
+ 'tasks'
9
+ end
10
+
11
+ def validators
12
+ [
13
+ TasksNameValidator,
14
+ TasksMetadataLintValidator
15
+ ].freeze
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,120 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ # The base Validator class which all other validators should inherit from.
6
+ # Acutal validator implementation should inherit from other child abstract classes e.g. ValidatorGroup or ExternalCommandValdiator
7
+ # @abstract
8
+ class Validator
9
+ # A hash of options set when the Validator was instantiated
10
+ # @return Hash[Object => Object]
11
+ attr_reader :options
12
+
13
+ # The PDK context which the validator will be within.
14
+ # @return [PDK::Context::AbstractContext] or a subclass PDK::Context::AbstractContext
15
+ attr_reader :context
16
+
17
+ # Whether the validator is prepared to be invoked.
18
+ # This should only be used for testing
19
+ #
20
+ # @return [Boolean]
21
+ #
22
+ # @api private
23
+ attr_reader :prepared
24
+
25
+ # Creates a new Validator
26
+ #
27
+ # @param context [PDK::Context::AbstractContext] Optional context which specifies where the validation will take place.
28
+ # Passing nil will use a None context (PDK::Context::None)
29
+ # @param options [Hash] Optional configuration for the Validator
30
+ # @option options :parent_validator [PDK::Validate::Validator] The parent validator for this validator.
31
+ # Typically used by ValidatorGroup to create trees of Validators for invocation.
32
+ def initialize(context = nil, options = {})
33
+ if context.nil?
34
+ @context = PDK::Context::None.new(nil)
35
+ else
36
+ raise ArgumentError, format('Expected PDK::Context::AbstractContext but got \'%{klass}\' for context', klass: context.class) unless context.is_a?(PDK::Context::AbstractContext)
37
+
38
+ @context = context
39
+ end
40
+ @options = options.dup.freeze
41
+ @prepared = false
42
+ end
43
+
44
+ # Whether this Validator can be invoked in this context. By default any Validator can work in any Context
45
+ # @return [Boolean]
46
+ # @abstract
47
+ def valid_in_context?
48
+ true
49
+ end
50
+
51
+ # Returns the text used for the spinner to display to the user while invoking
52
+ #
53
+ # @return [String]
54
+ #
55
+ # @abstract
56
+ def spinner_text; end
57
+
58
+ # Whether Spinners should be enabled for this validator
59
+ #
60
+ # @return [Boolean]
61
+ #
62
+ # @api private
63
+ # :nocov: .interactive? is tested elsewhere
64
+ def spinners_enabled?
65
+ PDK::CLI::Util.interactive?
66
+ end
67
+ # :nocov:
68
+
69
+ # The TTY Spinner for this Validator. Returns nil if spinners are disabled for this validator
70
+ #
71
+ # @return [TTY::Spinner, nil]
72
+ #
73
+ # @api private
74
+ # @abstract
75
+ def spinner; end
76
+
77
+ # Start the spinner if it exists
78
+ # @api private
79
+ def start_spinner
80
+ spinner&.auto_spin
81
+ nil
82
+ end
83
+
84
+ # Stop the spinner if it exists
85
+ # @api private
86
+ def stop_spinner(success)
87
+ return if spinner.nil?
88
+
89
+ success ? spinner.success : spinner.error
90
+ nil
91
+ end
92
+
93
+ # Name of the Validator
94
+ #
95
+ # @return [String]
96
+ #
97
+ # @abstract
98
+ def name; end
99
+
100
+ # Once off tasks to run prior to invoking
101
+ #
102
+ # @api private
103
+ #
104
+ # @abstract
105
+ def prepare_invoke!
106
+ @prepared = true
107
+ end
108
+
109
+ # Invokes the validator and returns the exit code
110
+ #
111
+ # @param report [PDK::Report] Accumulator of events during the invokation of this validator
112
+ # and potential child validators
113
+ # @abstract
114
+ def invoke(_report)
115
+ prepare_invoke!
116
+ 0
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,107 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ # The base class which should be used by meta-validators, that is, this group executes other validators
6
+ #
7
+ # At a minimum, the `name` and `validators` methods should be overridden in the child class
8
+ #
9
+ # An example concrete implementation could look like:
10
+ #
11
+ # module PDK
12
+ # module Validate
13
+ # module Tasks
14
+ # class TasksValidatorGroup < ValidatorGroup
15
+ # def name
16
+ # 'tasks'
17
+ # end
18
+ #
19
+ # def validators
20
+ # [
21
+ # TasksNameValidator,
22
+ # TasksMetadataLintValidator,
23
+ # ].freeze
24
+ # end
25
+ # end
26
+ # end
27
+ # end
28
+ # end
29
+ #
30
+ # @see PDK::Validate::Validator
31
+ # @abstract
32
+ class ValidatorGroup < Validator
33
+ # @see PDK::Validate::Validator.spinner_text
34
+ def spinner_text
35
+ format('Running %{name} validators ...', name: name)
36
+ end
37
+
38
+ # @see PDK::Validate::Validator.spinner
39
+ def spinner
40
+ return nil unless spinners_enabled?
41
+ return @spinner unless @spinner.nil?
42
+
43
+ require 'pdk/cli/util/spinner'
44
+
45
+ @spinner = TTY::Spinner::Multi.new("[:spinner] #{spinner_text}", PDK::CLI::Util.spinner_opts_for_platform)
46
+
47
+ # Register the child spinners
48
+ validator_instances.each do |instance|
49
+ next if instance.spinner.nil?
50
+
51
+ @spinner.register(instance.spinner)
52
+ end
53
+
54
+ @spinner
55
+ end
56
+
57
+ # Can be overridden by child classes to do their own preparation tasks.
58
+ # Typically this is not required by a meta-validator though.
59
+ #
60
+ # @see PDK::Validate::Validator.prepare_invoke!
61
+ def prepare_invoke!
62
+ return if @prepared
63
+
64
+ super
65
+
66
+ # Force the spinner to be registered etc.
67
+ spinner
68
+
69
+ # Prepare child validators
70
+ validator_instances.each(&:prepare_invoke!)
71
+ nil
72
+ end
73
+
74
+ # A list of Validator classes that this group will run
75
+ # @return Array[Class] An array of Validator classes (or objects that subclass to it) that this group will execute
76
+ # @abstract
77
+ def validators
78
+ []
79
+ end
80
+
81
+ # @see PDK::Validate::Validator.invoke
82
+ def invoke(report)
83
+ exit_code = 0
84
+
85
+ prepare_invoke!
86
+ start_spinner
87
+
88
+ validator_instances.each do |instance|
89
+ exit_code = instance.invoke(report)
90
+ break if exit_code != 0
91
+ end
92
+
93
+ stop_spinner(exit_code.zero?)
94
+
95
+ exit_code
96
+ end
97
+
98
+ # The instanitated PDK::Validator::Validator classes from the `validators` array
99
+ # @return Array[PDK::Validator::Validator]
100
+ # @api private
101
+ def validator_instances
102
+ @validator_instances ||= validators.map { |klass| klass.new(context, options.merge(parent_validator: self)) }
103
+ .select(&:valid_in_context?)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,86 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module YAML
6
+ class YAMLSyntaxValidator < InternalRubyValidator
7
+ YAML_ALLOWLISTED_CLASSES = [Symbol].freeze
8
+
9
+ def ignore_dotfiles
10
+ false
11
+ end
12
+
13
+ def name
14
+ 'yaml-syntax'
15
+ end
16
+
17
+ def pattern
18
+ [
19
+ '**/*.yaml',
20
+ '**/*.yml'
21
+ ].tap do |pat|
22
+ if context.is_a?(PDK::Context::ControlRepo)
23
+ pat.push(
24
+ '**/*.eyaml',
25
+ '**/*.eyml'
26
+ )
27
+ else
28
+ pat
29
+ end
30
+ end
31
+ end
32
+
33
+ def spinner_text
34
+ format('Checking YAML syntax (%{patterns}).', patterns: pattern.join(' '))
35
+ end
36
+
37
+ def validate_target(report, target)
38
+ return 0 unless PDK::Util::Filesystem.file?(target)
39
+
40
+ unless PDK::Util::Filesystem.readable?(target)
41
+ report.add_event(
42
+ file: target,
43
+ source: name,
44
+ state: :failure,
45
+ severity: 'error',
46
+ message: 'Could not be read.'
47
+ )
48
+ return 1
49
+ end
50
+
51
+ begin
52
+ ::YAML.safe_load(PDK::Util::Filesystem.read_file(target), permitted_classes: YAML_ALLOWLISTED_CLASSES, permitted_symbols: [], aliases: true)
53
+
54
+ report.add_event(
55
+ file: target,
56
+ source: name,
57
+ state: :passed,
58
+ severity: 'ok'
59
+ )
60
+ 0
61
+ rescue Psych::SyntaxError => e
62
+ report.add_event(
63
+ file: target,
64
+ source: name,
65
+ state: :failure,
66
+ severity: 'error',
67
+ line: e.line,
68
+ column: e.column,
69
+ message: format('%{problem} %{context}', problem: e.problem, context: e.context)
70
+ )
71
+ 1
72
+ rescue Psych::DisallowedClass => e
73
+ report.add_event(
74
+ file: target,
75
+ source: name,
76
+ state: :failure,
77
+ severity: 'error',
78
+ message: format('Unsupported class: %{message}', message: e.message)
79
+ )
80
+ 1
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,19 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module YAML
6
+ class YAMLValidatorGroup < ValidatorGroup
7
+ def name
8
+ 'yaml'
9
+ end
10
+
11
+ def validators
12
+ [
13
+ YAMLSyntaxValidator
14
+ ].freeze
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/pdk/validate.rb CHANGED
@@ -1,19 +1,93 @@
1
- require 'pdk/validate/metadata_validator'
2
- require 'pdk/validate/puppet_validator'
3
- require 'pdk/validate/ruby_validator'
4
- require 'pdk/validate/tasks_validator'
5
- require 'pdk/validate/yaml_validator'
1
+ require 'pdk'
6
2
 
7
3
  module PDK
8
4
  module Validate
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'
10
+
11
+ module ControlRepo
12
+ autoload :ControlRepoValidatorGroup, 'pdk/validate/control_repo/control_repo_validator_group'
13
+ autoload :EnvironmentConfValidator, 'pdk/validate/control_repo/environment_conf_validator'
14
+ end
15
+
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 :PuppetPlanSyntaxValidator, 'pdk/validate/puppet/puppet_plan_syntax_validator'
27
+ autoload :PuppetValidatorGroup, 'pdk/validate/puppet/puppet_validator_group'
28
+ end
29
+
30
+ module Ruby
31
+ autoload :RubyRubocopValidator, 'pdk/validate/ruby/ruby_rubocop_validator'
32
+ autoload :RubyValidatorGroup, 'pdk/validate/ruby/ruby_validator_group'
33
+ end
34
+
35
+ module Tasks
36
+ autoload :TasksMetadataLintValidator, 'pdk/validate/tasks/tasks_metadata_lint_validator'
37
+ autoload :TasksNameValidator, 'pdk/validate/tasks/tasks_name_validator'
38
+ autoload :TasksValidatorGroup, 'pdk/validate/tasks/tasks_validator_group'
39
+ end
40
+
41
+ module YAML
42
+ autoload :YAMLSyntaxValidator, 'pdk/validate/yaml/yaml_syntax_validator'
43
+ autoload :YAMLValidatorGroup, 'pdk/validate/yaml/yaml_validator_group'
44
+ end
45
+
9
46
  def self.validators
10
- @validators ||= [
11
- MetadataValidator,
12
- YAMLValidator,
13
- PuppetValidator,
14
- RubyValidator,
15
- TasksValidator,
16
- ].freeze
47
+ validator_hash.values
48
+ end
49
+
50
+ def self.validator_names
51
+ validator_hash.keys
52
+ end
53
+
54
+ # @api private
55
+ def self.validator_hash
56
+ # TODO: This isn't the most performant... But with only 6 items, it's fine
57
+ @validator_hash ||= [
58
+ ControlRepo::ControlRepoValidatorGroup,
59
+ Metadata::MetadataValidatorGroup,
60
+ Puppet::PuppetValidatorGroup,
61
+ Ruby::RubyValidatorGroup,
62
+ Tasks::TasksValidatorGroup,
63
+ YAML::YAMLValidatorGroup
64
+ ].to_h { |klass| [klass.new.name, klass] }.freeze
65
+ end
66
+
67
+ def self.invoke_validators_by_name(context, names, parallel = false, options = {})
68
+ instances = names.select { |name| validator_names.include?(name) }
69
+ .map { |name| validator_hash[name].new(context, options) }
70
+ .select(&:valid_in_context?)
71
+ .each(&:prepare_invoke!)
72
+ report = PDK::Report.new
73
+
74
+ # Nothing to validate then nothing to do.
75
+ return [0, report] if instances.empty?
76
+
77
+ require 'pdk/cli/exec_group'
78
+ exec_group = PDK::CLI::ExecGroup.create(
79
+ format('Validating module using %{num_of_threads} threads', num_of_threads: instances.count),
80
+ { parallel: parallel },
81
+ options
82
+ )
83
+
84
+ instances.each do |validator|
85
+ exec_group.register do
86
+ validator.invoke(report)
87
+ end
88
+ end
89
+
90
+ [exec_group.exit_code, report]
17
91
  end
18
92
 
19
93
  class ParseOutputError < StandardError; end
data/lib/pdk/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PDK
2
- VERSION = '1.9.0'.freeze
3
- TEMPLATE_REF = VERSION
2
+ VERSION = '3.2.0'.freeze
3
+ TEMPLATE_REF = '3.2.0'.freeze
4
4
  end
data/lib/pdk.rb CHANGED
@@ -1,10 +1,60 @@
1
- require 'pdk/answer_file'
2
- require 'pdk/generate'
3
- require 'pdk/i18n'
4
- require 'pdk/logger'
5
- require 'pdk/report'
6
- require 'pdk/template_file'
7
- require 'pdk/validate'
8
- require 'pdk/version'
9
-
10
- module PDK; end
1
+ module PDK
2
+ autoload :AnswerFile, 'pdk/answer_file'
3
+ autoload :Bolt, 'pdk/bolt'
4
+ autoload :Config, 'pdk/config'
5
+ autoload :Context, 'pdk/context'
6
+ autoload :ControlRepo, 'pdk/control_repo'
7
+ autoload :Generate, 'pdk/generate'
8
+ autoload :Logger, 'pdk/logger'
9
+ autoload :Module, 'pdk/module'
10
+ autoload :Report, 'pdk/report'
11
+ autoload :Template, 'pdk/template'
12
+ autoload :TEMPLATE_REF, 'pdk/version'
13
+ autoload :Util, 'pdk/util'
14
+ autoload :Validate, 'pdk/validate'
15
+ autoload :VERSION, 'pdk/version'
16
+
17
+ # TODO: Refactor backend code to not raise CLI errors or use CLI util
18
+ # methods.
19
+ module CLI
20
+ autoload :ExitWithError, 'pdk/cli/errors'
21
+ autoload :FatalError, 'pdk/cli/errors'
22
+ autoload :Util, 'pdk/cli/util'
23
+ autoload :Exec, 'pdk/cli/exec'
24
+ autoload :ExecGroup, 'pdk/cli/exec_group'
25
+ end
26
+
27
+ module Test
28
+ autoload :Unit, 'pdk/tests/unit'
29
+ end
30
+
31
+ def self.logger
32
+ @logger ||= PDK::Logger.new
33
+ end
34
+
35
+ def self.config
36
+ return @config unless @config.nil?
37
+
38
+ options = {}
39
+ options['user.module_defaults.path'] = PDK::Util::Env['PDK_ANSWER_FILE'] unless PDK::Util::Env['PDK_ANSWER_FILE'].nil?
40
+ @config = PDK::Config.new(options)
41
+ end
42
+
43
+ def self.context
44
+ @context ||= PDK::Context.create(Dir.pwd)
45
+ end
46
+
47
+ def self.available_feature_flags
48
+ @available_feature_flags ||= ['controlrepo'].freeze
49
+ end
50
+
51
+ def self.requested_feature_flags
52
+ @requested_feature_flags ||= (PDK::Util::Env['PDK_FEATURE_FLAGS'] || '').split(',').map(&:strip)
53
+ end
54
+
55
+ def self.feature_flag?(flagname)
56
+ return false unless available_feature_flags.include?(flagname)
57
+
58
+ requested_feature_flags.include?(flagname)
59
+ end
60
+ end