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
@@ -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 File.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, File.read(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 File.file?(target)
69
-
70
- unless File.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(File.read(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