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 MetadataValidator < BaseValidator
6
- def self.name
7
- 'metadata'
8
- end
9
-
10
- def self.metadata_validators
11
- [MetadataSyntax, MetadataJSONLint]
12
- end
13
-
14
- def self.invoke(report, options = {})
15
- exit_code = 0
16
-
17
- metadata_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,137 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class PuppetEPP < BaseValidator
6
- # In Puppet >= 5.3.4, the error context formatting was changed to facilitate localization
7
- ERROR_CONTEXT = %r{(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))}
8
- # In Puppet < 5.3.3, the error context was formatted in these variations:
9
- # - "at file_path:line_num:col_num"
10
- # - "at file_path:line_num"
11
- # - "at line line_num"
12
- # - "in file_path"
13
- ERROR_CONTEXT_LEGACY = %r{(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))}
14
-
15
- PUPPET_LOGGER_PREFIX = %r{^(debug|info|notice|warning|error|alert|critical):\s.+?$}i
16
- PUPPET_SYNTAX_PATTERN = %r{^
17
- (?<severity>.+?):\s
18
- (?<message>.+?)
19
- (?:
20
- \s\(#{ERROR_CONTEXT}(,\s#{ERROR_CONTEXT})*\)| # attempt to match the new localisation friendly location
21
- \s#{ERROR_CONTEXT_LEGACY}| # attempt to match the old " at file:line:column" location
22
- $ # handle cases where the output has no location
23
- )
24
- $}x
25
-
26
- def self.name
27
- 'puppet-epp'
28
- end
29
-
30
- def self.cmd
31
- 'puppet'
32
- end
33
-
34
- def self.pattern
35
- '**/*.epp'
36
- end
37
-
38
- def self.pattern_ignore
39
- ''
40
- end
41
-
42
- def self.spinner_text(_targets = nil)
43
- _('Checking Puppet EPP syntax (%{pattern}).') % { pattern: pattern }
44
- end
45
-
46
- def self.parse_options(_options, targets)
47
- # Due to PDK-1266 we need to run `puppet parser validate` with an empty
48
- # modulepath. On *nix, Ruby treats `/dev/null` as an empty directory
49
- # however it doesn't do so with `NUL` on Windows. The workaround for
50
- # this to ensure consistent behaviour is to create an empty temporary
51
- # directory and use that as the modulepath.
52
- ['epp', 'validate', '--config', null_file, '--modulepath', validate_tmpdir].concat(targets)
53
- end
54
-
55
- def self.invoke(report, options)
56
- super
57
- ensure
58
- remove_validate_tmpdir
59
- end
60
-
61
- def self.validate_tmpdir
62
- require 'tmpdir'
63
-
64
- @validate_tmpdir ||= Dir.mktmpdir('puppet-epp-validate')
65
- end
66
-
67
- def self.remove_validate_tmpdir
68
- return unless @validate_tmpdir
69
- return unless File.directory?(@validate_tmpdir)
70
-
71
- require 'fileutils'
72
-
73
- FileUtils.remove_entry_secure(@validate_tmpdir)
74
- @validate_tmpdir = nil
75
- end
76
-
77
- def self.null_file
78
- Gem.win_platform? ? 'NUL' : '/dev/null'
79
- end
80
-
81
- def self.parse_output(report, result, targets)
82
- # Due to PUP-7504, we will have to programmatically construct the json
83
- # object from the text output for now.
84
- output = result[:stderr].split(%r{\r?\n}).reject { |entry| entry.empty? }
85
-
86
- results_data = []
87
- output.each do |offense|
88
- offense_data = parse_offense(offense)
89
- results_data << offense_data
90
- end
91
-
92
- # puppet parser validate does not include files without problems in its
93
- # output, so we need to go through the list of targets and add passing
94
- # events to the report for any target not listed in the output.
95
- targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
96
- report.add_event(
97
- file: target,
98
- source: name,
99
- severity: :ok,
100
- state: :passed,
101
- )
102
- end
103
-
104
- results_data.each do |offense|
105
- report.add_event(offense)
106
- end
107
- end
108
-
109
- def self.parse_offense(offense)
110
- sanitize_console_output(offense)
111
-
112
- offense_data = {
113
- source: name,
114
- state: :failure,
115
- }
116
-
117
- if offense.match(PUPPET_LOGGER_PREFIX)
118
- attributes = offense.match(PUPPET_SYNTAX_PATTERN)
119
-
120
- unless attributes.nil?
121
- attributes.names.each do |name|
122
- offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
123
- end
124
- end
125
- else
126
- offense_data[:message] = offense
127
- end
128
-
129
- offense_data
130
- end
131
-
132
- def self.sanitize_console_output(line)
133
- line.gsub!(%r{\e\[([;\d]+)?m}, '')
134
- end
135
- end
136
- end
137
- end
@@ -1,64 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class PuppetLint < BaseValidator
6
- def self.name
7
- 'puppet-lint'
8
- end
9
-
10
- def self.cmd
11
- 'puppet-lint'
12
- end
13
-
14
- def self.pattern
15
- '**/*.pp'
16
- end
17
-
18
- def self.spinner_text(_targets = nil)
19
- _('Checking Puppet manifest style (%{pattern}).') % { pattern: pattern }
20
- end
21
-
22
- def self.parse_options(options, targets)
23
- cmd_options = ['--json', '--relative']
24
-
25
- cmd_options << '--fix' if options[:auto_correct]
26
-
27
- cmd_options.concat(targets)
28
- end
29
-
30
- def self.parse_output(report, result, targets)
31
- begin
32
- json_data = JSON.parse(result[:stdout]).flatten
33
- rescue JSON::ParserError
34
- raise PDK::Validate::ParseOutputError, result[:stdout]
35
- end
36
-
37
- # puppet-lint does not include files without problems in its JSON
38
- # output, so we need to go through the list of targets and add passing
39
- # events to the report for any target not listed in the JSON output.
40
- targets.reject { |target| json_data.any? { |j| j['path'] == target } }.each do |target|
41
- report.add_event(
42
- file: target,
43
- source: name,
44
- severity: 'ok',
45
- state: :passed,
46
- )
47
- end
48
-
49
- json_data.each do |offense|
50
- report.add_event(
51
- file: offense['path'],
52
- source: name,
53
- line: offense['line'],
54
- column: offense['column'],
55
- message: offense['message'],
56
- test: offense['check'],
57
- severity: (offense['kind'] == 'fixed') ? 'corrected' : offense['kind'],
58
- state: :failure,
59
- )
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,137 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class PuppetSyntax < BaseValidator
6
- # In Puppet >= 5.3.4, the error context formatting was changed to facilitate localization
7
- ERROR_CONTEXT = %r{(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))}
8
- # In Puppet < 5.3.3, the error context was formatted in these variations:
9
- # - "at file_path:line_num:col_num"
10
- # - "at file_path:line_num"
11
- # - "at line line_num"
12
- # - "in file_path"
13
- ERROR_CONTEXT_LEGACY = %r{(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))}
14
-
15
- PUPPET_LOGGER_PREFIX = %r{^(debug|info|notice|warning|error|alert|critical):\s.+?$}i
16
- PUPPET_SYNTAX_PATTERN = %r{^
17
- (?<severity>.+?):\s
18
- (?<message>.+?)
19
- (?:
20
- \s\(#{ERROR_CONTEXT}(,\s#{ERROR_CONTEXT})*\)| # attempt to match the new localisation friendly location
21
- \s#{ERROR_CONTEXT_LEGACY}| # attempt to match the old " at file:line:column" location
22
- $ # handle cases where the output has no location
23
- )
24
- $}x
25
-
26
- def self.name
27
- 'puppet-syntax'
28
- end
29
-
30
- def self.cmd
31
- 'puppet'
32
- end
33
-
34
- def self.pattern
35
- '**/*.pp'
36
- end
37
-
38
- def self.pattern_ignore
39
- '/plans/**/*.pp'
40
- end
41
-
42
- def self.spinner_text(_targets = nil)
43
- _('Checking Puppet manifest syntax (%{pattern}).') % { pattern: pattern }
44
- end
45
-
46
- def self.parse_options(_options, targets)
47
- # Due to PDK-1266 we need to run `puppet parser validate` with an empty
48
- # modulepath. On *nix, Ruby treats `/dev/null` as an empty directory
49
- # however it doesn't do so with `NUL` on Windows. The workaround for
50
- # this to ensure consistent behaviour is to create an empty temporary
51
- # directory and use that as the modulepath.
52
- ['parser', 'validate', '--config', null_file, '--modulepath', validate_tmpdir].concat(targets)
53
- end
54
-
55
- def self.invoke(report, options)
56
- super
57
- ensure
58
- remove_validate_tmpdir
59
- end
60
-
61
- def self.validate_tmpdir
62
- require 'tmpdir'
63
-
64
- @validate_tmpdir ||= Dir.mktmpdir('puppet-parser-validate')
65
- end
66
-
67
- def self.remove_validate_tmpdir
68
- return unless @validate_tmpdir
69
- return unless File.directory?(@validate_tmpdir)
70
-
71
- require 'fileutils'
72
-
73
- FileUtils.remove_entry_secure(@validate_tmpdir)
74
- @validate_tmpdir = nil
75
- end
76
-
77
- def self.null_file
78
- Gem.win_platform? ? 'NUL' : '/dev/null'
79
- end
80
-
81
- def self.parse_output(report, result, targets)
82
- # Due to PUP-7504, we will have to programmatically construct the json
83
- # object from the text output for now.
84
- output = result[:stderr].split(%r{\r?\n}).reject { |entry| entry.empty? }
85
-
86
- results_data = []
87
- output.each do |offense|
88
- offense_data = parse_offense(offense)
89
- results_data << offense_data
90
- end
91
-
92
- # puppet parser validate does not include files without problems in its
93
- # output, so we need to go through the list of targets and add passing
94
- # events to the report for any target not listed in the output.
95
- targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
96
- report.add_event(
97
- file: target,
98
- source: name,
99
- severity: :ok,
100
- state: :passed,
101
- )
102
- end
103
-
104
- results_data.each do |offense|
105
- report.add_event(offense)
106
- end
107
- end
108
-
109
- def self.parse_offense(offense)
110
- sanitize_console_output(offense)
111
-
112
- offense_data = {
113
- source: name,
114
- state: :failure,
115
- }
116
-
117
- if offense.match(PUPPET_LOGGER_PREFIX)
118
- attributes = offense.match(PUPPET_SYNTAX_PATTERN)
119
-
120
- unless attributes.nil?
121
- attributes.names.each do |name|
122
- offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
123
- end
124
- end
125
- else
126
- offense_data[:message] = offense
127
- end
128
-
129
- offense_data
130
- end
131
-
132
- def self.sanitize_console_output(line)
133
- line.gsub!(%r{\e\[([;\d]+)?m}, '')
134
- end
135
- end
136
- end
137
- end
@@ -1,26 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class PuppetValidator < BaseValidator
6
- def self.name
7
- 'puppet'
8
- end
9
-
10
- def self.puppet_validators
11
- [PuppetSyntax, PuppetLint, PuppetEPP]
12
- end
13
-
14
- def self.invoke(report, options = {})
15
- exit_code = 0
16
-
17
- puppet_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,72 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class Rubocop < BaseValidator
6
- ALLOW_EMPTY_TARGETS = true
7
-
8
- def self.name
9
- 'rubocop'
10
- end
11
-
12
- def self.cmd
13
- 'rubocop'
14
- end
15
-
16
- def self.pattern
17
- '**/**.rb'
18
- end
19
-
20
- def self.spinner_text(_targets = nil)
21
- _('Checking Ruby code style (%{pattern}).') % { pattern: pattern }
22
- end
23
-
24
- def self.parse_options(options, targets)
25
- cmd_options = ['--format', 'json']
26
-
27
- if options[:auto_correct]
28
- cmd_options << '--auto-correct'
29
- end
30
-
31
- cmd_options.concat(targets)
32
- end
33
-
34
- def self.parse_output(report, result, _targets)
35
- return if result[:stdout].empty?
36
-
37
- begin
38
- json_data = JSON.parse(result[:stdout])
39
- rescue JSON::ParserError
40
- raise PDK::Validate::ParseOutputError, result[:stdout]
41
- end
42
-
43
- return unless json_data.key?('files')
44
-
45
- json_data['files'].each do |file_info|
46
- next unless file_info.key?('offenses')
47
- result = {
48
- file: file_info['path'],
49
- source: 'rubocop',
50
- }
51
-
52
- if file_info['offenses'].empty?
53
- report.add_event(result.merge(state: :passed, severity: :ok))
54
- else
55
- file_info['offenses'].each do |offense|
56
- report.add_event(
57
- result.merge(
58
- line: offense['location']['line'],
59
- column: offense['location']['column'],
60
- message: offense['message'],
61
- severity: offense['corrected'] ? 'corrected' : offense['severity'],
62
- test: offense['cop_name'],
63
- state: :failure,
64
- ),
65
- )
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end