pdk 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -240,6 +240,7 @@ files:
240
240
  - lib/pdk/generate/task.rb
241
241
  - lib/pdk/i18n.rb
242
242
  - lib/pdk/logger.rb
243
+ - lib/pdk/module.rb
243
244
  - lib/pdk/module/build.rb
244
245
  - lib/pdk/module/convert.rb
245
246
  - lib/pdk/module/metadata.rb
@@ -252,6 +253,7 @@ files:
252
253
  - lib/pdk/tests/unit.rb
253
254
  - lib/pdk/util.rb
254
255
  - lib/pdk/util/bundler.rb
256
+ - lib/pdk/util/filesystem.rb
255
257
  - lib/pdk/util/git.rb
256
258
  - lib/pdk/util/puppet_version.rb
257
259
  - lib/pdk/util/ruby_version.rb
@@ -265,13 +267,15 @@ files:
265
267
  - lib/pdk/validate/base_validator.rb
266
268
  - lib/pdk/validate/metadata/metadata_json_lint.rb
267
269
  - lib/pdk/validate/metadata/metadata_syntax.rb
268
- - lib/pdk/validate/metadata/task_metadata_lint.rb
269
270
  - lib/pdk/validate/metadata_validator.rb
270
271
  - lib/pdk/validate/puppet/puppet_lint.rb
271
272
  - lib/pdk/validate/puppet/puppet_syntax.rb
272
273
  - lib/pdk/validate/puppet_validator.rb
273
274
  - lib/pdk/validate/ruby/rubocop.rb
274
275
  - lib/pdk/validate/ruby_validator.rb
276
+ - lib/pdk/validate/tasks/metadata_lint.rb
277
+ - lib/pdk/validate/tasks/name.rb
278
+ - lib/pdk/validate/tasks_validator.rb
275
279
  - lib/pdk/version.rb
276
280
  - locales/config.yaml
277
281
  - locales/pdk.pot
@@ -1,124 +0,0 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
- require 'pdk/validate/base_validator'
4
- require 'pdk/util'
5
- require 'pathname'
6
- require 'json-schema'
7
-
8
- module PDK
9
- module Validate
10
- class TaskMetadataLint < BaseValidator
11
- FORGE_SCHEMA_URL = 'https://forgeapi.puppet.com/schemas/task.json'.freeze
12
-
13
- def self.name
14
- 'task-metadata-lint'
15
- end
16
-
17
- def self.pattern
18
- 'tasks/*.json'
19
- end
20
-
21
- def self.spinner_text(_targets = [])
22
- _('Checking task metadata style (%{targets}).') % {
23
- targets: pattern,
24
- }
25
- end
26
-
27
- def self.create_spinner(targets = [], options = {})
28
- return unless PDK::CLI::Util.interactive?
29
- options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
30
-
31
- exec_group = options[:exec_group]
32
- @spinner = if exec_group
33
- exec_group.add_spinner(spinner_text(targets), options)
34
- else
35
- TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
36
- end
37
- @spinner.auto_spin
38
- end
39
-
40
- def self.stop_spinner(exit_code)
41
- if exit_code.zero? && @spinner
42
- @spinner.success
43
- elsif @spinner
44
- @spinner.error
45
- end
46
- end
47
-
48
- def self.schema_file
49
- schema = PDK::Util::VendoredFile.new('task.json', FORGE_SCHEMA_URL).read
50
-
51
- JSON.parse(schema)
52
- rescue PDK::Util::VendoredFile::DownloadError => e
53
- raise PDK::CLI::FatalError, e.message
54
- rescue JSON::ParserError
55
- raise PDK::CLI::FatalError, _('Failed to parse Task Metadata Schema file.')
56
- end
57
-
58
- def self.invoke(report, options = {})
59
- targets, skipped, invalid = parse_targets(options)
60
-
61
- process_skipped(report, skipped)
62
- process_invalid(report, invalid)
63
-
64
- return 0 if targets.empty?
65
-
66
- return_val = 0
67
- create_spinner(targets, options)
68
-
69
- targets.each do |target|
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
- # Need to set the JSON Parser and State Generator to the Native one to be
84
- # compatible with the multi_json adapter.
85
- JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
86
- JSON.generator = JSON::Ext::Generator
87
-
88
- begin
89
- errors = JSON::Validator.fully_validate(schema_file, File.read(target)) || []
90
- rescue JSON::Schema::SchemaError => e
91
- raise PDK::CLI::FatalError, _('Unable to validate Task Metadata. %{error}.') % { error: e.message }
92
- end
93
-
94
- if errors.empty?
95
- report.add_event(
96
- file: target,
97
- source: name,
98
- state: :passed,
99
- severity: 'ok',
100
- )
101
- else
102
- errors.each do |error|
103
- # strip off the trailing parts that aren't relevant
104
- error = error.split('in schema').first if error.include? 'in schema'
105
-
106
- report.add_event(
107
- file: target,
108
- source: name,
109
- state: :failure,
110
- severity: 'error',
111
- message: error,
112
- )
113
- end
114
- return_val = 1
115
- end
116
- end
117
- end
118
-
119
- stop_spinner(return_val)
120
- return_val
121
- end
122
- end
123
- end
124
- end