pdk 1.16.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +167 -11
  3. data/README.md +1 -1
  4. data/lib/pdk.rb +26 -19
  5. data/lib/pdk/answer_file.rb +2 -93
  6. data/lib/pdk/cli.rb +8 -6
  7. data/lib/pdk/cli/config.rb +3 -1
  8. data/lib/pdk/cli/config/get.rb +3 -1
  9. data/lib/pdk/cli/convert.rb +7 -9
  10. data/lib/pdk/cli/env.rb +52 -0
  11. data/lib/pdk/cli/exec/command.rb +13 -0
  12. data/lib/pdk/cli/exec_group.rb +78 -43
  13. data/lib/pdk/cli/get.rb +20 -0
  14. data/lib/pdk/cli/get/config.rb +24 -0
  15. data/lib/pdk/cli/new.rb +2 -0
  16. data/lib/pdk/cli/new/class.rb +2 -1
  17. data/lib/pdk/cli/new/defined_type.rb +2 -1
  18. data/lib/pdk/cli/new/fact.rb +29 -0
  19. data/lib/pdk/cli/new/function.rb +29 -0
  20. data/lib/pdk/cli/new/provider.rb +2 -1
  21. data/lib/pdk/cli/new/task.rb +2 -1
  22. data/lib/pdk/cli/new/test.rb +2 -1
  23. data/lib/pdk/cli/new/transport.rb +2 -1
  24. data/lib/pdk/cli/release/publish.rb +11 -1
  25. data/lib/pdk/cli/remove.rb +20 -0
  26. data/lib/pdk/cli/remove/config.rb +80 -0
  27. data/lib/pdk/cli/set.rb +20 -0
  28. data/lib/pdk/cli/set/config.rb +119 -0
  29. data/lib/pdk/cli/update.rb +6 -8
  30. data/lib/pdk/cli/util.rb +7 -3
  31. data/lib/pdk/cli/util/option_validator.rb +6 -0
  32. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  33. data/lib/pdk/cli/validate.rb +26 -44
  34. data/lib/pdk/config.rb +264 -7
  35. data/lib/pdk/config/ini_file.rb +183 -0
  36. data/lib/pdk/config/ini_file_setting.rb +39 -0
  37. data/lib/pdk/config/namespace.rb +25 -5
  38. data/lib/pdk/config/setting.rb +3 -2
  39. data/lib/pdk/context.rb +99 -0
  40. data/lib/pdk/context/control_repo.rb +60 -0
  41. data/lib/pdk/context/module.rb +28 -0
  42. data/lib/pdk/context/none.rb +22 -0
  43. data/lib/pdk/control_repo.rb +40 -0
  44. data/lib/pdk/generate/defined_type.rb +25 -32
  45. data/lib/pdk/generate/fact.rb +25 -0
  46. data/lib/pdk/generate/function.rb +48 -0
  47. data/lib/pdk/generate/module.rb +14 -17
  48. data/lib/pdk/generate/provider.rb +15 -64
  49. data/lib/pdk/generate/puppet_class.rb +25 -31
  50. data/lib/pdk/generate/puppet_object.rb +83 -187
  51. data/lib/pdk/generate/task.rb +28 -46
  52. data/lib/pdk/generate/transport.rb +20 -74
  53. data/lib/pdk/module.rb +1 -1
  54. data/lib/pdk/module/convert.rb +43 -23
  55. data/lib/pdk/module/metadata.rb +6 -2
  56. data/lib/pdk/module/release.rb +3 -9
  57. data/lib/pdk/module/update.rb +7 -11
  58. data/lib/pdk/module/update_manager.rb +7 -0
  59. data/lib/pdk/report.rb +3 -3
  60. data/lib/pdk/report/event.rb +8 -2
  61. data/lib/pdk/template.rb +59 -0
  62. data/lib/pdk/template/fetcher.rb +98 -0
  63. data/lib/pdk/template/fetcher/git.rb +85 -0
  64. data/lib/pdk/template/fetcher/local.rb +28 -0
  65. data/lib/pdk/template/renderer.rb +96 -0
  66. data/lib/pdk/template/renderer/v1.rb +25 -0
  67. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
  68. data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
  69. data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
  70. data/lib/pdk/template/template_dir.rb +67 -0
  71. data/lib/pdk/tests/unit.rb +8 -1
  72. data/lib/pdk/util.rb +38 -39
  73. data/lib/pdk/util/bundler.rb +2 -1
  74. data/lib/pdk/util/changelog_generator.rb +11 -2
  75. data/lib/pdk/util/json_finder.rb +84 -0
  76. data/lib/pdk/util/puppet_strings.rb +3 -3
  77. data/lib/pdk/util/puppet_version.rb +2 -2
  78. data/lib/pdk/util/ruby_version.rb +5 -1
  79. data/lib/pdk/util/template_uri.rb +13 -14
  80. data/lib/pdk/util/vendored_file.rb +1 -2
  81. data/lib/pdk/validate.rb +79 -25
  82. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  83. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  84. data/lib/pdk/validate/external_command_validator.rb +208 -0
  85. data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
  86. data/lib/pdk/validate/invokable_validator.rb +220 -0
  87. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
  88. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
  89. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  90. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
  91. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  92. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
  93. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
  94. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
  95. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  96. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
  97. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
  98. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  99. data/lib/pdk/validate/validator.rb +118 -0
  100. data/lib/pdk/validate/validator_group.rb +104 -0
  101. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
  102. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  103. data/lib/pdk/version.rb +1 -1
  104. data/locales/pdk.pot +477 -313
  105. metadata +77 -35
  106. data/lib/pdk/module/template_dir.rb +0 -115
  107. data/lib/pdk/module/template_dir/base.rb +0 -268
  108. data/lib/pdk/module/template_dir/git.rb +0 -91
  109. data/lib/pdk/module/template_dir/local.rb +0 -21
  110. data/lib/pdk/template_file.rb +0 -96
  111. data/lib/pdk/validate/base_validator.rb +0 -215
  112. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
  113. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
  114. data/lib/pdk/validate/metadata_validator.rb +0 -26
  115. data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
  116. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
  117. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
  118. data/lib/pdk/validate/puppet_validator.rb +0 -26
  119. data/lib/pdk/validate/ruby/rubocop.rb +0 -72
  120. data/lib/pdk/validate/ruby_validator.rb +0 -26
  121. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
  122. data/lib/pdk/validate/tasks/name.rb +0 -90
  123. data/lib/pdk/validate/tasks_validator.rb +0 -29
  124. data/lib/pdk/validate/yaml/syntax.rb +0 -125
  125. data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -1,91 +0,0 @@
1
- require 'pdk'
2
- require 'pdk/module/template_dir/base'
3
-
4
- module PDK
5
- module Module
6
- module TemplateDir
7
- class Git < Base
8
- def template_path(uri)
9
- # We don't do a checkout of local-path repos. There are lots of edge
10
- # cases or user un-expectations.
11
- if PDK::Util::Git.work_tree?(uri.shell_path)
12
- PDK.logger.warn _("Repository '%{repo}' has a work-tree; skipping git reset.") % {
13
- repo: uri.shell_path,
14
- }
15
- [uri.shell_path, false]
16
- else
17
- # This is either a bare local repo or a remote. either way it needs cloning.
18
- # A "remote" can also be git repo on the local filsystem.
19
- [clone_template_repo(uri), true]
20
- end
21
- end
22
-
23
- # For git repositories, this will return the URL to the repository and
24
- # a reference to the HEAD.
25
- #
26
- # @return [Hash{String => String}] A hash of identifying metadata.
27
- def metadata
28
- super.merge('template-url' => uri.metadata_format, 'template-ref' => cache_template_ref(@path))
29
- end
30
-
31
- private
32
-
33
- def cache_template_ref(path, ref = nil)
34
- require 'pdk/util/git'
35
-
36
- @template_ref ||= PDK::Util::Git.describe(File.join(path, '.git'), ref)
37
- end
38
-
39
- # @return [String] Path to working directory into which template repo has been cloned and reset
40
- #
41
- # @raise [PDK::CLI::FatalError] If unable to clone the given origin_repo into a tempdir.
42
- # @raise [PDK::CLI::FatalError] If reset HEAD of the cloned repo to desired ref.
43
- #
44
- # @api private
45
- def clone_template_repo(uri)
46
- # @todo When switching this over to using rugged, cache the cloned
47
- # template repo in `%AppData%` or `$XDG_CACHE_DIR` and update before
48
- # use.
49
- require 'pdk/util'
50
- require 'pdk/util/git'
51
-
52
- temp_dir = PDK::Util.make_tmpdir_name('pdk-templates')
53
- origin_repo = uri.bare_uri
54
- git_ref = uri.uri_fragment
55
-
56
- clone_result = PDK::Util::Git.git('clone', origin_repo, temp_dir)
57
-
58
- if clone_result[:exit_code].zero?
59
- checkout_template_ref(temp_dir, git_ref)
60
- else
61
- PDK.logger.error clone_result[:stdout]
62
- PDK.logger.error clone_result[:stderr]
63
- raise PDK::CLI::FatalError, _("Unable to clone git repository at '%{repo}' into '%{dest}'.") % { repo: origin_repo, dest: temp_dir }
64
- end
65
-
66
- PDK::Util.canonical_path(temp_dir)
67
- end
68
-
69
- # @api private
70
- def checkout_template_ref(path, ref)
71
- require 'pdk/util/git'
72
-
73
- if PDK::Util::Git.work_dir_clean?(path)
74
- Dir.chdir(path) do
75
- full_ref = PDK::Util::Git.ls_remote(path, ref)
76
- cache_template_ref(path, full_ref)
77
- reset_result = PDK::Util::Git.git('reset', '--hard', full_ref)
78
- return if reset_result[:exit_code].zero?
79
-
80
- PDK.logger.error reset_result[:stdout]
81
- PDK.logger.error reset_result[:stderr]
82
- raise PDK::CLI::FatalError, _("Unable to checkout '%{ref}' of git repository at '%{path}'.") % { ref: ref, path: path }
83
- end
84
- else
85
- PDK.logger.warn _("Uncommitted changes found when attempting to checkout '%{ref}' of git repository at '%{path}'; skipping git reset.") % { ref: ref, path: path }
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,21 +0,0 @@
1
- require 'pdk'
2
- require 'pdk/module/template_dir/base'
3
-
4
- module PDK
5
- module Module
6
- module TemplateDir
7
- class Local < Base
8
- def template_path(uri)
9
- [uri.shell_path, false]
10
- end
11
-
12
- # For plain fileystem directories, this will return the URL to the repository only.
13
- #
14
- # @return [Hash{String => String}] A hash of identifying metadata.
15
- def metadata
16
- super.merge('template-url' => uri.bare_uri)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,96 +0,0 @@
1
- require 'ostruct'
2
- require 'pdk'
3
-
4
- module PDK
5
- class TemplateFile < OpenStruct
6
- # Initialises the TemplateFile object with the path to the template file
7
- # and the data to be used when rendering the template.
8
- #
9
- # @param template_file [String] The path on disk to the template file.
10
- # @param data [Hash{Symbol => Object}] The data that should be provided to
11
- # the template when rendering.
12
- # @option data [Object] :configs The value of this key will be provided to
13
- # the template as an instance variable `@configs` in order to maintain
14
- # compatibility with modulesync.
15
- #
16
- # @api public
17
- def initialize(template_file, data = {})
18
- @template_file = template_file
19
-
20
- if data.key?(:configs)
21
- @configs = data[:configs]
22
- end
23
-
24
- super(data)
25
- end
26
-
27
- # Renders the template by calling the appropriate engine based on the file
28
- # extension.
29
- #
30
- # If the template has an `.erb` extension, the content of the template
31
- # file will be treated as an ERB template. All other extensions are treated
32
- # as plain text.
33
- #
34
- # @return [String] The rendered template
35
- #
36
- # @raise (see #template_content)
37
- #
38
- # @api public
39
- def render
40
- case File.extname(@template_file)
41
- when '.erb'
42
- render_erb
43
- else
44
- render_plain
45
- end
46
- end
47
-
48
- def config_for(path)
49
- return unless respond_to?(:template_dir)
50
-
51
- template_dir.config_for(path)
52
- end
53
-
54
- private
55
-
56
- # Reads the content of the template file into memory.
57
- #
58
- # @return [String] The content of the template file.
59
- #
60
- # @raise [ArgumentError] If the template file does not exist or can not be
61
- # read.
62
- #
63
- # @api private
64
- def template_content
65
- if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
66
- return PDK::Util::Filesystem.read_file(@template_file)
67
- end
68
-
69
- raise ArgumentError, _("'%{template}' is not a readable file") % { template: @template_file }
70
- end
71
-
72
- # Renders the content of the template file as an ERB template.
73
- #
74
- # @return [String] The rendered template.
75
- #
76
- # @raise (see #template_content)
77
- #
78
- # @api private
79
- def render_erb
80
- renderer = ERB.new(template_content, nil, '-')
81
- renderer.filename = @template_file
82
- renderer.result(binding)
83
- end
84
-
85
- # Renders the content of the template file as plain text.
86
- #
87
- # @return [String] The rendered template.
88
- #
89
- # @raise (see #template_content)
90
- #
91
- # @api private
92
- def render_plain
93
- template_content
94
- end
95
- end
96
- end
@@ -1,215 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class BaseValidator
6
- # Controls how many times the validator is invoked.
7
- #
8
- # :once - The validator will be invoked once and passed all the
9
- # targets.
10
- # :per_target - The validator will be invoked for each target
11
- # separately.
12
- INVOKE_STYLE = :once
13
-
14
- # Controls how the validator behaves if not passed any targets.
15
- #
16
- # true - PDK will not pass the globbed targets to the validator command
17
- # and it will instead rely on the underlying tool to find its
18
- # own default targets.
19
- # false - PDK will pass the globbed targets to the validator command.
20
- ALLOW_EMPTY_TARGETS = false
21
-
22
- IGNORE_DOTFILES = true
23
-
24
- def self.cmd_path
25
- File.join(PDK::Util.module_root, 'bin', cmd)
26
- end
27
-
28
- # Parses the target strings provided from the CLI
29
- #
30
- # @param options [Hash] A Hash containing the input options from the CLI.
31
- #
32
- # @return targets [Array] An Array of Strings containing target file paths
33
- # for the validator to validate.
34
- # @return skipped [Array] An Array of Strings containing targets
35
- # that are skipped due to target not containing
36
- # any files that can be validated by the validator.
37
- # @return invalid [Array] An Array of Strings containing targets that do
38
- # not exist, and will not be run by validator.
39
- def self.parse_targets(options)
40
- # If no targets are specified, then we will run validations from the
41
- # base module directory.
42
-
43
- targets = options.fetch(:targets, []).empty? ? [PDK::Util.module_root] : options[:targets]
44
-
45
- targets.map! { |r| r.gsub(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
46
- skipped = []
47
- invalid = []
48
- matched = targets.map { |target|
49
- if respond_to?(:pattern)
50
- if PDK::Util::Filesystem.directory?(target)
51
- target_root = PDK::Util.module_root
52
- pattern_glob = Array(pattern).map { |p| PDK::Util::Filesystem.glob(File.join(target_root, p), File::FNM_DOTMATCH) }
53
- target_list = pattern_glob.flatten
54
- .select { |glob| PDK::Util::Filesystem.fnmatch(File.join(PDK::Util::Filesystem.expand_path(PDK::Util.canonical_path(target)), '*'), glob, File::FNM_DOTMATCH) }
55
- .map { |glob| Pathname.new(glob).relative_path_from(Pathname.new(PDK::Util.module_root)).to_s }
56
-
57
- ignore_list = ignore_pathspec
58
- target_list = target_list.reject { |file| ignore_list.match(file) }
59
-
60
- skipped << target if target_list.flatten.empty?
61
- target_list
62
- elsif PDK::Util::Filesystem.file?(target)
63
- if Array(pattern).include? target
64
- target
65
- elsif Array(pattern).any? { |p| PDK::Util::Filesystem.fnmatch(PDK::Util::Filesystem.expand_path(p), PDK::Util::Filesystem.expand_path(target), File::FNM_DOTMATCH) }
66
- target
67
- else
68
- skipped << target
69
- next
70
- end
71
- else
72
- invalid << target
73
- next
74
- end
75
- else
76
- target
77
- end
78
- }.compact.flatten
79
- [matched, skipped, invalid]
80
- end
81
-
82
- def self.ignore_pathspec
83
- require 'pdk/module'
84
-
85
- ignore_pathspec = PDK::Module.default_ignored_pathspec(ignore_dotfiles?)
86
-
87
- if respond_to?(:pattern_ignore)
88
- Array(pattern_ignore).each do |pattern|
89
- ignore_pathspec.add(pattern)
90
- end
91
- end
92
-
93
- ignore_pathspec
94
- end
95
-
96
- def self.ignore_dotfiles?
97
- self::IGNORE_DOTFILES
98
- end
99
-
100
- def self.parse_options(_options, targets)
101
- targets
102
- end
103
-
104
- def self.spinner_text(_targets = nil)
105
- _('Invoking %{cmd}') % { cmd: cmd }
106
- end
107
-
108
- def self.process_skipped(report, skipped = [])
109
- skipped.each do |skipped_target|
110
- PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).') % { validator: name, target: skipped_target, pattern: pattern })
111
- report.add_event(
112
- file: skipped_target,
113
- source: name,
114
- message: _('Target does not contain any files to validate (%{pattern}).') % { pattern: pattern },
115
- severity: :info,
116
- state: :skipped,
117
- )
118
- end
119
- end
120
-
121
- def self.process_invalid(report, invalid = [])
122
- invalid.each do |invalid_target|
123
- PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target file not found.') % { validator: name, target: invalid_target })
124
- report.add_event(
125
- file: invalid_target,
126
- source: name,
127
- message: _('File does not exist.'),
128
- severity: :error,
129
- state: :error,
130
- )
131
- end
132
- end
133
-
134
- def self.allow_empty_targets?
135
- self::ALLOW_EMPTY_TARGETS == true
136
- end
137
-
138
- def self.invoke(report, options = {})
139
- require 'pdk/cli/exec/command'
140
-
141
- targets, skipped, invalid = parse_targets(options)
142
-
143
- process_skipped(report, skipped)
144
- process_invalid(report, invalid)
145
-
146
- return 0 if targets.empty?
147
-
148
- PDK::Util::Bundler.ensure_binstubs!(cmd)
149
-
150
- # If invoking :per_target, split the targets array into an array of
151
- # single element arrays (one per target). If invoking :once, wrap the
152
- # targets array in another array. This is so we can loop through the
153
- # invokes with the same logic, regardless of which invoke style is
154
- # needed.
155
- #
156
- if self::INVOKE_STYLE == :per_target
157
- targets = targets.combination(1).to_a
158
- else
159
- require 'pdk/cli/exec_group'
160
- targets = targets.each_slice(1000).to_a
161
- options[:split_exec] = PDK::CLI::ExecGroup.new(spinner_text(targets), parallel: false)
162
- end
163
-
164
- if options.fetch(:targets, []).empty? && allow_empty_targets?
165
- targets = [[]]
166
- end
167
-
168
- exit_codes = []
169
-
170
- targets.each do |invokation_targets|
171
- cmd_argv = parse_options(options, invokation_targets).unshift(cmd_path).compact
172
- cmd_argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe'), '-W0') if Gem.win_platform?
173
-
174
- command = PDK::CLI::Exec::Command.new(*cmd_argv).tap do |c|
175
- c.context = :module
176
- c.environment = { 'PUPPET_GEM_VERSION' => options[:puppet] } if options[:puppet]
177
- unless options[:split_exec]
178
- exec_group = options[:exec_group]
179
- if exec_group
180
- sub_spinner = exec_group.add_spinner(spinner_text(invokation_targets))
181
- c.register_spinner(sub_spinner)
182
- else
183
- c.add_spinner(spinner_text(invokation_targets))
184
- end
185
- end
186
- end
187
-
188
- if options[:split_exec]
189
- options[:split_exec].register do
190
- result = command.execute!
191
-
192
- begin
193
- parse_output(report, result, invokation_targets.compact)
194
- rescue PDK::Validate::ParseOutputError => e
195
- $stderr.puts e.message
196
- end
197
- result[:exit_code]
198
- end
199
- else
200
- result = command.execute!
201
- exit_codes << result[:exit_code]
202
-
203
- begin
204
- parse_output(report, result, invokation_targets.compact)
205
- rescue PDK::Validate::ParseOutputError => e
206
- $stderr.puts e.message
207
- end
208
- end
209
- end
210
-
211
- options.key?(:split_exec) ? options[:split_exec].exit_code : exit_codes.max
212
- end
213
- end
214
- end
215
- end
@@ -1,82 +0,0 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- class MetadataJSONLint < BaseValidator
6
- # Validate each metadata file separately, as metadata-json-lint does not
7
- # support multiple targets.
8
- INVOKE_STYLE = :per_target
9
-
10
- def self.name
11
- 'metadata-json-lint'
12
- end
13
-
14
- def self.cmd
15
- 'metadata-json-lint'
16
- end
17
-
18
- def self.spinner_text(targets = [])
19
- _('Checking module metadata style (%{targets}).') % {
20
- targets: PDK::Util.targets_relative_to_pwd(targets).join(' '),
21
- }
22
- end
23
-
24
- def self.pattern
25
- 'metadata.json'
26
- end
27
-
28
- def self.parse_options(_options, targets)
29
- cmd_options = ['--format', 'json']
30
- cmd_options << '--strict-dependencies'
31
-
32
- cmd_options.concat(targets)
33
- end
34
-
35
- def self.parse_output(report, result, targets)
36
- raise ArgumentError, _('More than 1 target provided to PDK::Validate::MetadataJSONLint.') if targets.count > 1
37
-
38
- if result[:stdout].strip.empty?
39
- # metadata-json-lint will print nothing if there are no problems with
40
- # the file being linted. This should be handled separately to
41
- # metadata-json-lint generating output that can not be parsed as JSON
42
- # (unhandled exception in metadata-json-lint).
43
- json_data = {}
44
- else
45
- begin
46
- json_data = JSON.parse(result[:stdout])
47
- rescue JSON::ParserError
48
- raise PDK::Validate::ParseOutputError, result[:stdout]
49
- end
50
- end
51
-
52
- if json_data.empty?
53
- report.add_event(
54
- file: targets.first,
55
- source: name,
56
- state: :passed,
57
- severity: :ok,
58
- )
59
- else
60
- json_data.delete('result')
61
- json_data.keys.each do |type|
62
- json_data[type].each do |offense|
63
- # metadata-json-lint groups the offenses by type, so the type ends
64
- # up being `warnings` or `errors`. We want to convert that to the
65
- # singular noun for the event.
66
- event_type = type[%r{\A(.+?)s?\Z}, 1]
67
-
68
- report.add_event(
69
- file: targets.first,
70
- source: name,
71
- message: offense['msg'],
72
- test: offense['check'],
73
- severity: event_type,
74
- state: :failure,
75
- )
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end