pdk 1.14.0 → 1.14.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 +31 -0
- data/lib/pdk.rb +63 -8
- data/lib/pdk/analytics.rb +14 -28
- data/lib/pdk/analytics/client/google_analytics.rb +2 -0
- data/lib/pdk/analytics/client/noop.rb +2 -0
- data/lib/pdk/analytics/util.rb +2 -0
- data/lib/pdk/answer_file.rb +2 -21
- data/lib/pdk/cli.rb +25 -13
- data/lib/pdk/cli/errors.rb +2 -0
- data/lib/pdk/cli/exec.rb +5 -0
- data/lib/pdk/cli/exec/command.rb +10 -6
- data/lib/pdk/cli/exec/interactive_command.rb +1 -1
- data/lib/pdk/cli/exec_group.rb +2 -0
- data/lib/pdk/cli/module/generate.rb +1 -1
- data/lib/pdk/cli/new/module.rb +8 -1
- data/lib/pdk/cli/new/test.rb +0 -1
- data/lib/pdk/cli/test/unit.rb +0 -3
- data/lib/pdk/cli/util.rb +24 -13
- data/lib/pdk/cli/util/command_redirector.rb +3 -2
- data/lib/pdk/cli/util/interview.rb +2 -1
- data/lib/pdk/cli/util/option_normalizer.rb +2 -0
- data/lib/pdk/cli/util/option_validator.rb +2 -0
- data/lib/pdk/cli/validate.rb +0 -1
- data/lib/pdk/config.rb +19 -13
- data/lib/pdk/config/json.rb +1 -1
- data/lib/pdk/config/json_schema_namespace.rb +3 -4
- data/lib/pdk/config/json_schema_setting.rb +1 -1
- data/lib/pdk/config/json_with_schema.rb +1 -2
- data/lib/pdk/config/namespace.rb +2 -0
- data/lib/pdk/config/setting.rb +2 -0
- data/lib/pdk/config/validator.rb +31 -0
- data/lib/pdk/config/yaml.rb +1 -2
- data/lib/pdk/config/yaml_with_schema.rb +1 -1
- data/lib/pdk/generate.rb +19 -13
- data/lib/pdk/generate/defined_type.rb +1 -1
- data/lib/pdk/generate/module.rb +1 -1
- data/lib/pdk/generate/provider.rb +2 -2
- data/lib/pdk/generate/puppet_class.rb +1 -1
- data/lib/pdk/generate/puppet_object.rb +2 -0
- data/lib/pdk/generate/task.rb +1 -1
- data/lib/pdk/generate/transport.rb +1 -1
- data/lib/pdk/logger.rb +1 -4
- data/lib/pdk/module.rb +7 -0
- data/lib/pdk/module/build.rb +2 -0
- data/lib/pdk/module/convert.rb +2 -0
- data/lib/pdk/module/metadata.rb +2 -1
- data/lib/pdk/module/templatedir.rb +2 -0
- data/lib/pdk/module/update.rb +1 -1
- data/lib/pdk/module/update_manager.rb +2 -0
- data/lib/pdk/report.rb +3 -1
- data/lib/pdk/report/event.rb +2 -0
- data/lib/pdk/template_file.rb +1 -0
- data/lib/pdk/tests/unit.rb +8 -3
- data/lib/pdk/util.rb +25 -7
- data/lib/pdk/util/bundler.rb +2 -0
- data/lib/pdk/util/env.rb +30 -0
- data/lib/pdk/util/filesystem.rb +4 -1
- data/lib/pdk/util/git.rb +3 -1
- data/lib/pdk/util/puppet_strings.rb +4 -2
- data/lib/pdk/util/puppet_version.rb +11 -1
- data/lib/pdk/util/ruby_version.rb +1 -0
- data/lib/pdk/util/template_uri.rb +2 -0
- data/lib/pdk/util/vendored_file.rb +2 -0
- data/lib/pdk/util/version.rb +2 -0
- data/lib/pdk/util/windows.rb +1 -0
- data/lib/pdk/util/windows/api_types.rb +32 -0
- data/lib/pdk/util/windows/process.rb +79 -0
- data/lib/pdk/validate.rb +24 -5
- data/lib/pdk/validate/base_validator.rb +2 -0
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +1 -1
- data/lib/pdk/validate/metadata/metadata_syntax.rb +1 -1
- data/lib/pdk/validate/metadata_validator.rb +1 -3
- data/lib/pdk/validate/puppet/puppet_epp.rb +2 -2
- data/lib/pdk/validate/puppet/puppet_lint.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_syntax.rb +2 -2
- data/lib/pdk/validate/puppet_validator.rb +1 -4
- data/lib/pdk/validate/ruby/rubocop.rb +1 -1
- data/lib/pdk/validate/ruby_validator.rb +1 -2
- data/lib/pdk/validate/tasks/metadata_lint.rb +1 -1
- data/lib/pdk/validate/tasks/name.rb +1 -1
- data/lib/pdk/validate/tasks_validator.rb +1 -3
- data/lib/pdk/validate/yaml/syntax.rb +1 -1
- data/lib/pdk/validate/yaml_validator.rb +1 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +243 -207
- metadata +7 -4
data/lib/pdk/cli/util.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
1
3
|
module PDK
|
2
4
|
module CLI
|
3
5
|
module Util
|
6
|
+
autoload :CommandRedirector, 'pdk/cli/util/command_redirector'
|
7
|
+
autoload :OptionNormalizer, 'pdk/cli/util/option_normalizer'
|
8
|
+
autoload :OptionValidator, 'pdk/cli/util/option_validator'
|
9
|
+
autoload :Interview, 'pdk/cli/util/interview'
|
10
|
+
autoload :Spinner, 'pdk/cli/util/spinner'
|
11
|
+
|
4
12
|
# Ensures the calling code is being run from inside a module directory.
|
5
13
|
#
|
6
14
|
# @param opts [Hash] options to change the behavior of the check logic.
|
@@ -31,6 +39,8 @@ module PDK
|
|
31
39
|
module_function :spinner_opts_for_platform
|
32
40
|
|
33
41
|
def prompt_for_yes(question_text, opts = {})
|
42
|
+
require 'tty/prompt'
|
43
|
+
|
34
44
|
prompt = opts[:prompt] || TTY::Prompt.new(help_color: :cyan)
|
35
45
|
validator = proc { |value| [true, false].include?(value) || value =~ %r{\A(?:yes|y|no|n)\Z}i }
|
36
46
|
response = nil
|
@@ -40,7 +50,7 @@ module PDK
|
|
40
50
|
q.default opts[:default] unless opts[:default].nil?
|
41
51
|
q.validate(validator, _('Answer "Y" to continue or "n" to cancel.'))
|
42
52
|
end
|
43
|
-
rescue
|
53
|
+
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
|
44
54
|
PDK.logger.info opts[:cancel_message] if opts[:cancel_message]
|
45
55
|
end
|
46
56
|
|
@@ -64,7 +74,7 @@ module PDK
|
|
64
74
|
'GOCD_SERVER_URL', # Go CD
|
65
75
|
'TRAVIS', # Travis CI
|
66
76
|
'GITHUB_WORKFLOW', # GitHub Actions
|
67
|
-
].any? { |name|
|
77
|
+
].any? { |name| PDK::Util::Env.key?(name) }
|
68
78
|
end
|
69
79
|
module_function :ci_environment?
|
70
80
|
|
@@ -72,7 +82,7 @@ module PDK
|
|
72
82
|
require 'pdk/logger'
|
73
83
|
|
74
84
|
return false if PDK.logger.debug?
|
75
|
-
return !
|
85
|
+
return !PDK::Util::Env['PDK_FRONTEND'].casecmp('noninteractive').zero? if PDK::Util::Env['PDK_FRONTEND']
|
76
86
|
return false if ci_environment?
|
77
87
|
return false unless $stderr.isatty
|
78
88
|
|
@@ -127,13 +137,14 @@ module PDK
|
|
127
137
|
# @return [Hash] - return hash of { gemset: <>, ruby_version: 2.x.x }
|
128
138
|
def puppet_from_opts_or_env(opts, logging_disabled = false)
|
129
139
|
opts ||= {}
|
130
|
-
use_puppet_dev = opts.fetch(:'puppet-dev',
|
131
|
-
desired_puppet_version = opts.fetch(:'puppet-version',
|
132
|
-
desired_pe_version = opts.fetch(:'pe-version',
|
140
|
+
use_puppet_dev = opts.fetch(:'puppet-dev', PDK::Util::Env['PDK_PUPPET_DEV'])
|
141
|
+
desired_puppet_version = opts.fetch(:'puppet-version', PDK::Util::Env['PDK_PUPPET_VERSION'])
|
142
|
+
desired_pe_version = opts.fetch(:'pe-version', PDK::Util::Env['PDK_PE_VERSION'])
|
133
143
|
|
134
144
|
begin
|
135
145
|
puppet_env =
|
136
146
|
if use_puppet_dev
|
147
|
+
PDK::Util::PuppetVersion.fetch_puppet_dev(run: :once)
|
137
148
|
PDK::Util::PuppetVersion.puppet_dev_env
|
138
149
|
elsif desired_puppet_version
|
139
150
|
PDK::Util::PuppetVersion.find_gem_for(desired_puppet_version)
|
@@ -179,15 +190,15 @@ module PDK
|
|
179
190
|
def validate_puppet_version_opts(opts)
|
180
191
|
puppet_ver_specs = []
|
181
192
|
puppet_ver_specs << '--puppet-version option' if opts[:'puppet-version']
|
182
|
-
puppet_ver_specs << 'PDK_PUPPET_VERSION environment variable' if
|
193
|
+
puppet_ver_specs << 'PDK_PUPPET_VERSION environment variable' if PDK::Util::Env['PDK_PUPPET_VERSION'] && !PDK::Util::Env['PDK_PUPPET_VERSION'].empty?
|
183
194
|
|
184
195
|
pe_ver_specs = []
|
185
196
|
pe_ver_specs << '--pe-version option' if opts[:'pe-version']
|
186
|
-
pe_ver_specs << 'PDK_PE_VERSION environment variable' if
|
197
|
+
pe_ver_specs << 'PDK_PE_VERSION environment variable' if PDK::Util::Env['PDK_PE_VERSION'] && !PDK::Util::Env['PDK_PE_VERSION'].empty?
|
187
198
|
|
188
199
|
puppet_dev_specs = []
|
189
200
|
puppet_dev_specs << '--puppet-dev flag' if opts[:'puppet-dev']
|
190
|
-
puppet_dev_specs << 'PDK_PUPPET_DEV environment variable' if
|
201
|
+
puppet_dev_specs << 'PDK_PUPPET_DEV environment variable' if PDK::Util::Env['PDK_PUPPET_DEV'] && !PDK::Util::Env['PDK_PUPPET_DEV'].empty?
|
191
202
|
|
192
203
|
puppet_dev_specs.each do |pup_dev_spec|
|
193
204
|
[puppet_ver_specs, pe_ver_specs].each do |offending|
|
@@ -217,7 +228,7 @@ module PDK
|
|
217
228
|
|
218
229
|
PDK.logger.warn(_(warning_str) % {
|
219
230
|
pup_ver_opt: opts[:'puppet-dev'],
|
220
|
-
pup_ver_env:
|
231
|
+
pup_ver_env: PDK::Util::Env['PDK_PUPPET_DEV'],
|
221
232
|
})
|
222
233
|
elsif puppet_ver_specs.size == 2
|
223
234
|
warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
|
@@ -225,7 +236,7 @@ module PDK
|
|
225
236
|
|
226
237
|
PDK.logger.warn(_(warning_str) % {
|
227
238
|
pup_ver_opt: opts[:'puppet-version'],
|
228
|
-
pup_ver_env:
|
239
|
+
pup_ver_env: PDK::Util::Env['PDK_PUPPET_VERSION'],
|
229
240
|
})
|
230
241
|
elsif pe_ver_specs.size == 2
|
231
242
|
warning_str = 'Puppet Enterprise version option from command line: "--pe-version=%{pe_ver_opt}" '
|
@@ -233,7 +244,7 @@ module PDK
|
|
233
244
|
|
234
245
|
PDK.logger.warn(_(warning_str) % {
|
235
246
|
pup_ver_opt: opts[:'pe-version'],
|
236
|
-
pup_ver_env:
|
247
|
+
pup_ver_env: PDK::Util::Env['PDK_PE_VERSION'],
|
237
248
|
})
|
238
249
|
end
|
239
250
|
end
|
@@ -279,7 +290,7 @@ module PDK
|
|
279
290
|
dimensions[:cli_options] = redacted_opts.join(',') unless redacted_opts.empty?
|
280
291
|
|
281
292
|
ignored_env_vars = %w[PDK_ANALYTICS_CONFIG PDK_DISABLE_ANALYTICS]
|
282
|
-
env_vars =
|
293
|
+
env_vars = PDK::Util::Env.select { |k, _| k.start_with?('PDK_') && !ignored_env_vars.include?(k) }.map { |k, v| "#{k}=#{v}" }
|
283
294
|
dimensions[:env_vars] = env_vars.join(',') unless env_vars.empty?
|
284
295
|
|
285
296
|
PDK.analytics.screen_view(screen_name, dimensions)
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'pdk'
|
2
|
+
require 'tty/prompt'
|
2
3
|
|
3
4
|
module PDK
|
4
5
|
module CLI
|
@@ -17,7 +18,7 @@ module PDK
|
|
17
18
|
def run
|
18
19
|
@prompt.puts _('Did you mean \'%{command}\'?') % { command: pastel.bold(@command) }
|
19
20
|
@prompt.yes?('-->')
|
20
|
-
rescue
|
21
|
+
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
|
21
22
|
nil
|
22
23
|
end
|
23
24
|
end
|
data/lib/pdk/cli/validate.rb
CHANGED
@@ -96,7 +96,6 @@ module PDK::CLI
|
|
96
96
|
|
97
97
|
# Ensure that the bundled gems are up to date and correct Ruby is activated before running any validations.
|
98
98
|
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
|
99
|
-
PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
|
100
99
|
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
101
100
|
|
102
101
|
options.merge!(puppet_env[:gemset])
|
data/lib/pdk/config.rb
CHANGED
@@ -1,27 +1,33 @@
|
|
1
|
-
require 'pdk
|
2
|
-
require 'pdk/config/namespace'
|
3
|
-
require 'pdk/config/setting'
|
4
|
-
require 'pdk/config/yaml'
|
5
|
-
require 'pdk/config/yaml_with_schema'
|
6
|
-
require 'pdk/config/json'
|
1
|
+
require 'pdk'
|
7
2
|
|
8
3
|
module PDK
|
9
|
-
def self.config
|
10
|
-
@config ||= PDK::Config.new
|
11
|
-
end
|
12
|
-
|
13
4
|
class Config
|
5
|
+
autoload :JSON, 'pdk/config/json'
|
6
|
+
autoload :JSONSchemaNamespace, 'pdk/config/json_schema_namespace'
|
7
|
+
autoload :JSONSchemaSetting, 'pdk/config/json_schema_setting'
|
8
|
+
autoload :LoadError, 'pdk/config/errors'
|
9
|
+
autoload :Namespace, 'pdk/config/namespace'
|
10
|
+
autoload :Setting, 'pdk/config/setting'
|
11
|
+
autoload :Validator, 'pdk/config/validator'
|
12
|
+
autoload :YAML, 'pdk/config/yaml'
|
13
|
+
|
14
14
|
def user
|
15
|
-
require 'pdk/answer_file'
|
16
15
|
@user ||= PDK::Config::JSON.new('user', file: PDK::Config.user_config_path) do
|
17
16
|
mount :module_defaults, PDK::Config::JSON.new(file: PDK.answers.answer_file_path)
|
18
17
|
|
19
|
-
|
18
|
+
# Due to the json-schema gem having issues with Windows based paths, and only supporting Draft 05 (or less) do
|
19
|
+
# not use JSON validation yet. Once PDK drops support for EOL rubies, we will be able to use the json_schemer gem
|
20
|
+
# Which has much more modern support
|
21
|
+
# Reference - https://github.com/puppetlabs/pdk/pull/777
|
22
|
+
# Reference - https://tickets.puppetlabs.com/browse/PDK-1526
|
23
|
+
mount :analytics, PDK::Config::YAML.new(file: PDK::Config.analytics_config_path, persistent_defaults: true) do
|
20
24
|
setting :disabled do
|
25
|
+
validate PDK::Config::Validator.boolean
|
21
26
|
default_to { PDK::Config.bolt_analytics_config.fetch('disabled', true) }
|
22
27
|
end
|
23
28
|
|
24
29
|
setting 'user-id' do
|
30
|
+
validate PDK::Config::Validator.uuid
|
25
31
|
default_to do
|
26
32
|
require 'securerandom'
|
27
33
|
|
@@ -52,7 +58,7 @@ module PDK
|
|
52
58
|
end
|
53
59
|
|
54
60
|
def self.analytics_config_path
|
55
|
-
|
61
|
+
PDK::Util::Env['PDK_ANALYTICS_CONFIG'] || File.join(File.dirname(PDK::Util.configdir), 'puppet', 'analytics.yml')
|
56
62
|
end
|
57
63
|
|
58
64
|
def self.user_config_path
|
data/lib/pdk/config/json.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'pdk
|
1
|
+
require 'pdk'
|
2
2
|
|
3
3
|
# Due to https://github.com/ruby-json-schema/json-schema/issues/439
|
4
4
|
# Windows file paths "appear" as uri's with no host and a schema of drive letter
|
@@ -23,6 +23,8 @@ module JSON
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
require 'json-schema'
|
27
|
+
|
26
28
|
module PDK
|
27
29
|
class Config
|
28
30
|
class JSONSchemaNamespace < Namespace
|
@@ -104,7 +106,6 @@ module PDK
|
|
104
106
|
#
|
105
107
|
# @return [JSON::Schema]
|
106
108
|
def create_empty_schema
|
107
|
-
require 'json-schema'
|
108
109
|
::JSON::Schema.new({}, 'http://json-schema.org/draft-06/schema#')
|
109
110
|
end
|
110
111
|
|
@@ -117,8 +118,6 @@ module PDK
|
|
117
118
|
# Create an empty schema by default.
|
118
119
|
@document_schema = create_empty_schema
|
119
120
|
|
120
|
-
require 'json-schema'
|
121
|
-
|
122
121
|
return @document_schema if @schema_file.nil?
|
123
122
|
unless PDK::Util::Filesystem.file?(@schema_file)
|
124
123
|
raise PDK::Config::LoadError, _('Unable to open %{file} for reading. File does not exist') % {
|
data/lib/pdk/config/namespace.rb
CHANGED
data/lib/pdk/config/setting.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module PDK
|
2
|
+
class Config
|
3
|
+
# A collection of predefined validators for use with {PDK::Config::Value}.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# value :enabled do
|
7
|
+
# validate PDK::Config::Validator.boolean
|
8
|
+
# end
|
9
|
+
module Validator
|
10
|
+
# @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
|
11
|
+
# validator that ensures that the value is either a TrueClass or
|
12
|
+
# FalseClass.
|
13
|
+
def self.boolean
|
14
|
+
{
|
15
|
+
proc: ->(value) { [true, false].include?(value) },
|
16
|
+
message: _('must be a boolean: true or false'),
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
|
21
|
+
# validator that ensures that the value is a String that matches the
|
22
|
+
# regex for a version 4 UUID.
|
23
|
+
def self.uuid
|
24
|
+
{
|
25
|
+
proc: ->(value) { value.match(%r{\A\h{8}(?:-\h{4}){3}-\h{12}\z}) },
|
26
|
+
message: _('must be a version 4 UUID'),
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/pdk/config/yaml.rb
CHANGED
data/lib/pdk/generate.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
require 'pdk
|
2
|
-
require 'pdk/generate/module'
|
3
|
-
require 'pdk/generate/provider'
|
4
|
-
require 'pdk/generate/puppet_class'
|
5
|
-
require 'pdk/generate/task'
|
6
|
-
require 'pdk/generate/transport'
|
1
|
+
require 'pdk'
|
7
2
|
|
8
3
|
module PDK
|
9
4
|
module Generate
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
autoload :DefinedType, 'pdk/generate/defined_type'
|
6
|
+
autoload :Module, 'pdk/generate/module'
|
7
|
+
autoload :Provider, 'pdk/generate/provider'
|
8
|
+
autoload :PuppetClass, 'pdk/generate/puppet_class'
|
9
|
+
autoload :PuppetObject, 'pdk/generate/puppet_object'
|
10
|
+
autoload :Task, 'pdk/generate/task'
|
11
|
+
autoload :Transport, 'pdk/generate/transport'
|
12
|
+
|
13
|
+
def generators
|
14
|
+
@generators ||= [
|
15
|
+
PDK::Generate::DefinedType,
|
16
|
+
PDK::Generate::Provider,
|
17
|
+
PDK::Generate::PuppetClass,
|
18
|
+
PDK::Generate::Task,
|
19
|
+
PDK::Generate::Transport,
|
20
|
+
].freeze
|
21
|
+
end
|
22
|
+
module_function :generators
|
17
23
|
end
|
18
24
|
end
|
data/lib/pdk/generate/module.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'pdk
|
1
|
+
require 'pdk'
|
2
2
|
|
3
3
|
module PDK
|
4
4
|
module Generate
|
@@ -21,7 +21,7 @@ module PDK
|
|
21
21
|
|
22
22
|
def raise_precondition_error(error)
|
23
23
|
raise PDK::CLI::ExitWithError, _('%{error}: Creating a provider needs some local configuration in your module.' \
|
24
|
-
' Please follow the docs at https://
|
24
|
+
' Please follow the docs at https://puppet.com/docs/puppet/latest/create_types_and_providers_resource_api.html.') % { error: error }
|
25
25
|
end
|
26
26
|
|
27
27
|
def check_preconditions
|
data/lib/pdk/generate/task.rb
CHANGED
data/lib/pdk/logger.rb
CHANGED
data/lib/pdk/module.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module PDK
|
2
2
|
module Module
|
3
|
+
autoload :Build, 'pdk/module/build'
|
4
|
+
autoload :Convert, 'pdk/module/convert'
|
5
|
+
autoload :Metadata, 'pdk/module/metadata'
|
6
|
+
autoload :TemplateDir, 'pdk/module/templatedir'
|
7
|
+
autoload :UpdateManager, 'pdk/module/update_manager'
|
8
|
+
autoload :Update, 'pdk/module/update'
|
9
|
+
|
3
10
|
DEFAULT_IGNORED = [
|
4
11
|
'/pkg/',
|
5
12
|
'~*',
|