pdk 1.17.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +148 -11
  3. data/README.md +1 -1
  4. data/lib/pdk.rb +1 -1
  5. data/lib/pdk/cli.rb +7 -1
  6. data/lib/pdk/cli/convert.rb +7 -9
  7. data/lib/pdk/cli/env.rb +52 -0
  8. data/lib/pdk/cli/exec/command.rb +11 -1
  9. data/lib/pdk/cli/new.rb +2 -0
  10. data/lib/pdk/cli/new/class.rb +2 -1
  11. data/lib/pdk/cli/new/defined_type.rb +2 -1
  12. data/lib/pdk/cli/new/fact.rb +29 -0
  13. data/lib/pdk/cli/new/function.rb +29 -0
  14. data/lib/pdk/cli/new/provider.rb +2 -1
  15. data/lib/pdk/cli/new/task.rb +2 -1
  16. data/lib/pdk/cli/new/test.rb +2 -1
  17. data/lib/pdk/cli/new/transport.rb +2 -1
  18. data/lib/pdk/cli/release.rb +1 -1
  19. data/lib/pdk/cli/release/publish.rb +11 -1
  20. data/lib/pdk/cli/remove.rb +20 -0
  21. data/lib/pdk/cli/remove/config.rb +80 -0
  22. data/lib/pdk/cli/set.rb +20 -0
  23. data/lib/pdk/cli/set/config.rb +119 -0
  24. data/lib/pdk/cli/update.rb +6 -8
  25. data/lib/pdk/cli/util.rb +1 -0
  26. data/lib/pdk/cli/util/option_validator.rb +6 -0
  27. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  28. data/lib/pdk/config.rb +96 -13
  29. data/lib/pdk/context.rb +8 -5
  30. data/lib/pdk/generate/defined_type.rb +25 -32
  31. data/lib/pdk/generate/fact.rb +25 -0
  32. data/lib/pdk/generate/function.rb +48 -0
  33. data/lib/pdk/generate/module.rb +11 -10
  34. data/lib/pdk/generate/provider.rb +15 -64
  35. data/lib/pdk/generate/puppet_class.rb +25 -31
  36. data/lib/pdk/generate/puppet_object.rb +83 -187
  37. data/lib/pdk/generate/task.rb +28 -46
  38. data/lib/pdk/generate/transport.rb +20 -74
  39. data/lib/pdk/module.rb +1 -1
  40. data/lib/pdk/module/convert.rb +43 -23
  41. data/lib/pdk/module/metadata.rb +6 -2
  42. data/lib/pdk/module/release.rb +8 -2
  43. data/lib/pdk/module/update.rb +7 -11
  44. data/lib/pdk/module/update_manager.rb +7 -0
  45. data/lib/pdk/report.rb +3 -3
  46. data/lib/pdk/report/event.rb +8 -2
  47. data/lib/pdk/template.rb +59 -0
  48. data/lib/pdk/template/fetcher.rb +98 -0
  49. data/lib/pdk/template/fetcher/git.rb +85 -0
  50. data/lib/pdk/template/fetcher/local.rb +28 -0
  51. data/lib/pdk/template/renderer.rb +96 -0
  52. data/lib/pdk/template/renderer/v1.rb +25 -0
  53. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
  54. data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
  55. data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
  56. data/lib/pdk/template/template_dir.rb +67 -0
  57. data/lib/pdk/tests/unit.rb +8 -1
  58. data/lib/pdk/util.rb +4 -35
  59. data/lib/pdk/util/bundler.rb +1 -1
  60. data/lib/pdk/util/changelog_generator.rb +20 -3
  61. data/lib/pdk/util/json_finder.rb +85 -0
  62. data/lib/pdk/util/puppet_strings.rb +3 -3
  63. data/lib/pdk/util/puppet_version.rb +2 -2
  64. data/lib/pdk/util/ruby_version.rb +5 -1
  65. data/lib/pdk/util/template_uri.rb +9 -11
  66. data/lib/pdk/util/vendored_file.rb +1 -2
  67. data/lib/pdk/validate.rb +17 -10
  68. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  69. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  70. data/lib/pdk/validate/invokable_validator.rb +8 -4
  71. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +1 -1
  72. data/lib/pdk/validate/validator.rb +7 -0
  73. data/lib/pdk/validate/validator_group.rb +1 -0
  74. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +2 -2
  75. data/lib/pdk/version.rb +1 -1
  76. data/locales/pdk.pot +356 -228
  77. metadata +65 -28
  78. data/lib/pdk/module/template_dir.rb +0 -115
  79. data/lib/pdk/module/template_dir/base.rb +0 -268
  80. data/lib/pdk/module/template_dir/git.rb +0 -91
  81. data/lib/pdk/module/template_dir/local.rb +0 -21
  82. data/lib/pdk/template_file.rb +0 -96
@@ -1,91 +0,0 @@
1
- require 'pdk'
2
- require 'pdk/module/template_dir/base'
3
-
4
- module PDK
5
- module Module
6
- module TemplateDir
7
- class Git < Base
8
- def template_path(uri)
9
- # We don't do a checkout of local-path repos. There are lots of edge
10
- # cases or user un-expectations.
11
- if PDK::Util::Git.work_tree?(uri.shell_path)
12
- PDK.logger.warn _("Repository '%{repo}' has a work-tree; skipping git reset.") % {
13
- repo: uri.shell_path,
14
- }
15
- [uri.shell_path, false]
16
- else
17
- # This is either a bare local repo or a remote. either way it needs cloning.
18
- # A "remote" can also be git repo on the local filsystem.
19
- [clone_template_repo(uri), true]
20
- end
21
- end
22
-
23
- # For git repositories, this will return the URL to the repository and
24
- # a reference to the HEAD.
25
- #
26
- # @return [Hash{String => String}] A hash of identifying metadata.
27
- def metadata
28
- super.merge('template-url' => uri.metadata_format, 'template-ref' => cache_template_ref(@path))
29
- end
30
-
31
- private
32
-
33
- def cache_template_ref(path, ref = nil)
34
- require 'pdk/util/git'
35
-
36
- @template_ref ||= PDK::Util::Git.describe(File.join(path, '.git'), ref)
37
- end
38
-
39
- # @return [String] Path to working directory into which template repo has been cloned and reset
40
- #
41
- # @raise [PDK::CLI::FatalError] If unable to clone the given origin_repo into a tempdir.
42
- # @raise [PDK::CLI::FatalError] If reset HEAD of the cloned repo to desired ref.
43
- #
44
- # @api private
45
- def clone_template_repo(uri)
46
- # @todo When switching this over to using rugged, cache the cloned
47
- # template repo in `%AppData%` or `$XDG_CACHE_DIR` and update before
48
- # use.
49
- require 'pdk/util'
50
- require 'pdk/util/git'
51
-
52
- temp_dir = PDK::Util.make_tmpdir_name('pdk-templates')
53
- origin_repo = uri.bare_uri
54
- git_ref = uri.uri_fragment
55
-
56
- clone_result = PDK::Util::Git.git('clone', origin_repo, temp_dir)
57
-
58
- if clone_result[:exit_code].zero?
59
- checkout_template_ref(temp_dir, git_ref)
60
- else
61
- PDK.logger.error clone_result[:stdout]
62
- PDK.logger.error clone_result[:stderr]
63
- raise PDK::CLI::FatalError, _("Unable to clone git repository at '%{repo}' into '%{dest}'.") % { repo: origin_repo, dest: temp_dir }
64
- end
65
-
66
- PDK::Util.canonical_path(temp_dir)
67
- end
68
-
69
- # @api private
70
- def checkout_template_ref(path, ref)
71
- require 'pdk/util/git'
72
-
73
- if PDK::Util::Git.work_dir_clean?(path)
74
- Dir.chdir(path) do
75
- full_ref = PDK::Util::Git.ls_remote(path, ref)
76
- cache_template_ref(path, full_ref)
77
- reset_result = PDK::Util::Git.git('reset', '--hard', full_ref)
78
- return if reset_result[:exit_code].zero?
79
-
80
- PDK.logger.error reset_result[:stdout]
81
- PDK.logger.error reset_result[:stderr]
82
- raise PDK::CLI::FatalError, _("Unable to checkout '%{ref}' of git repository at '%{path}'.") % { ref: ref, path: path }
83
- end
84
- else
85
- PDK.logger.warn _("Uncommitted changes found when attempting to checkout '%{ref}' of git repository at '%{path}'; skipping git reset.") % { ref: ref, path: path }
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,21 +0,0 @@
1
- require 'pdk'
2
- require 'pdk/module/template_dir/base'
3
-
4
- module PDK
5
- module Module
6
- module TemplateDir
7
- class Local < Base
8
- def template_path(uri)
9
- [uri.shell_path, false]
10
- end
11
-
12
- # For plain fileystem directories, this will return the URL to the repository only.
13
- #
14
- # @return [Hash{String => String}] A hash of identifying metadata.
15
- def metadata
16
- super.merge('template-url' => uri.bare_uri)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,96 +0,0 @@
1
- require 'ostruct'
2
- require 'pdk'
3
-
4
- module PDK
5
- class TemplateFile < OpenStruct
6
- # Initialises the TemplateFile object with the path to the template file
7
- # and the data to be used when rendering the template.
8
- #
9
- # @param template_file [String] The path on disk to the template file.
10
- # @param data [Hash{Symbol => Object}] The data that should be provided to
11
- # the template when rendering.
12
- # @option data [Object] :configs The value of this key will be provided to
13
- # the template as an instance variable `@configs` in order to maintain
14
- # compatibility with modulesync.
15
- #
16
- # @api public
17
- def initialize(template_file, data = {})
18
- @template_file = template_file
19
-
20
- if data.key?(:configs)
21
- @configs = data[:configs]
22
- end
23
-
24
- super(data)
25
- end
26
-
27
- # Renders the template by calling the appropriate engine based on the file
28
- # extension.
29
- #
30
- # If the template has an `.erb` extension, the content of the template
31
- # file will be treated as an ERB template. All other extensions are treated
32
- # as plain text.
33
- #
34
- # @return [String] The rendered template
35
- #
36
- # @raise (see #template_content)
37
- #
38
- # @api public
39
- def render
40
- case File.extname(@template_file)
41
- when '.erb'
42
- render_erb
43
- else
44
- render_plain
45
- end
46
- end
47
-
48
- def config_for(path)
49
- return unless respond_to?(:template_dir)
50
-
51
- template_dir.config_for(path)
52
- end
53
-
54
- private
55
-
56
- # Reads the content of the template file into memory.
57
- #
58
- # @return [String] The content of the template file.
59
- #
60
- # @raise [ArgumentError] If the template file does not exist or can not be
61
- # read.
62
- #
63
- # @api private
64
- def template_content
65
- if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
66
- return PDK::Util::Filesystem.read_file(@template_file)
67
- end
68
-
69
- raise ArgumentError, _("'%{template}' is not a readable file") % { template: @template_file }
70
- end
71
-
72
- # Renders the content of the template file as an ERB template.
73
- #
74
- # @return [String] The rendered template.
75
- #
76
- # @raise (see #template_content)
77
- #
78
- # @api private
79
- def render_erb
80
- renderer = ERB.new(template_content, nil, '-')
81
- renderer.filename = @template_file
82
- renderer.result(binding)
83
- end
84
-
85
- # Renders the content of the template file as plain text.
86
- #
87
- # @return [String] The rendered template.
88
- #
89
- # @raise (see #template_content)
90
- #
91
- # @api private
92
- def render_plain
93
- template_content
94
- end
95
- end
96
- end