pdk 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/lib/pdk.rb +25 -18
  4. data/lib/pdk/answer_file.rb +2 -93
  5. data/lib/pdk/cli.rb +1 -5
  6. data/lib/pdk/cli/config.rb +3 -1
  7. data/lib/pdk/cli/config/get.rb +3 -1
  8. data/lib/pdk/cli/convert.rb +1 -1
  9. data/lib/pdk/cli/exec/command.rb +13 -0
  10. data/lib/pdk/cli/exec_group.rb +78 -43
  11. data/lib/pdk/cli/get.rb +20 -0
  12. data/lib/pdk/cli/get/config.rb +24 -0
  13. data/lib/pdk/cli/util.rb +6 -3
  14. data/lib/pdk/cli/validate.rb +26 -44
  15. data/lib/pdk/config.rb +178 -4
  16. data/lib/pdk/config/ini_file.rb +183 -0
  17. data/lib/pdk/config/ini_file_setting.rb +39 -0
  18. data/lib/pdk/config/namespace.rb +25 -5
  19. data/lib/pdk/config/setting.rb +3 -2
  20. data/lib/pdk/context.rb +96 -0
  21. data/lib/pdk/context/control_repo.rb +60 -0
  22. data/lib/pdk/context/module.rb +28 -0
  23. data/lib/pdk/context/none.rb +22 -0
  24. data/lib/pdk/control_repo.rb +40 -0
  25. data/lib/pdk/generate/module.rb +8 -12
  26. data/lib/pdk/module/release.rb +2 -8
  27. data/lib/pdk/util.rb +35 -5
  28. data/lib/pdk/util/bundler.rb +1 -0
  29. data/lib/pdk/util/changelog_generator.rb +6 -1
  30. data/lib/pdk/util/template_uri.rb +4 -3
  31. data/lib/pdk/validate.rb +72 -25
  32. data/lib/pdk/validate/external_command_validator.rb +208 -0
  33. data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
  34. data/lib/pdk/validate/invokable_validator.rb +216 -0
  35. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
  36. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
  37. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  38. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
  39. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  40. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
  41. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
  42. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
  43. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  44. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
  45. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
  46. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  47. data/lib/pdk/validate/validator.rb +111 -0
  48. data/lib/pdk/validate/validator_group.rb +103 -0
  49. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
  50. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  51. data/lib/pdk/version.rb +1 -1
  52. data/locales/pdk.pot +161 -125
  53. metadata +29 -17
  54. data/lib/pdk/validate/base_validator.rb +0 -215
  55. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
  56. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
  57. data/lib/pdk/validate/metadata_validator.rb +0 -26
  58. data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
  59. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
  60. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
  61. data/lib/pdk/validate/puppet_validator.rb +0 -26
  62. data/lib/pdk/validate/ruby/rubocop.rb +0 -72
  63. data/lib/pdk/validate/ruby_validator.rb +0 -26
  64. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
  65. data/lib/pdk/validate/tasks/name.rb +0 -90
  66. data/lib/pdk/validate/tasks_validator.rb +0 -29
  67. data/lib/pdk/validate/yaml/syntax.rb +0 -125
  68. data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -1,26 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class RubyValidator < BaseValidator
6
- def self.name
7
- 'ruby'
8
- end
9
-
10
- def self.ruby_validators
11
- [Rubocop]
12
- end
13
-
14
- def self.invoke(report, options = {})
15
- exit_code = 0
16
-
17
- ruby_validators.each do |validator|
18
- exit_code = validator.invoke(report, options)
19
- break if exit_code != 0
20
- end
21
-
22
- exit_code
23
- end
24
- end
25
- end
26
- end
@@ -1,130 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class Tasks
6
- class MetadataLint < BaseValidator
7
- FORGE_SCHEMA_URL = 'https://forgeapi.puppet.com/schemas/task.json'.freeze
8
-
9
- def self.name
10
- 'task-metadata-lint'
11
- end
12
-
13
- def self.pattern
14
- 'tasks/*.json'
15
- end
16
-
17
- def self.spinner_text(_targets = [])
18
- _('Checking task metadata style (%{targets}).') % {
19
- targets: pattern,
20
- }
21
- end
22
-
23
- def self.create_spinner(targets = [], options = {})
24
- require 'pdk/cli/util'
25
-
26
- return unless PDK::CLI::Util.interactive?
27
-
28
- options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
29
-
30
- exec_group = options[:exec_group]
31
- @spinner = if exec_group
32
- exec_group.add_spinner(spinner_text(targets), options)
33
- else
34
- require 'pdk/cli/util/spinner'
35
-
36
- TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
37
- end
38
- @spinner.auto_spin
39
- end
40
-
41
- def self.stop_spinner(exit_code)
42
- if exit_code.zero? && @spinner
43
- @spinner.success
44
- elsif @spinner
45
- @spinner.error
46
- end
47
- end
48
-
49
- def self.schema_file
50
- require 'pdk/util/vendored_file'
51
-
52
- schema = PDK::Util::VendoredFile.new('task.json', FORGE_SCHEMA_URL).read
53
-
54
- JSON.parse(schema)
55
- rescue PDK::Util::VendoredFile::DownloadError => e
56
- raise PDK::CLI::FatalError, e.message
57
- rescue JSON::ParserError
58
- raise PDK::CLI::FatalError, _('Failed to parse Task Metadata Schema file.')
59
- end
60
-
61
- def self.invoke(report, options = {})
62
- targets, skipped, invalid = parse_targets(options)
63
-
64
- process_skipped(report, skipped)
65
- process_invalid(report, invalid)
66
-
67
- return 0 if targets.empty?
68
-
69
- return_val = 0
70
- create_spinner(targets, options)
71
-
72
- require 'json-schema'
73
-
74
- targets.each do |target|
75
- unless PDK::Util::Filesystem.readable?(target)
76
- report.add_event(
77
- file: target,
78
- source: name,
79
- state: :failure,
80
- severity: 'error',
81
- message: _('Could not be read.'),
82
- )
83
- return_val = 1
84
- next
85
- end
86
-
87
- begin
88
- # Need to set the JSON Parser and State Generator to the Native one to be
89
- # compatible with the multi_json adapter.
90
- JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
91
- JSON.generator = JSON::Ext::Generator
92
-
93
- begin
94
- errors = JSON::Validator.fully_validate(schema_file, PDK::Util::Filesystem.read_file(target)) || []
95
- rescue JSON::Schema::SchemaError => e
96
- raise PDK::CLI::FatalError, _('Unable to validate Task Metadata. %{error}.') % { error: e.message }
97
- end
98
-
99
- if errors.empty?
100
- report.add_event(
101
- file: target,
102
- source: name,
103
- state: :passed,
104
- severity: 'ok',
105
- )
106
- else
107
- errors.each do |error|
108
- # strip off the trailing parts that aren't relevant
109
- error = error.split('in schema').first if error.include? 'in schema'
110
-
111
- report.add_event(
112
- file: target,
113
- source: name,
114
- state: :failure,
115
- severity: 'error',
116
- message: error,
117
- )
118
- end
119
- return_val = 1
120
- end
121
- end
122
- end
123
-
124
- stop_spinner(return_val)
125
- return_val
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,90 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class Tasks
6
- class Name < BaseValidator
7
- INVALID_TASK_MSG = _(
8
- 'Invalid task name. Task names must start with a lowercase letter ' \
9
- 'and can only contain lowercase letters, numbers, and underscores.',
10
- )
11
-
12
- def self.name
13
- 'task-name'
14
- end
15
-
16
- def self.pattern
17
- 'tasks/**/*'
18
- end
19
-
20
- def self.spinner_text(_targets = [])
21
- _('Checking task names (%{targets}).') % {
22
- targets: pattern,
23
- }
24
- end
25
-
26
- def self.create_spinner(targets = [], options = {})
27
- require 'pdk/cli/util'
28
-
29
- return unless PDK::CLI::Util.interactive?
30
- options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
31
-
32
- exec_group = options[:exec_group]
33
- @spinner = if exec_group
34
- exec_group.add_spinner(spinner_text(targets), options)
35
- else
36
- require 'pdk/cli/util/spinner'
37
-
38
- TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
39
- end
40
- @spinner.auto_spin
41
- end
42
-
43
- def self.stop_spinner(exit_code)
44
- if exit_code.zero? && @spinner
45
- @spinner.success
46
- elsif @spinner
47
- @spinner.error
48
- end
49
- end
50
-
51
- def self.invoke(report, options = {})
52
- targets, skipped, invalid = parse_targets(options)
53
-
54
- process_skipped(report, skipped)
55
- process_invalid(report, invalid)
56
-
57
- return 0 if targets.empty?
58
-
59
- return_val = 0
60
- create_spinner(targets, options)
61
-
62
- targets.each do |target|
63
- task_name = File.basename(target, File.extname(target))
64
- if PDK::CLI::Util::OptionValidator.valid_task_name?(task_name)
65
- report.add_event(
66
- file: target,
67
- source: name,
68
- state: :passed,
69
- severity: 'ok',
70
- )
71
- else
72
- report.add_event(
73
- file: target,
74
- source: name,
75
- state: :failure,
76
- severity: 'error',
77
- message: INVALID_TASK_MSG,
78
- )
79
-
80
- return_val = 1
81
- end
82
- end
83
-
84
- stop_spinner(return_val)
85
- return_val
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,29 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class TasksValidator < BaseValidator
6
- def self.name
7
- 'tasks'
8
- end
9
-
10
- def self.metadata_validators
11
- [
12
- Tasks::Name,
13
- Tasks::MetadataLint,
14
- ]
15
- end
16
-
17
- def self.invoke(report, options = {})
18
- exit_code = 0
19
-
20
- metadata_validators.each do |validator|
21
- exit_code = validator.invoke(report, options)
22
- break if exit_code != 0
23
- end
24
-
25
- exit_code
26
- end
27
- end
28
- end
29
- end
@@ -1,125 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class YAML
6
- class Syntax < BaseValidator
7
- IGNORE_DOTFILES = false
8
- YAML_WHITELISTED_CLASSES = [Symbol].freeze
9
-
10
- def self.name
11
- 'yaml-syntax'
12
- end
13
-
14
- def self.pattern
15
- [
16
- '**/*.yaml',
17
- '*.yaml',
18
- '**/*.yml',
19
- '*.yml',
20
- ]
21
- end
22
-
23
- def self.spinner_text(_targets = [])
24
- _('Checking YAML syntax (%{targets}).') % {
25
- targets: pattern,
26
- }
27
- end
28
-
29
- def self.create_spinner(targets = [], options = {})
30
- require 'pdk/cli/util'
31
-
32
- return unless PDK::CLI::Util.interactive?
33
- options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
34
-
35
- exec_group = options[:exec_group]
36
- @spinner = if exec_group
37
- exec_group.add_spinner(spinner_text(targets), options)
38
- else
39
- require 'pdk/cli/util/spinner'
40
-
41
- TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
42
- end
43
- @spinner.auto_spin
44
- end
45
-
46
- def self.stop_spinner(exit_code)
47
- if exit_code.zero? && @spinner
48
- @spinner.success
49
- elsif @spinner
50
- @spinner.error
51
- end
52
- end
53
-
54
- def self.invoke(report, options = {})
55
- targets, skipped, invalid = parse_targets(options)
56
-
57
- process_skipped(report, skipped)
58
- process_invalid(report, invalid)
59
-
60
- return 0 if targets.empty?
61
-
62
- return_val = 0
63
- create_spinner(targets, options)
64
-
65
- PDK.logger.debug(_('Validating yaml content of %{parsed_targets}') % { parsed_targets: targets.to_s })
66
-
67
- targets.each do |target|
68
- next unless PDK::Util::Filesystem.file?(target)
69
-
70
- unless PDK::Util::Filesystem.readable?(target)
71
- report.add_event(
72
- file: target,
73
- source: name,
74
- state: :failure,
75
- severity: 'error',
76
- message: _('Could not be read.'),
77
- )
78
- return_val = 1
79
- next
80
- end
81
-
82
- begin
83
- ::YAML.safe_load(PDK::Util::Filesystem.read_file(target), YAML_WHITELISTED_CLASSES, [], true)
84
-
85
- report.add_event(
86
- file: target,
87
- source: name,
88
- state: :passed,
89
- severity: 'ok',
90
- )
91
- rescue Psych::SyntaxError => e
92
- report.add_event(
93
- file: target,
94
- source: name,
95
- state: :failure,
96
- severity: 'error',
97
- line: e.line,
98
- column: e.column,
99
- message: _('%{problem} %{context}') % {
100
- problem: e.problem,
101
- context: e.context,
102
- },
103
- )
104
- return_val = 1
105
- rescue Psych::DisallowedClass => e
106
- report.add_event(
107
- file: target,
108
- source: name,
109
- state: :failure,
110
- severity: 'error',
111
- message: _('Unsupported class: %{message}') % {
112
- message: e.message,
113
- },
114
- )
115
- return_val = 1
116
- end
117
- end
118
-
119
- stop_spinner(return_val)
120
- return_val
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,28 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class YAMLValidator < BaseValidator
6
- def self.name
7
- 'yaml'
8
- end
9
-
10
- def self.validators
11
- [
12
- PDK::Validate::YAML::Syntax,
13
- ]
14
- end
15
-
16
- def self.invoke(report, options = {})
17
- exit_code = 0
18
-
19
- validators.each do |validator|
20
- exit_code = validator.invoke(report, options)
21
- break if exit_code != 0
22
- end
23
-
24
- exit_code
25
- end
26
- end
27
- end
28
- end