pdk 1.16.0 → 2.1.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 +167 -11
- data/README.md +1 -1
- data/lib/pdk.rb +26 -19
- data/lib/pdk/answer_file.rb +2 -93
- data/lib/pdk/cli.rb +8 -6
- data/lib/pdk/cli/config.rb +3 -1
- data/lib/pdk/cli/config/get.rb +3 -1
- data/lib/pdk/cli/convert.rb +7 -9
- data/lib/pdk/cli/env.rb +52 -0
- data/lib/pdk/cli/exec/command.rb +13 -0
- data/lib/pdk/cli/exec_group.rb +78 -43
- data/lib/pdk/cli/get.rb +20 -0
- data/lib/pdk/cli/get/config.rb +24 -0
- data/lib/pdk/cli/new.rb +2 -0
- data/lib/pdk/cli/new/class.rb +2 -1
- data/lib/pdk/cli/new/defined_type.rb +2 -1
- data/lib/pdk/cli/new/fact.rb +29 -0
- data/lib/pdk/cli/new/function.rb +29 -0
- data/lib/pdk/cli/new/provider.rb +2 -1
- data/lib/pdk/cli/new/task.rb +2 -1
- data/lib/pdk/cli/new/test.rb +2 -1
- data/lib/pdk/cli/new/transport.rb +2 -1
- data/lib/pdk/cli/release/publish.rb +11 -1
- data/lib/pdk/cli/remove.rb +20 -0
- data/lib/pdk/cli/remove/config.rb +80 -0
- data/lib/pdk/cli/set.rb +20 -0
- data/lib/pdk/cli/set/config.rb +119 -0
- data/lib/pdk/cli/update.rb +6 -8
- data/lib/pdk/cli/util.rb +7 -3
- data/lib/pdk/cli/util/option_validator.rb +6 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/validate.rb +26 -44
- data/lib/pdk/config.rb +264 -7
- data/lib/pdk/config/ini_file.rb +183 -0
- data/lib/pdk/config/ini_file_setting.rb +39 -0
- data/lib/pdk/config/namespace.rb +25 -5
- data/lib/pdk/config/setting.rb +3 -2
- data/lib/pdk/context.rb +99 -0
- data/lib/pdk/context/control_repo.rb +60 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/control_repo.rb +40 -0
- data/lib/pdk/generate/defined_type.rb +25 -32
- data/lib/pdk/generate/fact.rb +25 -0
- data/lib/pdk/generate/function.rb +48 -0
- data/lib/pdk/generate/module.rb +14 -17
- data/lib/pdk/generate/provider.rb +15 -64
- data/lib/pdk/generate/puppet_class.rb +25 -31
- data/lib/pdk/generate/puppet_object.rb +83 -187
- data/lib/pdk/generate/task.rb +28 -46
- data/lib/pdk/generate/transport.rb +20 -74
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/module/convert.rb +43 -23
- data/lib/pdk/module/metadata.rb +6 -2
- data/lib/pdk/module/release.rb +3 -9
- data/lib/pdk/module/update.rb +7 -11
- data/lib/pdk/module/update_manager.rb +7 -0
- data/lib/pdk/report.rb +3 -3
- data/lib/pdk/report/event.rb +8 -2
- data/lib/pdk/template.rb +59 -0
- data/lib/pdk/template/fetcher.rb +98 -0
- data/lib/pdk/template/fetcher/git.rb +85 -0
- data/lib/pdk/template/fetcher/local.rb +28 -0
- data/lib/pdk/template/renderer.rb +96 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/tests/unit.rb +8 -1
- data/lib/pdk/util.rb +38 -39
- data/lib/pdk/util/bundler.rb +2 -1
- data/lib/pdk/util/changelog_generator.rb +11 -2
- data/lib/pdk/util/json_finder.rb +84 -0
- data/lib/pdk/util/puppet_strings.rb +3 -3
- data/lib/pdk/util/puppet_version.rb +2 -2
- data/lib/pdk/util/ruby_version.rb +5 -1
- data/lib/pdk/util/template_uri.rb +13 -14
- data/lib/pdk/util/vendored_file.rb +1 -2
- data/lib/pdk/validate.rb +79 -25
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +208 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
- data/lib/pdk/validate/invokable_validator.rb +220 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +118 -0
- data/lib/pdk/validate/validator_group.rb +104 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +477 -313
- metadata +77 -35
- data/lib/pdk/module/template_dir.rb +0 -115
- data/lib/pdk/module/template_dir/base.rb +0 -268
- data/lib/pdk/module/template_dir/git.rb +0 -91
- data/lib/pdk/module/template_dir/local.rb +0 -21
- data/lib/pdk/template_file.rb +0 -96
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
- data/lib/pdk/validate/metadata_validator.rb +0 -26
- data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
- data/lib/pdk/validate/puppet_validator.rb +0 -26
- data/lib/pdk/validate/ruby/rubocop.rb +0 -72
- data/lib/pdk/validate/ruby_validator.rb +0 -26
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
- data/lib/pdk/validate/tasks/name.rb +0 -90
- data/lib/pdk/validate/tasks_validator.rb +0 -29
- data/lib/pdk/validate/yaml/syntax.rb +0 -125
- data/lib/pdk/validate/yaml_validator.rb +0 -28
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.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,16 +76,22 @@ dependencies:
|
|
76
76
|
name: ffi
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.25
|
82
|
+
- - "<"
|
80
83
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
84
|
+
version: 2.0.0
|
82
85
|
type: :runtime
|
83
86
|
prerelease: false
|
84
87
|
version_requirements: !ruby/object:Gem::Requirement
|
85
88
|
requirements:
|
86
|
-
- - "
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 1.9.25
|
92
|
+
- - "<"
|
87
93
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
94
|
+
version: 2.0.0
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
96
|
name: gettext-setup
|
91
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,14 +182,14 @@ dependencies:
|
|
176
182
|
requirements:
|
177
183
|
- - "~>"
|
178
184
|
- !ruby/object:Gem::Version
|
179
|
-
version: '0.
|
185
|
+
version: '0.22'
|
180
186
|
type: :runtime
|
181
187
|
prerelease: false
|
182
188
|
version_requirements: !ruby/object:Gem::Requirement
|
183
189
|
requirements:
|
184
190
|
- - "~>"
|
185
191
|
- !ruby/object:Gem::Version
|
186
|
-
version: '0.
|
192
|
+
version: '0.22'
|
187
193
|
- !ruby/object:Gem::Dependency
|
188
194
|
name: tty-spinner
|
189
195
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,16 +236,22 @@ dependencies:
|
|
230
236
|
name: facter
|
231
237
|
requirement: !ruby/object:Gem::Requirement
|
232
238
|
requirements:
|
233
|
-
- - "
|
239
|
+
- - ">="
|
234
240
|
- !ruby/object:Gem::Version
|
235
241
|
version: 2.5.1
|
242
|
+
- - "<"
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: 5.0.0
|
236
245
|
type: :runtime
|
237
246
|
prerelease: false
|
238
247
|
version_requirements: !ruby/object:Gem::Requirement
|
239
248
|
requirements:
|
240
|
-
- - "
|
249
|
+
- - ">="
|
241
250
|
- !ruby/object:Gem::Version
|
242
251
|
version: 2.5.1
|
252
|
+
- - "<"
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: 5.0.0
|
243
255
|
- !ruby/object:Gem::Dependency
|
244
256
|
name: httpclient
|
245
257
|
requirement: !ruby/object:Gem::Requirement
|
@@ -294,17 +306,22 @@ files:
|
|
294
306
|
- lib/pdk/cli/config/get.rb
|
295
307
|
- lib/pdk/cli/console.rb
|
296
308
|
- lib/pdk/cli/convert.rb
|
309
|
+
- lib/pdk/cli/env.rb
|
297
310
|
- lib/pdk/cli/errors.rb
|
298
311
|
- lib/pdk/cli/exec.rb
|
299
312
|
- lib/pdk/cli/exec/command.rb
|
300
313
|
- lib/pdk/cli/exec/interactive_command.rb
|
301
314
|
- lib/pdk/cli/exec_group.rb
|
315
|
+
- lib/pdk/cli/get.rb
|
316
|
+
- lib/pdk/cli/get/config.rb
|
302
317
|
- lib/pdk/cli/module.rb
|
303
318
|
- lib/pdk/cli/module/build.rb
|
304
319
|
- lib/pdk/cli/module/generate.rb
|
305
320
|
- lib/pdk/cli/new.rb
|
306
321
|
- lib/pdk/cli/new/class.rb
|
307
322
|
- lib/pdk/cli/new/defined_type.rb
|
323
|
+
- lib/pdk/cli/new/fact.rb
|
324
|
+
- lib/pdk/cli/new/function.rb
|
308
325
|
- lib/pdk/cli/new/module.rb
|
309
326
|
- lib/pdk/cli/new/provider.rb
|
310
327
|
- lib/pdk/cli/new/task.rb
|
@@ -313,6 +330,10 @@ files:
|
|
313
330
|
- lib/pdk/cli/release.rb
|
314
331
|
- lib/pdk/cli/release/prep.rb
|
315
332
|
- lib/pdk/cli/release/publish.rb
|
333
|
+
- lib/pdk/cli/remove.rb
|
334
|
+
- lib/pdk/cli/remove/config.rb
|
335
|
+
- lib/pdk/cli/set.rb
|
336
|
+
- lib/pdk/cli/set/config.rb
|
316
337
|
- lib/pdk/cli/test.rb
|
317
338
|
- lib/pdk/cli/test/unit.rb
|
318
339
|
- lib/pdk/cli/update.rb
|
@@ -322,10 +343,13 @@ files:
|
|
322
343
|
- lib/pdk/cli/util/option_normalizer.rb
|
323
344
|
- lib/pdk/cli/util/option_validator.rb
|
324
345
|
- lib/pdk/cli/util/spinner.rb
|
346
|
+
- lib/pdk/cli/util/update_manager_printer.rb
|
325
347
|
- lib/pdk/cli/validate.rb
|
326
348
|
- lib/pdk/config.rb
|
327
349
|
- lib/pdk/config/analytics_schema.json
|
328
350
|
- lib/pdk/config/errors.rb
|
351
|
+
- lib/pdk/config/ini_file.rb
|
352
|
+
- lib/pdk/config/ini_file_setting.rb
|
329
353
|
- lib/pdk/config/json.rb
|
330
354
|
- lib/pdk/config/json_schema_namespace.rb
|
331
355
|
- lib/pdk/config/json_schema_setting.rb
|
@@ -335,9 +359,15 @@ files:
|
|
335
359
|
- lib/pdk/config/validator.rb
|
336
360
|
- lib/pdk/config/yaml.rb
|
337
361
|
- lib/pdk/config/yaml_with_schema.rb
|
362
|
+
- lib/pdk/context.rb
|
363
|
+
- lib/pdk/context/control_repo.rb
|
364
|
+
- lib/pdk/context/module.rb
|
365
|
+
- lib/pdk/context/none.rb
|
338
366
|
- lib/pdk/control_repo.rb
|
339
367
|
- lib/pdk/generate.rb
|
340
368
|
- lib/pdk/generate/defined_type.rb
|
369
|
+
- lib/pdk/generate/fact.rb
|
370
|
+
- lib/pdk/generate/function.rb
|
341
371
|
- lib/pdk/generate/module.rb
|
342
372
|
- lib/pdk/generate/provider.rb
|
343
373
|
- lib/pdk/generate/puppet_class.rb
|
@@ -351,15 +381,20 @@ files:
|
|
351
381
|
- lib/pdk/module/convert.rb
|
352
382
|
- lib/pdk/module/metadata.rb
|
353
383
|
- lib/pdk/module/release.rb
|
354
|
-
- lib/pdk/module/template_dir.rb
|
355
|
-
- lib/pdk/module/template_dir/base.rb
|
356
|
-
- lib/pdk/module/template_dir/git.rb
|
357
|
-
- lib/pdk/module/template_dir/local.rb
|
358
384
|
- lib/pdk/module/update.rb
|
359
385
|
- lib/pdk/module/update_manager.rb
|
360
386
|
- lib/pdk/report.rb
|
361
387
|
- lib/pdk/report/event.rb
|
362
|
-
- lib/pdk/
|
388
|
+
- lib/pdk/template.rb
|
389
|
+
- lib/pdk/template/fetcher.rb
|
390
|
+
- lib/pdk/template/fetcher/git.rb
|
391
|
+
- lib/pdk/template/fetcher/local.rb
|
392
|
+
- lib/pdk/template/renderer.rb
|
393
|
+
- lib/pdk/template/renderer/v1.rb
|
394
|
+
- lib/pdk/template/renderer/v1/legacy_template_dir.rb
|
395
|
+
- lib/pdk/template/renderer/v1/renderer.rb
|
396
|
+
- lib/pdk/template/renderer/v1/template_file.rb
|
397
|
+
- lib/pdk/template/template_dir.rb
|
363
398
|
- lib/pdk/tests/unit.rb
|
364
399
|
- lib/pdk/util.rb
|
365
400
|
- lib/pdk/util/bundler.rb
|
@@ -367,6 +402,7 @@ files:
|
|
367
402
|
- lib/pdk/util/env.rb
|
368
403
|
- lib/pdk/util/filesystem.rb
|
369
404
|
- lib/pdk/util/git.rb
|
405
|
+
- lib/pdk/util/json_finder.rb
|
370
406
|
- lib/pdk/util/puppet_strings.rb
|
371
407
|
- lib/pdk/util/puppet_version.rb
|
372
408
|
- lib/pdk/util/ruby_version.rb
|
@@ -379,28 +415,34 @@ files:
|
|
379
415
|
- lib/pdk/util/windows/process.rb
|
380
416
|
- lib/pdk/util/windows/string.rb
|
381
417
|
- lib/pdk/validate.rb
|
382
|
-
- lib/pdk/validate/
|
383
|
-
- lib/pdk/validate/
|
384
|
-
- lib/pdk/validate/
|
385
|
-
- lib/pdk/validate/
|
386
|
-
- lib/pdk/validate/
|
387
|
-
- lib/pdk/validate/
|
388
|
-
- lib/pdk/validate/
|
389
|
-
- lib/pdk/validate/
|
390
|
-
- lib/pdk/validate/
|
391
|
-
- lib/pdk/validate/
|
392
|
-
- lib/pdk/validate/
|
393
|
-
- lib/pdk/validate/
|
394
|
-
- lib/pdk/validate/
|
395
|
-
- lib/pdk/validate/
|
396
|
-
- lib/pdk/validate/
|
418
|
+
- lib/pdk/validate/control_repo/control_repo_validator_group.rb
|
419
|
+
- lib/pdk/validate/control_repo/environment_conf_validator.rb
|
420
|
+
- lib/pdk/validate/external_command_validator.rb
|
421
|
+
- lib/pdk/validate/internal_ruby_validator.rb
|
422
|
+
- lib/pdk/validate/invokable_validator.rb
|
423
|
+
- lib/pdk/validate/metadata/metadata_json_lint_validator.rb
|
424
|
+
- lib/pdk/validate/metadata/metadata_syntax_validator.rb
|
425
|
+
- lib/pdk/validate/metadata/metadata_validator_group.rb
|
426
|
+
- lib/pdk/validate/puppet/puppet_epp_validator.rb
|
427
|
+
- lib/pdk/validate/puppet/puppet_lint_validator.rb
|
428
|
+
- lib/pdk/validate/puppet/puppet_syntax_validator.rb
|
429
|
+
- lib/pdk/validate/puppet/puppet_validator_group.rb
|
430
|
+
- lib/pdk/validate/ruby/ruby_rubocop_validator.rb
|
431
|
+
- lib/pdk/validate/ruby/ruby_validator_group.rb
|
432
|
+
- lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb
|
433
|
+
- lib/pdk/validate/tasks/tasks_name_validator.rb
|
434
|
+
- lib/pdk/validate/tasks/tasks_validator_group.rb
|
435
|
+
- lib/pdk/validate/validator.rb
|
436
|
+
- lib/pdk/validate/validator_group.rb
|
437
|
+
- lib/pdk/validate/yaml/yaml_syntax_validator.rb
|
438
|
+
- lib/pdk/validate/yaml/yaml_validator_group.rb
|
397
439
|
- lib/pdk/version.rb
|
398
440
|
- locales/config.yaml
|
399
441
|
- locales/pdk.pot
|
400
442
|
homepage: https://github.com/puppetlabs/pdk
|
401
443
|
licenses: []
|
402
444
|
metadata: {}
|
403
|
-
post_install_message:
|
445
|
+
post_install_message:
|
404
446
|
rdoc_options: []
|
405
447
|
require_paths:
|
406
448
|
- lib
|
@@ -408,15 +450,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
408
450
|
requirements:
|
409
451
|
- - ">="
|
410
452
|
- !ruby/object:Gem::Version
|
411
|
-
version: 2.
|
453
|
+
version: 2.4.0
|
412
454
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
413
455
|
requirements:
|
414
456
|
- - ">="
|
415
457
|
- !ruby/object:Gem::Version
|
416
458
|
version: '0'
|
417
459
|
requirements: []
|
418
|
-
rubygems_version: 3.
|
419
|
-
signing_key:
|
460
|
+
rubygems_version: 3.1.2
|
461
|
+
signing_key:
|
420
462
|
specification_version: 4
|
421
463
|
summary: A key part of the Puppet Development Kit, the shortest path to better modules
|
422
464
|
test_files: []
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Module
|
5
|
-
module TemplateDir
|
6
|
-
# Creates a TemplateDir object with the path or URL to the template
|
7
|
-
# and the block of code to run to be run while the template is available.
|
8
|
-
#
|
9
|
-
# The template directory is only guaranteed to be available on disk
|
10
|
-
# within the scope of the block passed to this method.
|
11
|
-
#
|
12
|
-
# @param uri [PDK::Util::TemplateURI] The path to a directory to use as the
|
13
|
-
# template or a URI to a git repository.
|
14
|
-
# @param module_metadata [Hash] A Hash containing the module metadata.
|
15
|
-
# Defaults to an empty Hash.
|
16
|
-
# @yieldparam self [PDK::Module::TemplateDir] The initialised object with
|
17
|
-
# the template available on disk.
|
18
|
-
#
|
19
|
-
# @example Using a git repository as a template
|
20
|
-
# PDK::Module::TemplateDir.with('https://github.com/puppetlabs/pdk-templates') do |t|
|
21
|
-
# t.render do |filename, content|
|
22
|
-
# File.open(filename, 'w') do |file|
|
23
|
-
# file.write(content)
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# @raise [ArgumentError] If no block is given to this method.
|
29
|
-
# @raise [PDK::CLI::FatalError] (see #clone_repo)
|
30
|
-
# @raise [ArgumentError] (see #validate_module_template!)
|
31
|
-
#
|
32
|
-
# @api public
|
33
|
-
def self.with(uri, module_metadata = {}, init = false)
|
34
|
-
unless block_given?
|
35
|
-
raise ArgumentError, _('%{class_name}.with must be passed a block.') % { class_name: name }
|
36
|
-
end
|
37
|
-
unless uri.is_a? PDK::Util::TemplateURI
|
38
|
-
raise ArgumentError, _('%{class_name}.with must be passed a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class, class_name: name }
|
39
|
-
end
|
40
|
-
|
41
|
-
if PDK::Util::Git.repo?(uri.bare_uri)
|
42
|
-
require 'pdk/module/template_dir/git'
|
43
|
-
PDK::Module::TemplateDir::Git.new(uri, module_metadata, init) { |value| yield value }
|
44
|
-
else
|
45
|
-
require 'pdk/module/template_dir/local'
|
46
|
-
PDK::Module::TemplateDir::Local.new(uri, module_metadata, init) { |value| yield value }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.moduleroot_dir(template_root_dir)
|
51
|
-
File.join(template_root_dir, 'moduleroot')
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.moduleroot_init(template_root_dir)
|
55
|
-
File.join(template_root_dir, 'moduleroot_init')
|
56
|
-
end
|
57
|
-
|
58
|
-
# Validate the content of the template directory.
|
59
|
-
#
|
60
|
-
# @raise [ArgumentError] If the specified path is not a directory.
|
61
|
-
# @raise [ArgumentError] If the template directory does not contain
|
62
|
-
# a directory called 'moduleroot'.
|
63
|
-
#
|
64
|
-
# @return [void]
|
65
|
-
#
|
66
|
-
# @api public
|
67
|
-
def self.validate_module_template!(template_root_dir)
|
68
|
-
# rubocop:disable Style/GuardClause
|
69
|
-
unless PDK::Util::Filesystem.directory?(template_root_dir)
|
70
|
-
require 'pdk/util'
|
71
|
-
|
72
|
-
if PDK::Util.package_install? && PDK::Util::Filesystem.fnmatch?(File.join(PDK::Util.package_cachedir, '*'), template_root_dir)
|
73
|
-
raise ArgumentError, _('The built-in template has substantially changed. Please run "pdk convert" on your module to continue.')
|
74
|
-
else
|
75
|
-
raise ArgumentError, _("The specified template '%{path}' is not a directory.") % { path: template_root_dir }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
unless PDK::Util::Filesystem.directory?(moduleroot_dir(template_root_dir))
|
80
|
-
raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot/' directory.") % { path: template_root_dir }
|
81
|
-
end
|
82
|
-
|
83
|
-
unless PDK::Util::Filesystem.directory?(moduleroot_init(template_root_dir))
|
84
|
-
# rubocop:disable Metrics/LineLength
|
85
|
-
raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot_init/' directory, which indicates you are using an older style of template. Before continuing please use the --template-url flag when running the pdk new commands to pass a new style template.") % { path: template_root_dir }
|
86
|
-
# rubocop:enable Metrics/LineLength
|
87
|
-
end
|
88
|
-
# rubocop:enable Style/GuardClause
|
89
|
-
end
|
90
|
-
|
91
|
-
# Get a list of template files in the template directory.
|
92
|
-
#
|
93
|
-
# @return [Hash{String=>String}] A hash of key file names and
|
94
|
-
# value locations.
|
95
|
-
#
|
96
|
-
# @api public
|
97
|
-
def self.files_in_template(dirs)
|
98
|
-
temp_paths = []
|
99
|
-
dirlocs = []
|
100
|
-
dirs.each do |dir|
|
101
|
-
raise ArgumentError, _("The directory '%{dir}' doesn't exist") % { dir: dir } unless PDK::Util::Filesystem.directory?(dir)
|
102
|
-
temp_paths += PDK::Util::Filesystem.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH).select do |template_path|
|
103
|
-
if PDK::Util::Filesystem.file?(template_path) && !PDK::Util::Filesystem.symlink?(template_path)
|
104
|
-
dirlocs << dir
|
105
|
-
end
|
106
|
-
end
|
107
|
-
temp_paths.map do |template_path|
|
108
|
-
template_path.sub!(%r{\A#{Regexp.escape(dir)}#{Regexp.escape(File::SEPARATOR)}}, '')
|
109
|
-
end
|
110
|
-
end
|
111
|
-
Hash[temp_paths.zip dirlocs]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Module
|
5
|
-
module TemplateDir
|
6
|
-
class Base
|
7
|
-
attr_accessor :module_metadata
|
8
|
-
attr_reader :uri
|
9
|
-
|
10
|
-
# Initialises the TemplateDir object with the path or URL to the template
|
11
|
-
# and the block of code to run to be run while the template is available.
|
12
|
-
#
|
13
|
-
# The template directory is only guaranteed to be available on disk
|
14
|
-
# within the scope of the block passed to this method.
|
15
|
-
#
|
16
|
-
# @param uri [PDK::Util::TemplateURI] The path to a directory to use as the
|
17
|
-
# template or a URI to a git repository.
|
18
|
-
# @param module_metadata [Hash] A Hash containing the module metadata.
|
19
|
-
# Defaults to an empty Hash.
|
20
|
-
# @yieldparam self [PDK::Module::TemplateDir] The initialised object with
|
21
|
-
# the template available on disk.
|
22
|
-
#
|
23
|
-
# @example Using a git repository as a template
|
24
|
-
# PDK::Module::TemplateDir::Base.new('https://github.com/puppetlabs/pdk-templates') do |t|
|
25
|
-
# t.render do |filename, content|
|
26
|
-
# File.open(filename, 'w') do |file|
|
27
|
-
# file.write(content)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# @raise [ArgumentError] If no block is given to this method.
|
33
|
-
# @raise [PDK::CLI::FatalError] (see #clone_repo)
|
34
|
-
# @raise [ArgumentError] (see #validate_module_template!)
|
35
|
-
#
|
36
|
-
# @api public
|
37
|
-
def initialize(uri, module_metadata = {}, init = false)
|
38
|
-
unless block_given?
|
39
|
-
raise ArgumentError, _('%{class_name} must be initialized with a block.') % { class_name: self.class.name }
|
40
|
-
end
|
41
|
-
unless uri.is_a? PDK::Util::TemplateURI
|
42
|
-
raise ArgumentError, _('%{class_name} must be initialized with a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class, class_name: self.class.name }
|
43
|
-
end
|
44
|
-
|
45
|
-
@path, @is_temporary_path = template_path(uri)
|
46
|
-
@uri = uri
|
47
|
-
|
48
|
-
@init = init
|
49
|
-
@moduleroot_dir = PDK::Module::TemplateDir.moduleroot_dir(@path)
|
50
|
-
@moduleroot_init = PDK::Module::TemplateDir.moduleroot_init(@path)
|
51
|
-
@dirs = [@moduleroot_dir]
|
52
|
-
@dirs << @moduleroot_init if @init
|
53
|
-
@object_dir = File.join(@path, 'object_templates')
|
54
|
-
|
55
|
-
PDK::Module::TemplateDir.validate_module_template!(@path)
|
56
|
-
|
57
|
-
@module_metadata = module_metadata
|
58
|
-
|
59
|
-
template_type = uri.default? ? 'default' : 'custom'
|
60
|
-
PDK.analytics.event('TemplateDir', 'initialize', label: template_type)
|
61
|
-
|
62
|
-
yield self
|
63
|
-
ensure
|
64
|
-
# If the the path is temporary, clean it up
|
65
|
-
if @is_temporary_path
|
66
|
-
PDK::Util::Filesystem.rm_rf(@path)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Retrieve identifying metadata for the template.
|
71
|
-
#
|
72
|
-
# For git repositories, this will return the URL to the repository and
|
73
|
-
# a reference to the HEAD.
|
74
|
-
#
|
75
|
-
# For plain fileystem directories, this will return the URL to the repository only.
|
76
|
-
#
|
77
|
-
# @return [Hash{String => String}] A hash of identifying metadata.
|
78
|
-
#
|
79
|
-
# @api public
|
80
|
-
# @abstract
|
81
|
-
def metadata
|
82
|
-
{
|
83
|
-
'pdk-version' => PDK::Util::Version.version_string,
|
84
|
-
'template-url' => nil,
|
85
|
-
'template-ref' => nil,
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
# Loop through the files in the template, yielding each rendered file to
|
90
|
-
# the supplied block.
|
91
|
-
#
|
92
|
-
# @yieldparam dest_path [String] The path of the destination file,
|
93
|
-
# relative to the root of the module.
|
94
|
-
# @yieldparam dest_content [String] The rendered content of the
|
95
|
-
# destination file.
|
96
|
-
#
|
97
|
-
# @raise [PDK::CLI::FatalError] If the template fails to render.
|
98
|
-
#
|
99
|
-
# @return [void]
|
100
|
-
#
|
101
|
-
# @api public
|
102
|
-
def render
|
103
|
-
require 'pdk/template_file'
|
104
|
-
|
105
|
-
PDK::Module::TemplateDir.files_in_template(@dirs).each do |template_file, template_loc|
|
106
|
-
template_file = template_file.to_s
|
107
|
-
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
108
|
-
dest_path = template_file.sub(%r{\.erb\Z}, '')
|
109
|
-
config = config_for(dest_path)
|
110
|
-
|
111
|
-
dest_status = if template_loc.start_with?(@moduleroot_init)
|
112
|
-
:init
|
113
|
-
else
|
114
|
-
:manage
|
115
|
-
end
|
116
|
-
|
117
|
-
if config['unmanaged']
|
118
|
-
dest_status = :unmanage
|
119
|
-
elsif config['delete']
|
120
|
-
dest_status = :delete
|
121
|
-
else
|
122
|
-
begin
|
123
|
-
dest_content = PDK::TemplateFile.new(File.join(template_loc, template_file), configs: config, template_dir: self).render
|
124
|
-
rescue => error
|
125
|
-
error_msg = _(
|
126
|
-
"Failed to render template '%{template}'\n" \
|
127
|
-
'%{exception}: %{message}',
|
128
|
-
) % { template: template_file, exception: error.class, message: error.message }
|
129
|
-
raise PDK::CLI::FatalError, error_msg
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
yield dest_path, dest_content, dest_status
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Searches the template directory for template files that can be used to
|
138
|
-
# render files for the specified object type.
|
139
|
-
#
|
140
|
-
# @param object_type [Symbol] The object type, e.g. (`:class`,
|
141
|
-
# `:defined_type`, `:fact`, etc).
|
142
|
-
#
|
143
|
-
# @return [Hash{Symbol => String}] if the templates are available in the
|
144
|
-
# template dir, otherwise `nil`. The returned hash can contain two keys,
|
145
|
-
# :object contains the path on disk to the template for the object, :spec
|
146
|
-
# contains the path on disk to the template for the object's spec file
|
147
|
-
# (if available).
|
148
|
-
#
|
149
|
-
# @api public
|
150
|
-
def object_template_for(object_type)
|
151
|
-
object_path = File.join(@object_dir, "#{object_type}.erb")
|
152
|
-
type_path = File.join(@object_dir, "#{object_type}_type.erb")
|
153
|
-
device_path = File.join(@object_dir, "#{object_type}_device.erb")
|
154
|
-
spec_path = File.join(@object_dir, "#{object_type}_spec.erb")
|
155
|
-
type_spec_path = File.join(@object_dir, "#{object_type}_type_spec.erb")
|
156
|
-
|
157
|
-
if PDK::Util::Filesystem.file?(object_path) && PDK::Util::Filesystem.readable?(object_path)
|
158
|
-
result = { object: object_path }
|
159
|
-
result[:type] = type_path if PDK::Util::Filesystem.file?(type_path) && PDK::Util::Filesystem.readable?(type_path)
|
160
|
-
result[:spec] = spec_path if PDK::Util::Filesystem.file?(spec_path) && PDK::Util::Filesystem.readable?(spec_path)
|
161
|
-
result[:device] = device_path if PDK::Util::Filesystem.file?(device_path) && PDK::Util::Filesystem.readable?(device_path)
|
162
|
-
result[:type_spec] = type_spec_path if PDK::Util::Filesystem.file?(type_spec_path) && PDK::Util::Filesystem.readable?(type_spec_path)
|
163
|
-
result
|
164
|
-
else
|
165
|
-
nil
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# Generate a hash of data to be used when rendering object templates.
|
170
|
-
#
|
171
|
-
# Read `config_defaults.yml` from the root of the template directory (if
|
172
|
-
# it exists) build a hash of values from the value of the `:global`
|
173
|
-
# key.
|
174
|
-
#
|
175
|
-
# @return [Hash] The data that will be available to the template via the
|
176
|
-
# `@configs` instance variable.
|
177
|
-
#
|
178
|
-
# @api private
|
179
|
-
def object_config
|
180
|
-
config_for(nil)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Generate a hash of data to be used when rendering the specified
|
184
|
-
# template.
|
185
|
-
#
|
186
|
-
# @param dest_path [String] The destination path of the file that the
|
187
|
-
# data is for, relative to the root of the module.
|
188
|
-
#
|
189
|
-
# @return [Hash] The data that will be available to the template via the
|
190
|
-
# `@configs` instance variable.
|
191
|
-
#
|
192
|
-
# @api private
|
193
|
-
def config_for(dest_path, sync_config_path = nil)
|
194
|
-
require 'pdk/util'
|
195
|
-
require 'pdk/analytics'
|
196
|
-
|
197
|
-
module_root = PDK::Util.module_root
|
198
|
-
sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil?
|
199
|
-
config_path = File.join(@path, 'config_defaults.yml')
|
200
|
-
|
201
|
-
if @config.nil?
|
202
|
-
require 'deep_merge'
|
203
|
-
conf_defaults = read_config(config_path)
|
204
|
-
@sync_config = read_config(sync_config_path) unless sync_config_path.nil?
|
205
|
-
@config = conf_defaults
|
206
|
-
@config.deep_merge!(@sync_config, knockout_prefix: '---') unless @sync_config.nil?
|
207
|
-
end
|
208
|
-
file_config = @config.fetch(:global, {})
|
209
|
-
file_config['module_metadata'] = @module_metadata
|
210
|
-
file_config.merge!(@config.fetch(dest_path, {})) unless dest_path.nil?
|
211
|
-
file_config.merge!(@config).tap do |c|
|
212
|
-
if uri.default?
|
213
|
-
file_value = if c['unmanaged']
|
214
|
-
'unmanaged'
|
215
|
-
elsif c['delete']
|
216
|
-
'deleted'
|
217
|
-
elsif @sync_config && @sync_config.key?(dest_path)
|
218
|
-
'customized'
|
219
|
-
else
|
220
|
-
'default'
|
221
|
-
end
|
222
|
-
|
223
|
-
PDK.analytics.event('TemplateDir', 'file', label: dest_path, value: file_value)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
# Generates a hash of data from a given yaml file location.
|
229
|
-
#
|
230
|
-
# @param loc [String] The path of the yaml config file.
|
231
|
-
#
|
232
|
-
# @warn If the specified path is not a valid yaml file. Returns an empty Hash
|
233
|
-
# if so.
|
234
|
-
#
|
235
|
-
# @return [Hash] The data that has been read in from the given yaml file.
|
236
|
-
#
|
237
|
-
# @api private
|
238
|
-
def read_config(loc)
|
239
|
-
if PDK::Util::Filesystem.file?(loc) && PDK::Util::Filesystem.readable?(loc)
|
240
|
-
require 'yaml'
|
241
|
-
|
242
|
-
begin
|
243
|
-
YAML.safe_load(PDK::Util::Filesystem.read_file(loc), [], [], true)
|
244
|
-
rescue Psych::SyntaxError => e
|
245
|
-
PDK.logger.warn _("'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}") % {
|
246
|
-
file: loc,
|
247
|
-
problem: e.problem,
|
248
|
-
context: e.context,
|
249
|
-
line: e.line,
|
250
|
-
column: e.column,
|
251
|
-
}
|
252
|
-
{}
|
253
|
-
end
|
254
|
-
else
|
255
|
-
{}
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
# @return [Path, Boolean] The path to the Template and whether this path is temporary. Temporary paths
|
260
|
-
# are deleted once the object has yielded
|
261
|
-
# @api private
|
262
|
-
def template_path(uri)
|
263
|
-
[uri.shell_path, false]
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|