pdk 2.7.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +10 -50
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +3 -5
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +22 -14
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +11 -7
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +21 -68
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +13 -21
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -1,51 +1,53 @@
1
- module PDK::CLI
2
- @new_define_cmd = @new_cmd.define_command do
3
- name 'test'
4
- usage 'test [options] <name>'
5
- summary 'Create a new test for the object named <name>'
6
- flag :u, :unit, 'Create a new unit test.'
7
- PDK::CLI.puppet_version_options(self)
8
- PDK::CLI.puppet_dev_option(self)
9
-
10
- run do |opts, args, _cmd|
11
- require 'pdk/util/puppet_strings'
12
- require 'pdk/util/bundler'
13
-
14
- PDK::CLI::Util.validate_puppet_version_opts(opts)
15
- PDK::CLI::Util.ensure_in_module!(
16
- message: 'Tests can only be created from inside a valid module directory.',
17
- log_level: :info,
18
- )
19
-
20
- object_name = args[0]
21
-
22
- if object_name.nil? || object_name.empty?
23
- puts command.help
24
- exit 1
25
- end
26
-
27
- unless opts[:unit]
28
- # At a future time, we'll replace this conditional with an interactive
29
- # question to choose the test type.
30
- PDK.logger.info 'Test type not specified, assuming unit.'
31
- opts[:unit] = true
32
- end
33
-
34
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
35
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
36
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
37
-
38
- begin
39
- generator, obj = PDK::Util::PuppetStrings.find_object(object_name)
40
-
41
- PDK::CLI::Util.analytics_screen_view('new_test', opts)
42
-
43
- updates = generator.new(PDK.context, obj['name'], opts.merge(spec_only: true)).run
44
- PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
45
- rescue PDK::Util::PuppetStrings::NoObjectError
46
- raise PDK::CLI::ExitWithError, 'Unable to find anything called "%{object}" to generate unit tests for.' % { object: object_name }
47
- rescue PDK::Util::PuppetStrings::NoGeneratorError => e
48
- raise PDK::CLI::ExitWithError, 'PDK does not support generating unit tests for "%{object_type}" objects.' % { object_type: e.message }
1
+ module PDK
2
+ module CLI
3
+ @new_define_cmd = @new_cmd.define_command do
4
+ name 'test'
5
+ usage 'test [options] <name>'
6
+ summary 'Create a new test for the object named <name>'
7
+ flag :u, :unit, 'Create a new unit test.'
8
+ PDK::CLI.puppet_version_options(self)
9
+ PDK::CLI.puppet_dev_option(self)
10
+
11
+ run do |opts, args, _cmd|
12
+ require 'pdk/util/puppet_strings'
13
+ require 'pdk/util/bundler'
14
+
15
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
16
+ PDK::CLI::Util.ensure_in_module!(
17
+ message: 'Tests can only be created from inside a valid module directory.',
18
+ log_level: :info
19
+ )
20
+
21
+ object_name = args[0]
22
+
23
+ if object_name.nil? || object_name.empty?
24
+ puts command.help
25
+ exit 1
26
+ end
27
+
28
+ unless opts[:unit]
29
+ # At a future time, we'll replace this conditional with an interactive
30
+ # question to choose the test type.
31
+ PDK.logger.info 'Test type not specified, assuming unit.'
32
+ opts[:unit] = true
33
+ end
34
+
35
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
36
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
37
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
38
+
39
+ begin
40
+ generator, obj = PDK::Util::PuppetStrings.find_object(object_name)
41
+
42
+ PDK::CLI::Util.analytics_screen_view('new_test', opts)
43
+
44
+ updates = generator.new(PDK.context, obj['name'], opts.merge(spec_only: true)).run
45
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
46
+ rescue PDK::Util::PuppetStrings::NoObjectError
47
+ raise PDK::CLI::ExitWithError, format('Unable to find anything called "%{object}" to generate unit tests for.', object: object_name)
48
+ rescue PDK::Util::PuppetStrings::NoGeneratorError => e
49
+ raise PDK::CLI::ExitWithError, format('PDK does not support generating unit tests for "%{object_type}" objects.', object_type: e.message)
50
+ end
49
51
  end
50
52
  end
51
53
  end
@@ -1,27 +1,27 @@
1
- module PDK::CLI
2
- @new_transport_cmd = @new_cmd.define_command do
3
- name 'transport'
4
- usage 'transport [options] <name>'
5
- summary '[experimental] Create a new ruby transport named <name> using given options'
1
+ module PDK
2
+ module CLI
3
+ @new_transport_cmd = @new_cmd.define_command do
4
+ name 'transport'
5
+ usage 'transport [options] <name>'
6
+ summary '[experimental] Create a new ruby transport named <name> using given options'
6
7
 
7
- run do |opts, args, _cmd|
8
- PDK::CLI::Util.ensure_in_module!
8
+ run do |opts, args, _cmd|
9
+ PDK::CLI::Util.ensure_in_module!
9
10
 
10
- transport_name = args[0]
11
+ transport_name = args[0]
11
12
 
12
- if transport_name.nil? || transport_name.empty?
13
- puts command.help
14
- exit 1
15
- end
13
+ if transport_name.nil? || transport_name.empty?
14
+ puts command.help
15
+ exit 1
16
+ end
16
17
 
17
- unless Util::OptionValidator.valid_transport_name?(transport_name)
18
- raise PDK::CLI::ExitWithError, "'%{name}' is not a valid transport name" % { name: transport_name }
19
- end
18
+ raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid transport name", name: transport_name) unless Util::OptionValidator.valid_transport_name?(transport_name)
20
19
 
21
- require 'pdk/generate/transport'
20
+ require 'pdk/generate/transport'
22
21
 
23
- updates = PDK::Generate::Transport.new(PDK.context, transport_name, opts).run
24
- PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
22
+ updates = PDK::Generate::Transport.new(PDK.context, transport_name, opts).run
23
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
24
+ end
25
25
  end
26
26
  end
27
27
  end
data/lib/pdk/cli/new.rb CHANGED
@@ -1,13 +1,15 @@
1
- module PDK::CLI
2
- @new_cmd = @base_cmd.define_command do
3
- name 'new'
4
- usage 'new <thing> [options]'
5
- summary 'create a new module, etc.'
6
- description 'Creates a new <thing> using relevant options.'
7
- default_subcommand 'help'
8
- end
1
+ module PDK
2
+ module CLI
3
+ @new_cmd = @base_cmd.define_command do
4
+ name 'new'
5
+ usage 'new <thing> [options]'
6
+ summary 'create a new module, etc.'
7
+ description 'Creates a new <thing> using relevant options.'
8
+ default_subcommand 'help'
9
+ end
9
10
 
10
- @new_cmd.add_command Cri::Command.new_basic_help
11
+ @new_cmd.add_command Cri::Command.new_basic_help
12
+ end
11
13
  end
12
14
 
13
15
  require 'pdk/cli/new/class'
@@ -1,39 +1,41 @@
1
1
  require 'pdk/cli/release'
2
2
 
3
- module PDK::CLI
4
- @release_prep_cmd = @release_cmd.define_command do
5
- name 'prep'
6
- usage 'prep [options]'
7
- summary '(Experimental) Performs all the pre-release checks to ensure module is ready to be released'
3
+ module PDK
4
+ module CLI
5
+ @release_prep_cmd = @release_cmd.define_command do
6
+ name 'prep'
7
+ usage 'prep [options]'
8
+ summary '(Experimental) Performs all the pre-release checks to ensure module is ready to be released'
8
9
 
9
- flag nil, :force, 'Prepare the module automatically, with no prompts.'
10
- flag nil, :'skip-validation', 'Skips the module validation check.'
11
- flag nil, :'skip-changelog', 'Skips the automatic changelog generation.'
12
- flag nil, :'skip-dependency', 'Skips the module dependency check.'
13
- flag nil, :'skip-documentation', 'Skips the documentation update.'
10
+ flag nil, :force, 'Prepare the module automatically, with no prompts.'
11
+ flag nil, :'skip-validation', 'Skips the module validation check.'
12
+ flag nil, :'skip-changelog', 'Skips the automatic changelog generation.'
13
+ flag nil, :'skip-dependency', 'Skips the module dependency check.'
14
+ flag nil, :'skip-documentation', 'Skips the documentation update.'
14
15
 
15
- option nil, :version, 'Update the module to the specified version prior to release. When not specified, the new version will be computed from the Changelog where possible.',
16
- argument: :required
16
+ option nil, :version, 'Update the module to the specified version prior to release. When not specified, the new version will be computed from the Changelog where possible.',
17
+ argument: :required
17
18
 
18
- run do |opts, _args, cmd|
19
- # Make sure build is being run in a valid module directory with a metadata.json
20
- PDK::CLI::Util.ensure_in_module!(
21
- message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
22
- log_level: :info,
23
- )
19
+ run do |opts, _args, cmd|
20
+ # Make sure build is being run in a valid module directory with a metadata.json
21
+ PDK::CLI::Util.ensure_in_module!(
22
+ message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
23
+ log_level: :info
24
+ )
24
25
 
25
- opts[:'skip-build'] = true
26
- opts[:'skip-publish'] = true
26
+ opts[:'skip-build'] = true
27
+ opts[:'skip-publish'] = true
27
28
 
28
- Release.prepare_interview(opts) unless opts[:force]
29
+ Release.prepare_interview(opts) unless opts[:force]
29
30
 
30
- Release.send_analytics("release #{cmd.name}", opts)
31
+ Release.send_analytics("release #{cmd.name}", opts)
31
32
 
32
- release = PDK::Module::Release.new(nil, opts)
33
+ release = PDK::Module::Release.new(nil, opts)
33
34
 
34
- Release.module_compatibility_checks!(release, opts)
35
+ Release.module_compatibility_checks!(release, opts)
35
36
 
36
- release.run
37
+ release.run
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -1,46 +1,48 @@
1
1
  require 'pdk/cli/release'
2
2
 
3
- module PDK::CLI
4
- @release_publish_cmd = @release_cmd.define_command do
5
- name 'publish'
6
- usage 'publish [options] <tarball>'
7
- summary '(Experimental) Publishes the module <tarball> to the Forge.'
8
-
9
- flag nil, :force, 'Publish the module automatically, with no prompts.'
10
-
11
- option nil, :'forge-upload-url', 'Set forge upload url path.',
12
- argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
13
-
14
- option nil, :'forge-token', 'Set Forge API token (you may also set via environment variable PDK_FORGE_TOKEN)', argument: :required
15
-
16
- run do |opts, _args, cmd|
17
- # Make sure build is being run in a valid module directory with a metadata.json
18
- PDK::CLI::Util.ensure_in_module!(
19
- message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
20
- log_level: :info,
21
- )
22
-
23
- opts[:'skip-validation'] = true
24
- opts[:'skip-changelog'] = true
25
- opts[:'skip-dependency'] = true
26
- opts[:'skip-documentation'] = true
27
- opts[:'skip-build'] = true
28
- opts[:'skip-versionset'] = true
29
- opts[:force] = true unless PDK::CLI::Util.interactive?
30
- opts[:'forge-token'] ||= PDK::Util::Env['PDK_FORGE_TOKEN']
31
-
32
- if opts[:'forge-token'].nil? || opts[:'forge-token'].empty?
33
- PDK.logger.error 'You must supply a Forge API token either via `--forge-token` option or PDK_FORGE_TOKEN environment variable.'
34
- exit 1
35
- end
3
+ module PDK
4
+ module CLI
5
+ @release_publish_cmd = @release_cmd.define_command do
6
+ name 'publish'
7
+ usage 'publish [options] <tarball>'
8
+ summary '(Experimental) Publishes the module <tarball> to the Forge.'
9
+
10
+ flag nil, :force, 'Publish the module automatically, with no prompts.'
11
+
12
+ option nil, :'forge-upload-url', 'Set forge upload url path.',
13
+ argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
14
+
15
+ option nil, :'forge-token', 'Set Forge API token (you may also set via environment variable PDK_FORGE_TOKEN)', argument: :required
36
16
 
37
- Release.prepare_publish_interview(TTY::Prompt.new(help_color: :cyan), opts) unless opts[:force]
17
+ run do |opts, _args, cmd|
18
+ # Make sure build is being run in a valid module directory with a metadata.json
19
+ PDK::CLI::Util.ensure_in_module!(
20
+ message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
21
+ log_level: :info
22
+ )
38
23
 
39
- Release.send_analytics("release #{cmd.name}", opts)
24
+ opts[:'skip-validation'] = true
25
+ opts[:'skip-changelog'] = true
26
+ opts[:'skip-dependency'] = true
27
+ opts[:'skip-documentation'] = true
28
+ opts[:'skip-build'] = true
29
+ opts[:'skip-versionset'] = true
30
+ opts[:force] = true unless PDK::CLI::Util.interactive?
31
+ opts[:'forge-token'] ||= PDK::Util::Env['PDK_FORGE_TOKEN']
40
32
 
41
- release = PDK::Module::Release.new(nil, opts)
33
+ if opts[:'forge-token'].nil? || opts[:'forge-token'].empty?
34
+ PDK.logger.error 'You must supply a Forge API token either via `--forge-token` option or PDK_FORGE_TOKEN environment variable.'
35
+ exit 1
36
+ end
42
37
 
43
- release.run
38
+ Release.prepare_publish_interview(TTY::Prompt.new(help_color: :cyan), opts) unless opts[:force]
39
+
40
+ Release.send_analytics("release #{cmd.name}", opts)
41
+
42
+ release = PDK::Module::Release.new(nil, opts)
43
+
44
+ release.run
45
+ end
44
46
  end
45
47
  end
46
48
  end