pdk 2.7.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +2 -48
- 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 +2 -4
- 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 +19 -13
- 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 +4 -4
- 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 +16 -67
- 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 +12 -20
- 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
data/lib/pdk/module/build.rb
CHANGED
@@ -7,8 +7,7 @@ module PDK
|
|
7
7
|
new(options).build
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :module_dir
|
11
|
-
attr_reader :target_dir
|
10
|
+
attr_reader :module_dir, :target_dir
|
12
11
|
|
13
12
|
def initialize(options = {})
|
14
13
|
@module_dir = PDK::Util::Filesystem.expand_path(options[:module_dir] || Dir.pwd)
|
@@ -86,7 +85,7 @@ module PDK
|
|
86
85
|
def release_name
|
87
86
|
@release_name ||= [
|
88
87
|
metadata['name'],
|
89
|
-
metadata['version']
|
88
|
+
metadata['version']
|
90
89
|
].join('-')
|
91
90
|
end
|
92
91
|
|
@@ -126,8 +125,8 @@ module PDK
|
|
126
125
|
PDK::Util::Filesystem.cp(path, dest_path, preserve: true)
|
127
126
|
end
|
128
127
|
rescue ArgumentError => e
|
129
|
-
raise PDK::CLI::ExitWithError, '%{message} Rename the file or exclude it from the package ' \
|
130
|
-
|
128
|
+
raise PDK::CLI::ExitWithError, format('%{message} Rename the file or exclude it from the package ' \
|
129
|
+
'by adding it to the .pdkignore file in your module.', message: e.message)
|
131
130
|
end
|
132
131
|
|
133
132
|
# Check if the given path matches one of the patterns listed in the
|
@@ -137,7 +136,7 @@ module PDK
|
|
137
136
|
#
|
138
137
|
# @return [Boolean] true if the path matches and should be ignored.
|
139
138
|
def ignored_path?(path)
|
140
|
-
path = path
|
139
|
+
path = "#{path}/" if PDK::Util::Filesystem.directory?(path)
|
141
140
|
|
142
141
|
!ignored_files.match_paths([path], module_dir).empty?
|
143
142
|
end
|
@@ -154,10 +153,8 @@ module PDK
|
|
154
153
|
symlink_path = Pathname.new(path)
|
155
154
|
module_path = Pathname.new(module_dir)
|
156
155
|
|
157
|
-
PDK.logger.warn 'Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.'
|
158
|
-
|
159
|
-
to: symlink_path.realpath.relative_path_from(module_path),
|
160
|
-
}
|
156
|
+
PDK.logger.warn format('Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.',
|
157
|
+
from: symlink_path.relative_path_from(module_path), to: symlink_path.realpath.relative_path_from(module_path))
|
161
158
|
end
|
162
159
|
|
163
160
|
# Checks if the path length will fit into the POSIX.1-1998 (ustar) tar
|
@@ -180,11 +177,7 @@ module PDK
|
|
180
177
|
#
|
181
178
|
# @return [nil]
|
182
179
|
def validate_ustar_path!(path)
|
183
|
-
if path.bytesize > 256
|
184
|
-
raise ArgumentError, "The path '%{path}' is longer than 256 bytes." % {
|
185
|
-
path: path,
|
186
|
-
}
|
187
|
-
end
|
180
|
+
raise ArgumentError, format("The path '%{path}' is longer than 256 bytes.", path: path) if path.bytesize > 256
|
188
181
|
|
189
182
|
if path.bytesize <= 100
|
190
183
|
prefix = ''
|
@@ -196,6 +189,7 @@ module PDK
|
|
196
189
|
loop do
|
197
190
|
nxt = parts.pop || ''
|
198
191
|
break if newpath.bytesize + 1 + nxt.bytesize >= 100
|
192
|
+
|
199
193
|
newpath = File.join(nxt, newpath)
|
200
194
|
end
|
201
195
|
|
@@ -206,9 +200,9 @@ module PDK
|
|
206
200
|
return unless path.bytesize > 100 || prefix.bytesize > 155
|
207
201
|
|
208
202
|
raise ArgumentError,
|
209
|
-
"'%{path}' could not be split at a directory separator into two " \
|
210
|
-
|
211
|
-
|
203
|
+
format("'%{path}' could not be split at a directory separator into two " \
|
204
|
+
'parts, the first having a maximum length of 155 bytes and the ' \
|
205
|
+
'second having a maximum length of 100 bytes.', path: path)
|
212
206
|
end
|
213
207
|
|
214
208
|
# Checks if the path contains any non-ASCII characters.
|
@@ -224,10 +218,10 @@ module PDK
|
|
224
218
|
#
|
225
219
|
# @return [nil]
|
226
220
|
def validate_path_encoding!(path)
|
227
|
-
return unless
|
221
|
+
return unless /[^\x00-\x7F]/.match?(path)
|
228
222
|
|
229
|
-
raise ArgumentError, "'%{path}' can only include ASCII characters in its path or " \
|
230
|
-
|
223
|
+
raise ArgumentError, format("'%{path}' can only include ASCII characters in its path or " \
|
224
|
+
'filename in order to be compatible with a wide range of hosts.', path: path)
|
231
225
|
end
|
232
226
|
|
233
227
|
# Creates a gzip compressed tarball of the build directory.
|
@@ -244,31 +238,24 @@ module PDK
|
|
244
238
|
PDK::Util::Filesystem.rm_f(package_file)
|
245
239
|
|
246
240
|
Dir.chdir(target_dir) do
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
entry: entry,
|
263
|
-
new_mode: (entry_meta[:mode] & 0o7777).to_s(8),
|
264
|
-
})
|
265
|
-
end
|
266
|
-
|
267
|
-
Minitar.pack_file(entry_meta, tar)
|
268
|
-
end
|
269
|
-
ensure
|
270
|
-
tar.close
|
241
|
+
gz = Zlib::GzipWriter.new(File.open(package_file, 'wb')) # rubocop:disable PDK/FileOpen
|
242
|
+
tar = Minitar::Output.new(gz)
|
243
|
+
Find.find(release_name) do |entry|
|
244
|
+
entry_meta = {
|
245
|
+
name: entry
|
246
|
+
}
|
247
|
+
|
248
|
+
orig_mode = PDK::Util::Filesystem.stat(entry).mode
|
249
|
+
min_mode = Minitar.dir?(entry) ? 0o755 : 0o644
|
250
|
+
|
251
|
+
entry_meta[:mode] = orig_mode | min_mode
|
252
|
+
|
253
|
+
PDK.logger.debug(format('Updated permissions of packaged \'%{entry}\' to %{new_mode}', entry: entry, new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) if entry_meta[:mode] != orig_mode
|
254
|
+
|
255
|
+
Minitar.pack_file(entry_meta, tar)
|
271
256
|
end
|
257
|
+
ensure
|
258
|
+
tar.close
|
272
259
|
end
|
273
260
|
end
|
274
261
|
|
@@ -283,7 +270,7 @@ module PDK
|
|
283
270
|
@ignore_file ||= [
|
284
271
|
File.join(module_dir, '.pdkignore'),
|
285
272
|
File.join(module_dir, '.pmtignore'),
|
286
|
-
File.join(module_dir, '.gitignore')
|
273
|
+
File.join(module_dir, '.gitignore')
|
287
274
|
].find { |file| PDK::Util::Filesystem.file?(file) && PDK::Util::Filesystem.readable?(file) }
|
288
275
|
end
|
289
276
|
|
@@ -303,9 +290,7 @@ module PDK
|
|
303
290
|
PathSpec.new(PDK::Util::Filesystem.read_file(ignore_file, open_args: 'rb:UTF-8'))
|
304
291
|
end
|
305
292
|
|
306
|
-
if File.realdirpath(target_dir).start_with?(File.realdirpath(module_dir))
|
307
|
-
ignored = ignored.add("\/#{File.basename(target_dir)}\/")
|
308
|
-
end
|
293
|
+
ignored = ignored.add("/#{File.basename(target_dir)}/") if File.realdirpath(target_dir).start_with?(File.realdirpath(module_dir))
|
309
294
|
|
310
295
|
PDK::Module::DEFAULT_IGNORED.each { |r| ignored.add(r) }
|
311
296
|
|
data/lib/pdk/module/convert.rb
CHANGED
@@ -7,9 +7,7 @@ module PDK
|
|
7
7
|
new(module_dir, options).run
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :module_dir
|
11
|
-
|
12
|
-
attr_reader :options
|
10
|
+
attr_reader :module_dir, :options
|
13
11
|
|
14
12
|
def initialize(module_dir, options = {})
|
15
13
|
@module_dir = module_dir
|
@@ -100,6 +98,7 @@ module PDK
|
|
100
98
|
|
101
99
|
def test_generators(context = PDK.context)
|
102
100
|
return @test_generators unless @test_generators.nil?
|
101
|
+
|
103
102
|
require 'pdk/util/puppet_strings'
|
104
103
|
|
105
104
|
test_gens = PDK::Util::PuppetStrings.all_objects.map do |generator, objects|
|
@@ -153,13 +152,11 @@ module PDK
|
|
153
152
|
absolute_file_path = File.join(module_dir, relative_file_path)
|
154
153
|
case file_status
|
155
154
|
when :unmanage
|
156
|
-
PDK.logger.debug("skipping '%{path}'"
|
155
|
+
PDK.logger.debug(format("skipping '%{path}'", path: absolute_file_path))
|
157
156
|
when :delete
|
158
157
|
update_manager.remove_file(absolute_file_path)
|
159
158
|
when :init
|
160
|
-
if convert? && !PDK::Util::Filesystem.exist?(absolute_file_path)
|
161
|
-
update_manager.add_file(absolute_file_path, file_content)
|
162
|
-
end
|
159
|
+
update_manager.add_file(absolute_file_path, file_content) if convert? && !PDK::Util::Filesystem.exist?(absolute_file_path)
|
163
160
|
when :manage
|
164
161
|
if PDK::Util::Filesystem.exist?(absolute_file_path)
|
165
162
|
update_manager.modify_file(absolute_file_path, file_content)
|
@@ -191,11 +188,7 @@ module PDK
|
|
191
188
|
require 'pdk/module/metadata'
|
192
189
|
|
193
190
|
if PDK::Util::Filesystem.file?(metadata_path)
|
194
|
-
unless PDK::Util::Filesystem.readable?(metadata_path)
|
195
|
-
raise PDK::CLI::ExitWithError, 'Unable to update module metadata; %{path} exists but it is not readable.' % {
|
196
|
-
path: metadata_path,
|
197
|
-
}
|
198
|
-
end
|
191
|
+
raise PDK::CLI::ExitWithError, format('Unable to update module metadata; %{path} exists but it is not readable.', path: metadata_path) unless PDK::Util::Filesystem.readable?(metadata_path)
|
199
192
|
|
200
193
|
begin
|
201
194
|
metadata = PDK::Module::Metadata.from_file(metadata_path)
|
@@ -208,9 +201,7 @@ module PDK
|
|
208
201
|
metadata = PDK::Generate::Module.prepare_metadata(options) unless options[:noop]
|
209
202
|
end
|
210
203
|
elsif PDK::Util::Filesystem.exist?(metadata_path)
|
211
|
-
raise PDK::CLI::ExitWithError, 'Unable to update module metadata; %{path} exists but it is not a file.'
|
212
|
-
path: metadata_path,
|
213
|
-
}
|
204
|
+
raise PDK::CLI::ExitWithError, format('Unable to update module metadata; %{path} exists but it is not a file.', path: metadata_path)
|
214
205
|
else
|
215
206
|
return if options[:noop]
|
216
207
|
|
@@ -250,23 +241,23 @@ module PDK
|
|
250
241
|
|
251
242
|
footer = false
|
252
243
|
|
253
|
-
summary.
|
244
|
+
summary.each_key do |category|
|
254
245
|
next if summary[category].empty?
|
255
246
|
|
256
|
-
PDK::Report.default_target.puts("\n%{banner}"
|
247
|
+
PDK::Report.default_target.puts(format("\n%{banner}", banner: generate_banner("Files to be #{category}", 40)))
|
257
248
|
PDK::Report.default_target.puts(summary[category])
|
258
249
|
footer = true
|
259
250
|
end
|
260
251
|
|
261
|
-
PDK::Report.default_target.puts("\n%{banner}"
|
252
|
+
PDK::Report.default_target.puts(format("\n%{banner}", banner: generate_banner('', 40))) if footer
|
262
253
|
end
|
263
254
|
|
264
255
|
def print_result(banner_text)
|
265
256
|
require 'pdk/report'
|
266
257
|
|
267
|
-
PDK::Report.default_target.puts("\n%{banner}"
|
268
|
-
summary_to_print = summary.
|
269
|
-
PDK::Report.default_target.puts("\n%{summary}\n\n"
|
258
|
+
PDK::Report.default_target.puts(format("\n%{banner}", banner: generate_banner(banner_text, 40)))
|
259
|
+
summary_to_print = summary.filter_map { |k, v| "#{v.length} files #{k}" unless v.empty? }
|
260
|
+
PDK::Report.default_target.puts(format("\n%{summary}\n\n", summary: "#{summary_to_print.join(', ')}."))
|
270
261
|
end
|
271
262
|
|
272
263
|
def full_report(path)
|
@@ -275,7 +266,7 @@ module PDK
|
|
275
266
|
report = ["/* Report generated by PDK at #{Time.now} */"]
|
276
267
|
report.concat(update_manager.changes[:modified].map { |_, diff| "\n\n\n#{diff}" })
|
277
268
|
PDK::Util::Filesystem.write_file(path, report.join)
|
278
|
-
PDK::Report.default_target.puts("\nYou can find a report of differences in %{path}.\n\n"
|
269
|
+
PDK::Report.default_target.puts(format("\nYou can find a report of differences in %{path}.\n\n", path: path))
|
279
270
|
end
|
280
271
|
|
281
272
|
def generate_banner(text, width = 80)
|
data/lib/pdk/module/metadata.rb
CHANGED
@@ -8,81 +8,79 @@ module PDK
|
|
8
8
|
OPERATING_SYSTEMS = {
|
9
9
|
'RedHat based Linux' => [
|
10
10
|
{
|
11
|
-
'operatingsystem'
|
12
|
-
'operatingsystemrelease' => ['7']
|
11
|
+
'operatingsystem' => 'CentOS',
|
12
|
+
'operatingsystemrelease' => ['7']
|
13
13
|
},
|
14
14
|
{
|
15
|
-
'operatingsystem'
|
16
|
-
'operatingsystemrelease' => ['7']
|
15
|
+
'operatingsystem' => 'OracleLinux',
|
16
|
+
'operatingsystemrelease' => ['7']
|
17
17
|
},
|
18
18
|
{
|
19
|
-
'operatingsystem'
|
20
|
-
'operatingsystemrelease' => ['8']
|
19
|
+
'operatingsystem' => 'RedHat',
|
20
|
+
'operatingsystemrelease' => ['8']
|
21
21
|
},
|
22
22
|
{
|
23
|
-
'operatingsystem'
|
24
|
-
'operatingsystemrelease' => ['7']
|
25
|
-
}
|
23
|
+
'operatingsystem' => 'Scientific',
|
24
|
+
'operatingsystemrelease' => ['7']
|
25
|
+
}
|
26
26
|
],
|
27
27
|
'Debian based Linux' => [
|
28
28
|
{
|
29
|
-
'operatingsystem'
|
30
|
-
'operatingsystemrelease' => ['10']
|
29
|
+
'operatingsystem' => 'Debian',
|
30
|
+
'operatingsystemrelease' => ['10']
|
31
31
|
},
|
32
32
|
{
|
33
|
-
'operatingsystem'
|
34
|
-
'operatingsystemrelease' => ['18.04']
|
35
|
-
}
|
33
|
+
'operatingsystem' => 'Ubuntu',
|
34
|
+
'operatingsystemrelease' => ['18.04']
|
35
|
+
}
|
36
36
|
],
|
37
37
|
'Fedora' => {
|
38
|
-
'operatingsystem'
|
39
|
-
'operatingsystemrelease' => ['29']
|
38
|
+
'operatingsystem' => 'Fedora',
|
39
|
+
'operatingsystemrelease' => ['29']
|
40
40
|
},
|
41
41
|
'OSX' => {
|
42
|
-
'operatingsystem'
|
43
|
-
'operatingsystemrelease' => ['16']
|
42
|
+
'operatingsystem' => 'Darwin',
|
43
|
+
'operatingsystemrelease' => ['16']
|
44
44
|
},
|
45
45
|
'SLES' => {
|
46
|
-
'operatingsystem'
|
47
|
-
'operatingsystemrelease' => ['15']
|
46
|
+
'operatingsystem' => 'SLES',
|
47
|
+
'operatingsystemrelease' => ['15']
|
48
48
|
},
|
49
49
|
'Solaris' => {
|
50
|
-
'operatingsystem'
|
51
|
-
'operatingsystemrelease' => ['11']
|
50
|
+
'operatingsystem' => 'Solaris',
|
51
|
+
'operatingsystemrelease' => ['11']
|
52
52
|
},
|
53
53
|
'Windows' => {
|
54
|
-
'operatingsystem'
|
55
|
-
'operatingsystemrelease' =>
|
54
|
+
'operatingsystem' => 'windows',
|
55
|
+
'operatingsystemrelease' => ['2019', '10']
|
56
56
|
},
|
57
57
|
'AIX' => {
|
58
|
-
'operatingsystem'
|
59
|
-
'operatingsystemrelease' =>
|
60
|
-
}
|
58
|
+
'operatingsystem' => 'AIX',
|
59
|
+
'operatingsystemrelease' => ['6.1', '7.1', '7.2']
|
60
|
+
}
|
61
61
|
}.freeze
|
62
62
|
|
63
63
|
DEFAULT_OPERATING_SYSTEMS = [
|
64
64
|
'RedHat based Linux',
|
65
65
|
'Debian based Linux',
|
66
|
-
'Windows'
|
66
|
+
'Windows'
|
67
67
|
].freeze
|
68
68
|
|
69
69
|
DEFAULTS = {
|
70
|
-
'name'
|
71
|
-
'version'
|
72
|
-
'author'
|
73
|
-
'summary'
|
74
|
-
'license'
|
75
|
-
'source'
|
76
|
-
'project_page'
|
77
|
-
'issues_url'
|
78
|
-
'dependencies'
|
70
|
+
'name' => nil,
|
71
|
+
'version' => '0.1.0',
|
72
|
+
'author' => nil,
|
73
|
+
'summary' => '',
|
74
|
+
'license' => 'Apache-2.0',
|
75
|
+
'source' => '',
|
76
|
+
'project_page' => nil,
|
77
|
+
'issues_url' => nil,
|
78
|
+
'dependencies' => [],
|
79
79
|
'data_provider' => nil,
|
80
|
-
'operatingsystem_support' => DEFAULT_OPERATING_SYSTEMS.
|
81
|
-
OPERATING_SYSTEMS[os_name]
|
82
|
-
}.flatten,
|
80
|
+
'operatingsystem_support' => DEFAULT_OPERATING_SYSTEMS.dup,
|
83
81
|
'requirements' => [
|
84
|
-
{ 'name' => 'puppet', 'version_requirement' => '>=
|
85
|
-
]
|
82
|
+
{ 'name' => 'puppet', 'version_requirement' => '>= 7.24 < 9.0.0' }
|
83
|
+
]
|
86
84
|
}.freeze
|
87
85
|
|
88
86
|
def initialize(params = {})
|
@@ -91,23 +89,17 @@ module PDK
|
|
91
89
|
end
|
92
90
|
|
93
91
|
def self.from_file(metadata_json_path)
|
94
|
-
if metadata_json_path.nil?
|
95
|
-
raise ArgumentError, 'Cannot read metadata from file: no path to file was given.'
|
96
|
-
end
|
92
|
+
raise ArgumentError, 'Cannot read metadata from file: no path to file was given.' if metadata_json_path.nil?
|
97
93
|
|
98
|
-
unless PDK::Util::Filesystem.file?(metadata_json_path)
|
99
|
-
raise ArgumentError, "'%{file}' does not exist or is not a file." % { file: metadata_json_path }
|
100
|
-
end
|
94
|
+
raise ArgumentError, format("'%{file}' does not exist or is not a file.", file: metadata_json_path) unless PDK::Util::Filesystem.file?(metadata_json_path)
|
101
95
|
|
102
|
-
unless PDK::Util::Filesystem.readable?(metadata_json_path)
|
103
|
-
raise ArgumentError, "Unable to open '%{file}' for reading." % { file: metadata_json_path }
|
104
|
-
end
|
96
|
+
raise ArgumentError, format("Unable to open '%{file}' for reading.", file: metadata_json_path) unless PDK::Util::Filesystem.readable?(metadata_json_path)
|
105
97
|
|
106
98
|
require 'json'
|
107
99
|
begin
|
108
100
|
data = JSON.parse(PDK::Util::Filesystem.read_file(metadata_json_path))
|
109
101
|
rescue JSON::JSONError => e
|
110
|
-
raise ArgumentError, 'Invalid JSON in metadata.json: %{msg}'
|
102
|
+
raise ArgumentError, format('Invalid JSON in metadata.json: %{msg}', msg: e.message)
|
111
103
|
end
|
112
104
|
|
113
105
|
require 'pdk/util'
|
@@ -122,10 +114,10 @@ module PDK
|
|
122
114
|
self
|
123
115
|
end
|
124
116
|
|
125
|
-
def to_json
|
117
|
+
def to_json(*_args)
|
126
118
|
require 'json'
|
127
119
|
|
128
|
-
JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? })
|
120
|
+
JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? }) # rubocop:disable Style/CollectionCompact
|
129
121
|
end
|
130
122
|
|
131
123
|
def write!(path)
|
@@ -144,9 +136,9 @@ module PDK
|
|
144
136
|
|
145
137
|
def validate_puppet_version_requirement!
|
146
138
|
msgs = {
|
147
|
-
no_reqs:
|
139
|
+
no_reqs: 'Module metadata does not contain any requirements.',
|
148
140
|
no_puppet_req: 'Module metadata does not contain a "puppet" requirement.',
|
149
|
-
no_puppet_ver: 'The "puppet" requirement in module metadata does not specify a "version_requirement".'
|
141
|
+
no_puppet_ver: 'The "puppet" requirement in module metadata does not specify a "version_requirement".'
|
150
142
|
}
|
151
143
|
|
152
144
|
raise ArgumentError, msgs[:no_reqs] unless @data.key?('requirements')
|
@@ -162,7 +154,7 @@ module PDK
|
|
162
154
|
end
|
163
155
|
|
164
156
|
def missing_fields
|
165
|
-
fields = DEFAULTS.keys -
|
157
|
+
fields = DEFAULTS.keys - ['data_provider', 'requirements', 'dependencies']
|
166
158
|
fields.select { |key| @data[key].nil? || @data[key].empty? }
|
167
159
|
end
|
168
160
|
|
@@ -179,7 +171,7 @@ module PDK
|
|
179
171
|
|
180
172
|
# Validates that the given module name is both namespaced and well-formed.
|
181
173
|
def validate_name(name)
|
182
|
-
return if
|
174
|
+
return if %r{\A[a-z0-9]+[-/][a-z][a-z0-9_]*\Z}i.match?(name)
|
183
175
|
|
184
176
|
namespace, modname = name.split(%r{[-/]}, 2)
|
185
177
|
modname = :namespace_missing if namespace == ''
|
@@ -187,15 +179,15 @@ module PDK
|
|
187
179
|
err = case modname
|
188
180
|
when nil, '', :namespace_missing
|
189
181
|
'Field must be a dash-separated user name and module name.'
|
190
|
-
when
|
182
|
+
when /[^a-z0-9_]/i
|
191
183
|
'Module name must contain only alphanumeric or underscore characters.'
|
192
|
-
when
|
184
|
+
when /^[^a-z]/i
|
193
185
|
'Module name must begin with a letter.'
|
194
186
|
else
|
195
187
|
'Namespace must contain only alphanumeric characters.'
|
196
188
|
end
|
197
189
|
|
198
|
-
raise ArgumentError, "Invalid 'name' field in metadata.json: %{err}"
|
190
|
+
raise ArgumentError, format("Invalid 'name' field in metadata.json: %{err}", err: err)
|
199
191
|
end
|
200
192
|
end
|
201
193
|
end
|
data/lib/pdk/module/release.rb
CHANGED
@@ -8,9 +8,7 @@ module PDK
|
|
8
8
|
new(module_path, options).run
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :options
|
12
|
-
|
13
|
-
attr_reader :module_path
|
11
|
+
attr_reader :options, :module_path
|
14
12
|
|
15
13
|
def initialize(module_path, options = {})
|
16
14
|
@options = options
|
@@ -21,9 +19,10 @@ module PDK
|
|
21
19
|
|
22
20
|
if module_path.nil?
|
23
21
|
module_path = PDK::Util.module_root
|
24
|
-
raise PDK::CLI::ExitWithError, 'The module release process requires a valid module path'
|
22
|
+
raise PDK::CLI::ExitWithError, 'The module release process requires a valid module path' if module_path.nil?
|
25
23
|
end
|
26
|
-
raise PDK::CLI::ExitWithError, '%{module_path} is not a valid module'
|
24
|
+
raise PDK::CLI::ExitWithError, format('%{module_path} is not a valid module', module_path: module_path) unless PDK::Util.in_module_root?(module_path)
|
25
|
+
|
27
26
|
@module_path = module_path
|
28
27
|
end
|
29
28
|
|
@@ -41,24 +40,17 @@ module PDK
|
|
41
40
|
|
42
41
|
run_validations(options) unless skip_validation?
|
43
42
|
|
44
|
-
PDK.logger.info 'Releasing %{module_name} - from version %{module_version}'
|
45
|
-
module_name: module_metadata.data['name'],
|
46
|
-
module_version: module_metadata.data['version'],
|
47
|
-
}
|
43
|
+
PDK.logger.info format('Releasing %{module_name} - from version %{module_version}', module_name: module_metadata.data['name'], module_version: module_metadata.data['version'])
|
48
44
|
|
49
45
|
PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?
|
50
46
|
|
51
47
|
# Calculate the new module version
|
52
48
|
new_version = specified_version
|
53
|
-
if new_version.nil? && !skip_changelog?
|
54
|
-
new_version = PDK::Util::ChangelogGenerator.compute_next_version(module_metadata.data['version'])
|
55
|
-
end
|
49
|
+
new_version = PDK::Util::ChangelogGenerator.compute_next_version(module_metadata.data['version']) if new_version.nil? && !skip_changelog?
|
56
50
|
new_version = module_metadata.data['version'] if new_version.nil?
|
57
51
|
|
58
52
|
if new_version != module_metadata.data['version']
|
59
|
-
PDK.logger.info 'Updating version to %{module_version}'
|
60
|
-
module_version: new_version,
|
61
|
-
}
|
53
|
+
PDK.logger.info format('Updating version to %{module_version}', module_version: new_version)
|
62
54
|
|
63
55
|
# Set the new version in metadata file
|
64
56
|
module_metadata.data['version'] = new_version
|
@@ -69,8 +61,8 @@ module PDK
|
|
69
61
|
|
70
62
|
# Check if the versions match
|
71
63
|
latest_version = PDK::Util::ChangelogGenerator.latest_version
|
72
|
-
|
73
|
-
raise PDK::CLI::ExitWithError, '%{new_version} does not match %{latest_version}'
|
64
|
+
if !latest_version && (new_version != latest_version)
|
65
|
+
raise PDK::CLI::ExitWithError, format('%{new_version} does not match %{latest_version}', new_version: new_version, latest_version: latest_version)
|
74
66
|
end
|
75
67
|
end
|
76
68
|
|
@@ -102,6 +94,7 @@ module PDK
|
|
102
94
|
|
103
95
|
def default_package_filename
|
104
96
|
return @default_tarball_filename unless @default_tarball_filename.nil?
|
97
|
+
|
105
98
|
builder = PDK::Module::Build.new(module_dir: module_path)
|
106
99
|
@default_tarball_filename = builder.package_file
|
107
100
|
end
|
@@ -127,7 +120,7 @@ module PDK
|
|
127
120
|
docs_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'puppet', 'strings', 'generate', '--format', 'markdown', '--out', 'REFERENCE.md')
|
128
121
|
docs_command.context = :module
|
129
122
|
result = docs_command.execute!
|
130
|
-
raise PDK::CLI::ExitWithError, 'An error occured generating the module documentation: %{stdout}'
|
123
|
+
raise PDK::CLI::ExitWithError, format('An error occured generating the module documentation: %{stdout}', stdout: result[:stdout]) unless result[:exit_code].zero?
|
131
124
|
end
|
132
125
|
|
133
126
|
def run_dependency_checker(_opts)
|
@@ -138,7 +131,7 @@ module PDK
|
|
138
131
|
dep_command.context = :module
|
139
132
|
result = dep_command.execute!
|
140
133
|
|
141
|
-
raise PDK::CLI::ExitWithError, 'An error occured checking the module dependencies: %{stdout}'
|
134
|
+
raise PDK::CLI::ExitWithError, format('An error occured checking the module dependencies: %{stdout}', stdout: result[:stdout]) unless result[:exit_code].zero?
|
142
135
|
end
|
143
136
|
|
144
137
|
# @return [String] Path to the built tarball
|
@@ -148,7 +141,7 @@ module PDK
|
|
148
141
|
|
149
142
|
def run_publish(_opts, tarball_path)
|
150
143
|
validate_publish_options!
|
151
|
-
raise PDK::CLI::ExitWithError, 'Module tarball %{tarball_path} does not exist'
|
144
|
+
raise PDK::CLI::ExitWithError, format('Module tarball %{tarball_path} does not exist', tarball_path: tarball_path) unless PDK::Util::Filesystem.file?(tarball_path)
|
152
145
|
|
153
146
|
# TODO: Replace this code when the upload functionality is added to the forge ruby gem
|
154
147
|
require 'base64'
|
@@ -158,19 +151,20 @@ module PDK
|
|
158
151
|
uri = URI(forge_upload_url)
|
159
152
|
require 'net/http'
|
160
153
|
request = Net::HTTP::Post.new(uri.path)
|
161
|
-
request['Authorization'] =
|
154
|
+
request['Authorization'] = "Bearer #{forge_token}"
|
162
155
|
request['Content-Type'] = 'application/json'
|
163
156
|
data = { file: file_data }
|
164
157
|
|
165
158
|
request.body = data.to_json
|
166
159
|
|
167
160
|
require 'openssl'
|
168
|
-
use_ssl = uri.
|
161
|
+
use_ssl = uri.instance_of?(URI::HTTPS)
|
169
162
|
response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
|
170
163
|
http.request(request)
|
171
164
|
end
|
172
165
|
|
173
|
-
raise PDK::CLI::ExitWithError, 'Error uploading to Puppet Forge: %{result}'
|
166
|
+
raise PDK::CLI::ExitWithError, format('Error uploading to Puppet Forge: %{result}', result: response.body) unless response.is_a?(Net::HTTPSuccess)
|
167
|
+
|
174
168
|
PDK.logger.info 'Publish to Forge was successful'
|
175
169
|
end
|
176
170
|
|
@@ -235,7 +229,7 @@ module PDK
|
|
235
229
|
!skip_publish?
|
236
230
|
end
|
237
231
|
|
238
|
-
|
232
|
+
# :nocov:
|
239
233
|
# These are just convenience methods and are tested elsewhere
|
240
234
|
def forge_compatible?
|
241
235
|
module_metadata.forge_ready?
|
@@ -247,7 +241,7 @@ module PDK
|
|
247
241
|
builder = PDK::Module::Build.new(module_dir: module_path)
|
248
242
|
@pdk_compatible = builder.module_pdk_compatible?
|
249
243
|
end
|
250
|
-
|
244
|
+
# :nocov:
|
251
245
|
|
252
246
|
private
|
253
247
|
|
data/lib/pdk/module/update.rb
CHANGED
@@ -3,18 +3,14 @@ require 'pdk'
|
|
3
3
|
module PDK
|
4
4
|
module Module
|
5
5
|
class Update < Convert
|
6
|
-
GIT_DESCRIBE_PATTERN =
|
6
|
+
GIT_DESCRIBE_PATTERN = /\A(?<base>.+?)-(?<additional_commits>\d+)-g(?<sha>.+)\Z/.freeze
|
7
7
|
|
8
8
|
def run
|
9
9
|
template_uri.uri_fragment = new_template_version
|
10
10
|
|
11
11
|
stage_changes!
|
12
12
|
|
13
|
-
if current_version == new_version
|
14
|
-
PDK.logger.debug 'This module is already up to date with version %{version} of the template.' % {
|
15
|
-
version: new_version,
|
16
|
-
}
|
17
|
-
end
|
13
|
+
PDK.logger.debug format('This module is already up to date with version %{version} of the template.', version: new_version) if current_version == new_version
|
18
14
|
|
19
15
|
unless update_manager.changes?
|
20
16
|
PDK::Report.default_target.puts('No changes required.')
|
@@ -97,7 +93,7 @@ module PDK
|
|
97
93
|
|
98
94
|
return data if data.nil?
|
99
95
|
|
100
|
-
if
|
96
|
+
if %r{^(?:heads|remotes)/}.match?(data[:base])
|
101
97
|
"#{data[:base].gsub(%r{^(heads/|remotes/\w+?/)}, '')}@#{data[:sha]}"
|
102
98
|
else
|
103
99
|
data[:base]
|
@@ -119,12 +115,7 @@ module PDK
|
|
119
115
|
'Updating %{module_name} using the template at %{template_url}, from %{current_version} to %{new_version}'
|
120
116
|
end
|
121
117
|
|
122
|
-
format_string
|
123
|
-
module_name: module_metadata.data['name'],
|
124
|
-
template_url: template_uri.bare_uri,
|
125
|
-
current_version: current_version,
|
126
|
-
new_version: new_version,
|
127
|
-
}
|
118
|
+
format(format_string, module_name: module_metadata.data['name'], template_url: template_uri.bare_uri, current_version: current_version, new_version: new_version)
|
128
119
|
end
|
129
120
|
end
|
130
121
|
end
|