pdk 2.7.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +10 -50
- data/lib/pdk/analytics/client/google_analytics.rb +22 -26
- data/lib/pdk/analytics/util.rb +0 -1
- data/lib/pdk/analytics.rb +1 -1
- data/lib/pdk/bolt.rb +1 -0
- data/lib/pdk/cli/build.rb +53 -56
- data/lib/pdk/cli/bundle.rb +34 -33
- data/lib/pdk/cli/console.rb +136 -134
- data/lib/pdk/cli/convert.rb +39 -41
- data/lib/pdk/cli/env.rb +49 -47
- data/lib/pdk/cli/errors.rb +1 -2
- data/lib/pdk/cli/exec/command.rb +23 -29
- data/lib/pdk/cli/exec/interactive_command.rb +7 -12
- data/lib/pdk/cli/exec.rb +4 -11
- data/lib/pdk/cli/exec_group.rb +3 -2
- data/lib/pdk/cli/get/config.rb +21 -19
- data/lib/pdk/cli/get.rb +15 -13
- data/lib/pdk/cli/new/class.rb +22 -22
- data/lib/pdk/cli/new/defined_type.rb +22 -22
- data/lib/pdk/cli/new/fact.rb +19 -19
- data/lib/pdk/cli/new/function.rb +20 -20
- data/lib/pdk/cli/new/module.rb +40 -38
- data/lib/pdk/cli/new/provider.rb +19 -19
- data/lib/pdk/cli/new/task.rb +23 -23
- data/lib/pdk/cli/new/test.rb +50 -48
- data/lib/pdk/cli/new/transport.rb +18 -18
- data/lib/pdk/cli/new.rb +11 -9
- data/lib/pdk/cli/release/prep.rb +27 -25
- data/lib/pdk/cli/release/publish.rb +39 -37
- data/lib/pdk/cli/release.rb +152 -149
- data/lib/pdk/cli/remove/config.rb +63 -60
- data/lib/pdk/cli/remove.rb +15 -13
- data/lib/pdk/cli/set/config.rb +91 -89
- data/lib/pdk/cli/set.rb +15 -13
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -7
- data/lib/pdk/cli/update.rb +33 -38
- data/lib/pdk/cli/util/command_redirector.rb +10 -1
- data/lib/pdk/cli/util/interview.rb +11 -4
- data/lib/pdk/cli/util/option_normalizer.rb +3 -5
- data/lib/pdk/cli/util/option_validator.rb +7 -9
- data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
- data/lib/pdk/cli/util.rb +32 -48
- data/lib/pdk/cli/validate.rb +98 -96
- data/lib/pdk/cli.rb +124 -120
- data/lib/pdk/config/ini_file.rb +4 -3
- data/lib/pdk/config/ini_file_setting.rb +6 -10
- data/lib/pdk/config/json.rb +1 -0
- data/lib/pdk/config/json_schema_namespace.rb +5 -10
- data/lib/pdk/config/json_schema_setting.rb +3 -5
- data/lib/pdk/config/json_with_schema.rb +2 -4
- data/lib/pdk/config/namespace.rb +22 -14
- data/lib/pdk/config/setting.rb +5 -6
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +4 -4
- data/lib/pdk/config/yaml.rb +3 -8
- data/lib/pdk/config/yaml_with_schema.rb +4 -12
- data/lib/pdk/config.rb +47 -51
- data/lib/pdk/context/control_repo.rb +3 -2
- data/lib/pdk/context/module.rb +2 -2
- data/lib/pdk/context/none.rb +2 -2
- data/lib/pdk/context.rb +4 -5
- data/lib/pdk/control_repo.rb +3 -4
- data/lib/pdk/generate/defined_type.rb +3 -3
- data/lib/pdk/generate/fact.rb +3 -2
- data/lib/pdk/generate/function.rb +5 -4
- data/lib/pdk/generate/module.rb +91 -106
- data/lib/pdk/generate/provider.rb +5 -4
- data/lib/pdk/generate/puppet_class.rb +3 -3
- data/lib/pdk/generate/puppet_object.rb +9 -12
- data/lib/pdk/generate/task.rb +11 -10
- data/lib/pdk/generate/transport.rb +8 -7
- data/lib/pdk/generate.rb +1 -1
- data/lib/pdk/logger.rb +3 -2
- data/lib/pdk/module/build.rb +34 -49
- data/lib/pdk/module/convert.rb +13 -22
- data/lib/pdk/module/metadata.rb +53 -61
- data/lib/pdk/module/release.rb +19 -25
- data/lib/pdk/module/update.rb +4 -13
- data/lib/pdk/module/update_manager.rb +18 -25
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +12 -37
- data/lib/pdk/report.rb +11 -7
- data/lib/pdk/template/fetcher/git.rb +7 -8
- data/lib/pdk/template/fetcher/local.rb +1 -0
- data/lib/pdk/template/fetcher.rb +4 -2
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
- data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
- data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
- data/lib/pdk/template/renderer/v1.rb +1 -1
- data/lib/pdk/template/renderer.rb +1 -0
- data/lib/pdk/template/template_dir.rb +3 -3
- data/lib/pdk/template.rb +2 -6
- data/lib/pdk/tests/unit.rb +36 -25
- data/lib/pdk/util/bundler.rb +10 -14
- data/lib/pdk/util/changelog_generator.rb +15 -12
- data/lib/pdk/util/env.rb +1 -0
- data/lib/pdk/util/filesystem.rb +18 -17
- data/lib/pdk/util/git.rb +16 -21
- data/lib/pdk/util/json_finder.rb +7 -6
- data/lib/pdk/util/puppet_strings.rb +1 -1
- data/lib/pdk/util/puppet_version.rb +21 -68
- data/lib/pdk/util/ruby_version.rb +9 -13
- data/lib/pdk/util/template_uri.rb +17 -29
- data/lib/pdk/util/vendored_file.rb +5 -18
- data/lib/pdk/util/windows/api_types.rb +70 -64
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +59 -61
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util.rb +13 -21
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
- data/lib/pdk/validate/external_command_validator.rb +6 -1
- data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
- data/lib/pdk/validate/invokable_validator.rb +30 -20
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
- data/lib/pdk/validate/validator.rb +4 -2
- data/lib/pdk/validate/validator_group.rb +6 -3
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
- data/lib/pdk/validate.rb +6 -6
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +12 -12
- metadata +27 -35
- data/lib/pdk/cli/config/get.rb +0 -26
- data/lib/pdk/cli/config.rb +0 -22
- data/lib/pdk/cli/module/build.rb +0 -12
- data/lib/pdk/cli/module/generate.rb +0 -47
- data/lib/pdk/cli/module.rb +0 -14
@@ -5,7 +5,7 @@ module PDK
|
|
5
5
|
module Util
|
6
6
|
class OptionValidator
|
7
7
|
def self.comma_separated_list?(list, _options = {})
|
8
|
-
|
8
|
+
/^[\w-]+(?:,[\w-]+)+$/.match?(list)
|
9
9
|
end
|
10
10
|
|
11
11
|
# @return [Boolean] true if the fact name is valid
|
@@ -17,9 +17,7 @@ module PDK
|
|
17
17
|
vals = val.is_a?(Array) ? val : [val]
|
18
18
|
invalid_entries = vals.reject { |e| valid_entries.include?(e) }
|
19
19
|
|
20
|
-
unless invalid_entries.empty?
|
21
|
-
raise ArgumentError, 'Error: the following values are invalid: %{invalid_entries}' % { invalid_entries: invalid_entries }
|
22
|
-
end
|
20
|
+
raise ArgumentError, format('Error: the following values are invalid: %{invalid_entries}', invalid_entries: invalid_entries) unless invalid_entries.empty?
|
23
21
|
|
24
22
|
val
|
25
23
|
end
|
@@ -27,7 +25,7 @@ module PDK
|
|
27
25
|
# Validate the module name against the regular expression in the
|
28
26
|
# documentation: https://docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names
|
29
27
|
def self.valid_module_name?(string)
|
30
|
-
!(string =~
|
28
|
+
!(string =~ /\A[a-z][a-z0-9_]*\Z/).nil?
|
31
29
|
end
|
32
30
|
singleton_class.send(:alias_method, :valid_task_name?, :valid_module_name?)
|
33
31
|
|
@@ -44,7 +42,7 @@ module PDK
|
|
44
42
|
def self.valid_namespace?(string)
|
45
43
|
return false if (string || '').split('::').last == 'init'
|
46
44
|
|
47
|
-
!(string =~
|
45
|
+
!(string =~ /\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z/).nil?
|
48
46
|
end
|
49
47
|
singleton_class.send(:alias_method, :valid_function_name?, :valid_namespace?)
|
50
48
|
|
@@ -56,11 +54,11 @@ module PDK
|
|
56
54
|
# The parameter should also not be a reserved word or overload
|
57
55
|
# a metaparameter.
|
58
56
|
def self.valid_param_name?(string)
|
59
|
-
reserved_words =
|
60
|
-
metaparams =
|
57
|
+
reserved_words = ['trusted', 'facts', 'server_facts', 'title', 'name'].freeze
|
58
|
+
metaparams = ['alias', 'audit', 'before', 'loglevel', 'noop', 'notify', 'require', 'schedule', 'stage', 'subscribe', 'tag'].freeze
|
61
59
|
return false if reserved_words.include?(string) || metaparams.include?(string)
|
62
60
|
|
63
|
-
!(string =~
|
61
|
+
!(string =~ /\A[a-z][a-zA-Z0-9_]*\Z/).nil?
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
@@ -14,7 +14,7 @@ module PDK
|
|
14
14
|
require 'pdk/report'
|
15
15
|
|
16
16
|
options = {
|
17
|
-
tense: :future
|
17
|
+
tense: :future
|
18
18
|
}.merge(options)
|
19
19
|
|
20
20
|
footer = false
|
@@ -23,7 +23,7 @@ module PDK
|
|
23
23
|
next if files.empty?
|
24
24
|
|
25
25
|
PDK::Report.default_target.puts('')
|
26
|
-
PDK::Report.default_target.puts(generate_banner("Files #{
|
26
|
+
PDK::Report.default_target.puts(generate_banner("Files #{options[:tense] == :future ? 'to be ' : ''}#{category}", 40))
|
27
27
|
PDK::Report.default_target.puts(files.map(&:to_s).join("\n"))
|
28
28
|
footer = true
|
29
29
|
end
|
@@ -34,7 +34,7 @@ module PDK
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
# :nocov: Tested as part of the public methods
|
38
38
|
# Returns a hash, summarizing the contents of the Update Manager object
|
39
39
|
# @param update_manager [PDK::Module::UpdateManager] The object to create a summary of
|
40
40
|
#
|
@@ -75,7 +75,7 @@ module PDK
|
|
75
75
|
banner
|
76
76
|
end
|
77
77
|
private_class_method :generate_banner
|
78
|
-
|
78
|
+
# :nocov:
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/lib/pdk/cli/util.rb
CHANGED
@@ -31,10 +31,11 @@ module PDK
|
|
31
31
|
def spinner_opts_for_platform
|
32
32
|
windows_opts = {
|
33
33
|
success_mark: '*',
|
34
|
-
error_mark: 'X'
|
34
|
+
error_mark: 'X'
|
35
35
|
}
|
36
36
|
|
37
37
|
return windows_opts if Gem.win_platform?
|
38
|
+
|
38
39
|
{}
|
39
40
|
end
|
40
41
|
module_function :spinner_opts_for_platform
|
@@ -43,7 +44,7 @@ module PDK
|
|
43
44
|
require 'tty/prompt'
|
44
45
|
|
45
46
|
prompt = opts[:prompt] || TTY::Prompt.new(help_color: :cyan)
|
46
|
-
validator = proc { |value| [true, false].include?(value) || value =~
|
47
|
+
validator = proc { |value| [true, false].include?(value) || value =~ /\A(?:yes|y|no|n)\Z/i }
|
47
48
|
response = nil
|
48
49
|
|
49
50
|
begin
|
@@ -74,7 +75,7 @@ module PDK
|
|
74
75
|
'BAMBOO_BUILDKEY', # Bamboo
|
75
76
|
'GOCD_SERVER_URL', # Go CD
|
76
77
|
'TRAVIS', # Travis CI
|
77
|
-
'GITHUB_WORKFLOW'
|
78
|
+
'GITHUB_WORKFLOW' # GitHub Actions
|
78
79
|
].any? { |name| PDK::Util::Env.key?(name) }
|
79
80
|
end
|
80
81
|
module_function :ci_environment?
|
@@ -111,7 +112,10 @@ module PDK
|
|
111
112
|
# This checks if the version listed in the module's metadata is older
|
112
113
|
# than the installed PDK, and advises the user to run pdk update.
|
113
114
|
elsif Gem::Version.new(PDK::VERSION) > Gem::Version.new(module_pdk_ver)
|
114
|
-
|
115
|
+
message = 'This module is compatible with an older version of PDK.'
|
116
|
+
message = 'Module templates older than 3.0.0 may experience issues.' if Gem::Version.new(module_pdk_ver) < Gem::Version.new('3.0.0')
|
117
|
+
|
118
|
+
PDK.logger.warn "#{message} Run `pdk update` to update it to the latest version."
|
115
119
|
end
|
116
120
|
end
|
117
121
|
module_function :module_version_check
|
@@ -119,13 +123,10 @@ module PDK
|
|
119
123
|
def check_for_deprecated_puppet(version)
|
120
124
|
return unless version.is_a?(Gem::Version)
|
121
125
|
|
122
|
-
deprecated_below = Gem::Version.new('
|
126
|
+
deprecated_below = Gem::Version.new('7.0.0')
|
123
127
|
return unless version < deprecated_below
|
124
128
|
|
125
|
-
|
126
|
-
'Support for Puppet versions older than %{version} is ' \
|
127
|
-
'deprecated and will be removed in a future version of PDK.' % { version: deprecated_below.to_s }
|
128
|
-
PDK.logger.warn(deprecated_msg)
|
129
|
+
raise PDK::CLI::ExitWithError, "Support for Puppet versions older than #{deprecated_below} has been removed from PDK."
|
129
130
|
end
|
130
131
|
module_function :check_for_deprecated_puppet
|
131
132
|
|
@@ -161,11 +162,7 @@ module PDK
|
|
161
162
|
end
|
162
163
|
|
163
164
|
# Notify user of what Ruby version will be used.
|
164
|
-
unless logging_disabled
|
165
|
-
PDK.logger.info('Using Ruby %{version}' % {
|
166
|
-
version: puppet_env[:ruby_version],
|
167
|
-
})
|
168
|
-
end
|
165
|
+
PDK.logger.info(format('Using Ruby %{version}', version: puppet_env[:ruby_version])) unless logging_disabled
|
169
166
|
|
170
167
|
check_for_deprecated_puppet(puppet_env[:gem_version])
|
171
168
|
|
@@ -176,16 +173,13 @@ module PDK
|
|
176
173
|
gemset.each do |gem, version|
|
177
174
|
next if version.nil?
|
178
175
|
|
179
|
-
PDK.logger.info('Using %{gem} %{version}'
|
180
|
-
gem: gem.to_s.capitalize,
|
181
|
-
version: version,
|
182
|
-
})
|
176
|
+
PDK.logger.info(format('Using %{gem} %{version}', gem: gem.to_s.capitalize, version: version))
|
183
177
|
end
|
184
178
|
end
|
185
179
|
|
186
180
|
{
|
187
181
|
gemset: gemset,
|
188
|
-
ruby_version: puppet_env[:ruby_version]
|
182
|
+
ruby_version: puppet_env[:ruby_version]
|
189
183
|
}
|
190
184
|
end
|
191
185
|
module_function :puppet_from_opts_or_env
|
@@ -207,10 +201,7 @@ module PDK
|
|
207
201
|
[puppet_ver_specs, pe_ver_specs].each do |offending|
|
208
202
|
next if offending.empty?
|
209
203
|
|
210
|
-
raise PDK::CLI::ExitWithError, 'You cannot specify a %{first} and %{second} at the same time.'
|
211
|
-
first: pup_dev_spec,
|
212
|
-
second: offending.first,
|
213
|
-
}
|
204
|
+
raise PDK::CLI::ExitWithError, format('You cannot specify a %{first} and %{second} at the same time.', first: pup_dev_spec, second: offending.first)
|
214
205
|
end
|
215
206
|
end
|
216
207
|
|
@@ -219,46 +210,38 @@ module PDK
|
|
219
210
|
|
220
211
|
offending = [pup_ver_spec, pe_ver_specs[0]].sort
|
221
212
|
|
222
|
-
raise PDK::CLI::ExitWithError, 'You cannot specify a %{first} and %{second} at the same time.'
|
223
|
-
|
224
|
-
|
225
|
-
|
213
|
+
raise PDK::CLI::ExitWithError, format('You cannot specify a %{first} and %{second} at the same time.', first: offending[0], second: offending[1])
|
214
|
+
end
|
215
|
+
|
216
|
+
# We want to mark setting the PE as deprecated.
|
217
|
+
if opts[:'pe-version'] || PDK::Util::Env['PDK_PE_VERSION']
|
218
|
+
PDK.logger.warn('Specifying a Puppet Enterprise version is now deprecated and will be removed in a future version. Please use --puppet-version or PDK_PUPPET_VERSION instead.')
|
226
219
|
end
|
227
220
|
|
228
221
|
if puppet_dev_specs.size == 2
|
229
222
|
warning_str = 'Puppet dev flag from command line: "--puppet-dev" '
|
230
223
|
warning_str += 'overrides value from environment: "PDK_PUPPET_DEV=true". You should not specify both.'
|
231
224
|
|
232
|
-
PDK.logger.warn(warning_str
|
233
|
-
pup_ver_opt: opts[:'puppet-dev'],
|
234
|
-
pup_ver_env: PDK::Util::Env['PDK_PUPPET_DEV'],
|
235
|
-
})
|
225
|
+
PDK.logger.warn(format(warning_str, pup_ver_opt: opts[:'puppet-dev'], pup_ver_env: PDK::Util::Env['PDK_PUPPET_DEV']))
|
236
226
|
elsif puppet_ver_specs.size == 2
|
237
227
|
warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
|
238
228
|
warning_str += 'overrides value from environment: "PDK_PUPPET_VERSION=%{pup_ver_env}". You should not specify both.'
|
239
229
|
|
240
|
-
PDK.logger.warn(warning_str
|
241
|
-
pup_ver_opt: opts[:'puppet-version'],
|
242
|
-
pup_ver_env: PDK::Util::Env['PDK_PUPPET_VERSION'],
|
243
|
-
})
|
230
|
+
PDK.logger.warn(format(warning_str, pup_ver_opt: opts[:'puppet-version'], pup_ver_env: PDK::Util::Env['PDK_PUPPET_VERSION']))
|
244
231
|
elsif pe_ver_specs.size == 2
|
245
232
|
warning_str = 'Puppet Enterprise version option from command line: "--pe-version=%{pe_ver_opt}" '
|
246
233
|
warning_str += 'overrides value from environment: "PDK_PE_VERSION=%{pe_ver_env}". You should not specify both.'
|
247
234
|
|
248
|
-
PDK.logger.warn(warning_str
|
249
|
-
pe_ver_opt: opts[:'pe-version'],
|
250
|
-
pe_ver_env: PDK::Util::Env['PDK_PE_VERSION'],
|
251
|
-
})
|
235
|
+
PDK.logger.warn(format(warning_str, pe_ver_opt: opts[:'pe-version'], pe_ver_env: PDK::Util::Env['PDK_PE_VERSION']))
|
252
236
|
end
|
253
237
|
end
|
254
238
|
module_function :validate_puppet_version_opts
|
255
239
|
|
256
240
|
def validate_template_opts(opts)
|
257
|
-
if opts[:'template-ref'] && opts[:'template-url'].nil?
|
258
|
-
|
259
|
-
|
241
|
+
raise PDK::CLI::ExitWithError, '--template-ref requires --template-url to also be specified.' if opts[:'template-ref'] && opts[:'template-url'].nil?
|
242
|
+
|
243
|
+
return unless opts[:'template-url']&.include?('#')
|
260
244
|
|
261
|
-
return unless opts[:'template-url'] && opts[:'template-url'].include?('#')
|
262
245
|
raise PDK::CLI::ExitWithError, '--template-url may not be used to specify paths containing #\'s.'
|
263
246
|
end
|
264
247
|
module_function :validate_template_opts
|
@@ -267,7 +250,7 @@ module PDK
|
|
267
250
|
require 'pdk/analytics'
|
268
251
|
|
269
252
|
dimensions = {
|
270
|
-
ruby_version: RUBY_VERSION
|
253
|
+
ruby_version: RUBY_VERSION
|
271
254
|
}
|
272
255
|
|
273
256
|
cmd_opts = opts.dup.reject do |_, v|
|
@@ -276,14 +259,15 @@ module PDK
|
|
276
259
|
|
277
260
|
if (format_args = cmd_opts.delete(:format))
|
278
261
|
formats = PDK::CLI::Util::OptionNormalizer.report_formats(format_args)
|
279
|
-
dimensions[:output_format] = formats.map { |r| r[:method].to_s.
|
262
|
+
dimensions[:output_format] = formats.map { |r| r[:method].to_s.delete_prefix('write_') }.sort.uniq.join(',')
|
280
263
|
else
|
281
264
|
dimensions[:output_format] = 'default'
|
282
265
|
end
|
283
266
|
|
284
267
|
safe_opts = [:'puppet-version', :'pe-version']
|
268
|
+
safe_bools = [true, false]
|
285
269
|
redacted_opts = cmd_opts.map do |k, v|
|
286
|
-
value = if
|
270
|
+
value = if safe_bools.include?(v) || safe_opts.include?(k)
|
287
271
|
v
|
288
272
|
else
|
289
273
|
'redacted'
|
@@ -292,11 +276,11 @@ module PDK
|
|
292
276
|
end
|
293
277
|
dimensions[:cli_options] = redacted_opts.join(',') unless redacted_opts.empty?
|
294
278
|
|
295
|
-
ignored_env_vars =
|
279
|
+
ignored_env_vars = ['PDK_ANALYTICS_CONFIG', 'PDK_DISABLE_ANALYTICS']
|
296
280
|
env_vars = PDK::Util::Env.select { |k, _| k.start_with?('PDK_') && !ignored_env_vars.include?(k) }.map { |k, v| "#{k}=#{v}" }
|
297
281
|
dimensions[:env_vars] = env_vars.join(',') unless env_vars.empty?
|
298
282
|
|
299
|
-
PDK.analytics.screen_view(screen_name, dimensions)
|
283
|
+
PDK.analytics.screen_view(screen_name, **dimensions)
|
300
284
|
end
|
301
285
|
module_function :analytics_screen_view
|
302
286
|
end
|
data/lib/pdk/cli/validate.rb
CHANGED
@@ -1,114 +1,116 @@
|
|
1
|
-
module PDK
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@validate_cmd = @base_cmd.define_command do
|
4
|
+
name 'validate'
|
5
|
+
usage 'validate [validators] [options] [targets]'
|
6
|
+
summary 'Run static analysis tests.'
|
7
|
+
description "Run metadata, YAML, Puppet, Ruby, or Tasks validation.\n\n" \
|
8
|
+
'[validators] is an optional comma-separated list of validators to use. ' \
|
9
|
+
'If not specified, all validators are used. ' \
|
10
|
+
"Note that when using PowerShell, the list of validators must be enclosed in single quotes.\n\n" \
|
11
|
+
'[targets] is an optional space-separated list of files or directories to be validated. ' \
|
12
|
+
'If not specified, validators are run against all applicable files in the module.'
|
13
|
+
|
14
|
+
PDK::CLI.puppet_version_options(self)
|
15
|
+
PDK::CLI.puppet_dev_option(self)
|
16
|
+
flag nil, :list, 'List all available validators.'
|
17
|
+
flag :a, 'auto-correct', 'Automatically correct problems where possible.'
|
18
|
+
flag nil, :parallel, 'Run validations in parallel.'
|
19
|
+
|
20
|
+
run do |opts, args, _cmd|
|
21
|
+
# Write the context information to the debug log
|
22
|
+
PDK.context.to_debug_log
|
23
|
+
|
24
|
+
if args == ['help']
|
25
|
+
PDK::CLI.run(['validate', '--help'])
|
26
|
+
exit 0
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
+
require 'pdk/validate'
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
if opts[:list]
|
32
|
+
PDK::CLI::Util.analytics_screen_view('validate', opts)
|
33
|
+
PDK.logger.info(format('Available validators: %{validator_names}', validator_names: PDK::Validate.validator_names.join(', ')))
|
34
|
+
exit 0
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
38
|
+
unless PDK.feature_flag?('controlrepo') || PDK.context.is_a?(PDK::Context::Module)
|
39
|
+
raise PDK::CLI::ExitWithError.new('Code validation can only be run from inside a valid module directory', log_level: :error)
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
else
|
62
|
-
# This is a single item. Check if it's a known validator, or otherwise treat it as a target.
|
63
|
-
val = PDK::Validate.validator_names.find { |name| args[0] == name }
|
64
|
-
if val
|
65
|
-
validators_to_run = [val]
|
42
|
+
PDK::CLI::Util.module_version_check if PDK.context.is_a?(PDK::Context::Module)
|
43
|
+
|
44
|
+
# Set the ruby version we're going to use early. Must be set before the validators are created.
|
45
|
+
# Note that this is a bit of code-smell and should be fixed
|
46
|
+
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
|
47
|
+
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
48
|
+
|
49
|
+
targets = []
|
50
|
+
validators_to_run = nil
|
51
|
+
if args[0]
|
52
|
+
# This may be a single validator, a list of validators, or a target.
|
53
|
+
if Util::OptionValidator.comma_separated_list?(args[0])
|
54
|
+
# This is a comma separated list. Treat each item as a validator.
|
55
|
+
vals = Util::OptionNormalizer.comma_separated_list_to_array(args[0])
|
56
|
+
validators_to_run = PDK::Validate.validator_names.select { |name| vals.include?(name) }
|
57
|
+
|
58
|
+
vals.reject { |v| PDK::Validate.validator_names.include?(v) }
|
59
|
+
.each do |v|
|
60
|
+
PDK.logger.warn(format("Unknown validator '%{v}'. Available validators: %{validators}.", v: v, validators: PDK::Validate.validator_names.join(', ')))
|
61
|
+
end
|
66
62
|
else
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
# This is a single item. Check if it's a known validator, or otherwise treat it as a target.
|
64
|
+
val = PDK::Validate.validator_names.find { |name| args[0] == name }
|
65
|
+
if val
|
66
|
+
validators_to_run = [val]
|
67
|
+
else
|
68
|
+
targets = [args[0]]
|
69
|
+
# We now know that no validators were passed, so let the user know we're using all of them by default.
|
70
|
+
PDK.logger.info('Running all available validators...')
|
71
|
+
end
|
70
72
|
end
|
73
|
+
else
|
74
|
+
PDK.logger.info('Running all available validators...')
|
71
75
|
end
|
72
|
-
|
73
|
-
PDK.logger.info('Running all available validators...')
|
74
|
-
end
|
75
|
-
validators_to_run = PDK::Validate.validator_names if validators_to_run.nil?
|
76
|
+
validators_to_run = PDK::Validate.validator_names if validators_to_run.nil?
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
if validators_to_run.sort == PDK::Validate.validator_names.sort
|
79
|
+
PDK::CLI::Util.analytics_screen_view('validate', opts)
|
80
|
+
else
|
81
|
+
PDK::CLI::Util.analytics_screen_view(['validate', validators_to_run.sort].flatten.join('_'), opts)
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
# Subsequent arguments are targets.
|
85
|
+
targets.concat(args.to_a[1..]) if args.length > 1
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
report = PDK::Report.new
|
88
|
+
report_formats = if opts[:format]
|
89
|
+
PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
|
90
|
+
else
|
91
|
+
[{
|
92
|
+
method: PDK::Report.default_format,
|
93
|
+
target: PDK::Report.default_target
|
94
|
+
}]
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
options = targets.empty? ? {} : { targets: targets }
|
98
|
+
options[:auto_correct] = true if opts[:'auto-correct']
|
99
|
+
options.merge!(puppet_env[:gemset])
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
# Ensure that the bundled gems are up to date and correct Ruby is activated before running any validations.
|
102
|
+
# Note that if no Gemfile exists, then ensure_bundle! will log a debug message and exit gracefully
|
103
|
+
require 'pdk/util/bundler'
|
104
|
+
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
|
104
105
|
|
105
|
-
|
106
|
+
exit_code, report = PDK::Validate.invoke_validators_by_name(PDK.context, validators_to_run, opts.fetch(:parallel, false), options)
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
report_formats.each do |format|
|
109
|
+
report.send(format[:method], format[:target])
|
110
|
+
end
|
110
111
|
|
111
|
-
|
112
|
+
exit exit_code
|
113
|
+
end
|
112
114
|
end
|
113
115
|
end
|
114
116
|
end
|