pdk 2.4.0 → 2.6.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 +803 -1329
- data/LICENSE +201 -201
- data/README.md +165 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -293
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -194
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -46
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -390
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -260
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -137
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -85
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -278
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -228
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2111 -2094
- metadata +3 -3
@@ -1,116 +1,116 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Template
|
5
|
-
module Renderer
|
6
|
-
module V1
|
7
|
-
# The old templating code in the PDK passed through a TemplateDir object. This class mimics the methods
|
8
|
-
# of that old class so that existing custom templates will still function with the newer refactor templating code.
|
9
|
-
# Methods which have no use in custom templates exist but do no nothing, for example `def render; end`
|
10
|
-
#
|
11
|
-
# @see https://raw.githubusercontent.com/puppetlabs/pdk/4ffd58062c77ad1e54d2fe16b16015f7207bcee8/lib/pdk/module/template_dir/base.rb
|
12
|
-
# :nocov: This class is tested in the packaging and acceptance testing suites
|
13
|
-
class LegacyTemplateDir
|
14
|
-
attr_accessor :module_metadata
|
15
|
-
attr_reader :uri
|
16
|
-
|
17
|
-
def initialize(context, uri, path, module_metadata = {})
|
18
|
-
@uri = uri
|
19
|
-
@module_metadata = module_metadata
|
20
|
-
@context = context
|
21
|
-
@path = path
|
22
|
-
end
|
23
|
-
|
24
|
-
def metadata; end
|
25
|
-
|
26
|
-
def render; end
|
27
|
-
|
28
|
-
def object_template_for; end
|
29
|
-
|
30
|
-
def object_config
|
31
|
-
config_for(nil)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Generate a hash of data to be used when rendering the specified
|
35
|
-
# template.
|
36
|
-
#
|
37
|
-
# @param dest_path [String] The destination path of the file that the
|
38
|
-
# data is for, relative to the root of the module.
|
39
|
-
#
|
40
|
-
# @return [Hash] The data that will be available to the template via the
|
41
|
-
# `@configs` instance variable.
|
42
|
-
#
|
43
|
-
# @api private
|
44
|
-
def config_for(dest_path, sync_config_path = nil)
|
45
|
-
require 'pdk/util'
|
46
|
-
require 'pdk/analytics'
|
47
|
-
|
48
|
-
module_root = PDK::Util.module_root
|
49
|
-
sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil?
|
50
|
-
config_path = File.join(@path, 'config_defaults.yml')
|
51
|
-
|
52
|
-
if @config.nil?
|
53
|
-
require 'deep_merge'
|
54
|
-
conf_defaults = read_config(config_path)
|
55
|
-
@sync_config = read_config(sync_config_path) unless sync_config_path.nil?
|
56
|
-
@config = conf_defaults
|
57
|
-
@config.deep_merge!(@sync_config, knockout_prefix: '---') unless @sync_config.nil?
|
58
|
-
end
|
59
|
-
file_config = @config.fetch(:global, {})
|
60
|
-
file_config['module_metadata'] = @module_metadata
|
61
|
-
file_config.merge!(@config.fetch(dest_path, {})) unless dest_path.nil?
|
62
|
-
file_config.merge!(@config).tap do |c|
|
63
|
-
if uri.default?
|
64
|
-
file_value = if c['unmanaged']
|
65
|
-
'unmanaged'
|
66
|
-
elsif c['delete']
|
67
|
-
'deleted'
|
68
|
-
elsif @sync_config && @sync_config.key?(dest_path)
|
69
|
-
'customized'
|
70
|
-
else
|
71
|
-
'default'
|
72
|
-
end
|
73
|
-
|
74
|
-
PDK.analytics.event('TemplateDir', 'file', label: dest_path, value: file_value)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# Generates a hash of data from a given yaml file location.
|
80
|
-
#
|
81
|
-
# @param loc [String] The path of the yaml config file.
|
82
|
-
#
|
83
|
-
# @warn If the specified path is not a valid yaml file. Returns an empty Hash
|
84
|
-
# if so.
|
85
|
-
#
|
86
|
-
# @return [Hash] The data that has been read in from the given yaml file.
|
87
|
-
#
|
88
|
-
# @api private
|
89
|
-
def read_config(loc)
|
90
|
-
if PDK::Util::Filesystem.file?(loc) && PDK::Util::Filesystem.readable?(loc)
|
91
|
-
require 'yaml'
|
92
|
-
|
93
|
-
begin
|
94
|
-
YAML.safe_load(PDK::Util::Filesystem.read_file(loc), [], [], true)
|
95
|
-
rescue Psych::SyntaxError => e
|
96
|
-
PDK.logger.warn _("'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}") % {
|
97
|
-
file: loc,
|
98
|
-
problem: e.problem,
|
99
|
-
context: e.context,
|
100
|
-
line: e.line,
|
101
|
-
column: e.column,
|
102
|
-
}
|
103
|
-
{}
|
104
|
-
end
|
105
|
-
else
|
106
|
-
{}
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def template_path(_uri); end
|
111
|
-
end
|
112
|
-
# :nocov:
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Template
|
5
|
+
module Renderer
|
6
|
+
module V1
|
7
|
+
# The old templating code in the PDK passed through a TemplateDir object. This class mimics the methods
|
8
|
+
# of that old class so that existing custom templates will still function with the newer refactor templating code.
|
9
|
+
# Methods which have no use in custom templates exist but do no nothing, for example `def render; end`
|
10
|
+
#
|
11
|
+
# @see https://raw.githubusercontent.com/puppetlabs/pdk/4ffd58062c77ad1e54d2fe16b16015f7207bcee8/lib/pdk/module/template_dir/base.rb
|
12
|
+
# :nocov: This class is tested in the packaging and acceptance testing suites
|
13
|
+
class LegacyTemplateDir
|
14
|
+
attr_accessor :module_metadata
|
15
|
+
attr_reader :uri
|
16
|
+
|
17
|
+
def initialize(context, uri, path, module_metadata = {})
|
18
|
+
@uri = uri
|
19
|
+
@module_metadata = module_metadata
|
20
|
+
@context = context
|
21
|
+
@path = path
|
22
|
+
end
|
23
|
+
|
24
|
+
def metadata; end
|
25
|
+
|
26
|
+
def render; end
|
27
|
+
|
28
|
+
def object_template_for; end
|
29
|
+
|
30
|
+
def object_config
|
31
|
+
config_for(nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generate a hash of data to be used when rendering the specified
|
35
|
+
# template.
|
36
|
+
#
|
37
|
+
# @param dest_path [String] The destination path of the file that the
|
38
|
+
# data is for, relative to the root of the module.
|
39
|
+
#
|
40
|
+
# @return [Hash] The data that will be available to the template via the
|
41
|
+
# `@configs` instance variable.
|
42
|
+
#
|
43
|
+
# @api private
|
44
|
+
def config_for(dest_path, sync_config_path = nil)
|
45
|
+
require 'pdk/util'
|
46
|
+
require 'pdk/analytics'
|
47
|
+
|
48
|
+
module_root = PDK::Util.module_root
|
49
|
+
sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil?
|
50
|
+
config_path = File.join(@path, 'config_defaults.yml')
|
51
|
+
|
52
|
+
if @config.nil?
|
53
|
+
require 'deep_merge'
|
54
|
+
conf_defaults = read_config(config_path)
|
55
|
+
@sync_config = read_config(sync_config_path) unless sync_config_path.nil?
|
56
|
+
@config = conf_defaults
|
57
|
+
@config.deep_merge!(@sync_config, knockout_prefix: '---') unless @sync_config.nil?
|
58
|
+
end
|
59
|
+
file_config = @config.fetch(:global, {})
|
60
|
+
file_config['module_metadata'] = @module_metadata
|
61
|
+
file_config.merge!(@config.fetch(dest_path, {})) unless dest_path.nil?
|
62
|
+
file_config.merge!(@config).tap do |c|
|
63
|
+
if uri.default?
|
64
|
+
file_value = if c['unmanaged']
|
65
|
+
'unmanaged'
|
66
|
+
elsif c['delete']
|
67
|
+
'deleted'
|
68
|
+
elsif @sync_config && @sync_config.key?(dest_path)
|
69
|
+
'customized'
|
70
|
+
else
|
71
|
+
'default'
|
72
|
+
end
|
73
|
+
|
74
|
+
PDK.analytics.event('TemplateDir', 'file', label: dest_path, value: file_value)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Generates a hash of data from a given yaml file location.
|
80
|
+
#
|
81
|
+
# @param loc [String] The path of the yaml config file.
|
82
|
+
#
|
83
|
+
# @warn If the specified path is not a valid yaml file. Returns an empty Hash
|
84
|
+
# if so.
|
85
|
+
#
|
86
|
+
# @return [Hash] The data that has been read in from the given yaml file.
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
def read_config(loc)
|
90
|
+
if PDK::Util::Filesystem.file?(loc) && PDK::Util::Filesystem.readable?(loc)
|
91
|
+
require 'yaml'
|
92
|
+
|
93
|
+
begin
|
94
|
+
YAML.safe_load(PDK::Util::Filesystem.read_file(loc), [], [], true)
|
95
|
+
rescue Psych::SyntaxError => e
|
96
|
+
PDK.logger.warn _("'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}") % {
|
97
|
+
file: loc,
|
98
|
+
problem: e.problem,
|
99
|
+
context: e.context,
|
100
|
+
line: e.line,
|
101
|
+
column: e.column,
|
102
|
+
}
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
else
|
106
|
+
{}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def template_path(_uri); end
|
111
|
+
end
|
112
|
+
# :nocov:
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -1,132 +1,132 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
require 'pdk/template/renderer'
|
3
|
-
|
4
|
-
module PDK
|
5
|
-
module Template
|
6
|
-
module Renderer
|
7
|
-
module V1
|
8
|
-
class Renderer < PDK::Template::Renderer::AbstractRenderer
|
9
|
-
# @see PDK::Template::Renderer::AbstractRenderer.render
|
10
|
-
def render(template_type, _name, options = {})
|
11
|
-
render_module(options) { |*args| yield(*args) } if template_type == PDK::Template::MODULE_TEMPLATE_TYPE
|
12
|
-
end
|
13
|
-
|
14
|
-
# @see PDK::Template::Renderer::AbstractRenderer.has_single_item?
|
15
|
-
def has_single_item?(item_path) # rubocop:disable Naming/PredicateName
|
16
|
-
PDK::Util::Filesystem.exist?(single_item_path(item_path))
|
17
|
-
end
|
18
|
-
|
19
|
-
# @see PDK::Template::Renderer::AbstractRenderer.render_single_item
|
20
|
-
def render_single_item(relative_file_path, template_data_hash)
|
21
|
-
template_file = single_item_path(relative_file_path)
|
22
|
-
return nil unless PDK::Util::Filesystem.file?(template_file) && PDK::Util::Filesystem.readable?(template_file)
|
23
|
-
|
24
|
-
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
25
|
-
new_template_file(template_file, template_data_hash).render
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns the full path for a single item
|
29
|
-
#
|
30
|
-
# @param item_path [String] The path of the single item to render
|
31
|
-
# @return [String]
|
32
|
-
# @api private
|
33
|
-
#:nocov:
|
34
|
-
def single_item_path(item_path)
|
35
|
-
File.join(template_root, 'object_templates', item_path)
|
36
|
-
end
|
37
|
-
#:nocov:
|
38
|
-
|
39
|
-
# Helper method used during testing
|
40
|
-
#:nocov:
|
41
|
-
# @api private
|
42
|
-
def new_template_file(template_file, template_data_hash)
|
43
|
-
TemplateFile.new(template_file, template_data_hash)
|
44
|
-
end
|
45
|
-
#:nocov:
|
46
|
-
|
47
|
-
# Helper method used during testing
|
48
|
-
#:nocov:
|
49
|
-
# @api private
|
50
|
-
def new_legacy_template_dir(context, uri, path, module_metadata = {})
|
51
|
-
LegacyTemplateDir.new(context, uri, path, module_metadata)
|
52
|
-
end
|
53
|
-
#:nocov:
|
54
|
-
|
55
|
-
# Renders a new module
|
56
|
-
#
|
57
|
-
# @param options [Hash{Object => Object}] A list of options to pass through to the renderer. See PDK::Template::TemplateDir helper methods for other options
|
58
|
-
# @see #render
|
59
|
-
# @api private
|
60
|
-
#:nocov: This is tested in acceptance and packaging tests
|
61
|
-
def render_module(options = {})
|
62
|
-
require 'pdk/template/renderer/v1/template_file'
|
63
|
-
|
64
|
-
moduleroot_dir = File.join(template_root, 'moduleroot')
|
65
|
-
moduleroot_init = File.join(template_root, 'moduleroot_init')
|
66
|
-
|
67
|
-
dirs = [moduleroot_dir]
|
68
|
-
dirs << moduleroot_init if options[:include_first_time]
|
69
|
-
|
70
|
-
legacy_template_dir = new_legacy_template_dir(context, template_uri, template_root, options[:module_metadata] || {})
|
71
|
-
|
72
|
-
files_in_template(dirs).each do |template_file, template_loc|
|
73
|
-
template_file = template_file.to_s
|
74
|
-
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
75
|
-
dest_path = template_file.sub(%r{\.erb\Z}, '')
|
76
|
-
config = legacy_template_dir.config_for(dest_path)
|
77
|
-
|
78
|
-
dest_status = if template_loc.start_with?(moduleroot_init)
|
79
|
-
:init
|
80
|
-
else
|
81
|
-
:manage
|
82
|
-
end
|
83
|
-
|
84
|
-
if config['unmanaged']
|
85
|
-
dest_status = :unmanage
|
86
|
-
elsif config['delete']
|
87
|
-
dest_status = :delete
|
88
|
-
else
|
89
|
-
begin
|
90
|
-
dest_content = new_template_file(File.join(template_loc, template_file), configs: config, template_dir: legacy_template_dir).render
|
91
|
-
rescue => error
|
92
|
-
error_msg = _(
|
93
|
-
"Failed to render template '%{template}'\n" \
|
94
|
-
'%{exception}: %{message}',
|
95
|
-
) % { template: template_file, exception: error.class, message: error.message }
|
96
|
-
raise PDK::CLI::FatalError, error_msg
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
yield dest_path, dest_content, dest_status
|
101
|
-
end
|
102
|
-
end
|
103
|
-
#:nocov:
|
104
|
-
|
105
|
-
# Returns all files in the given template directories
|
106
|
-
#
|
107
|
-
# @param dirs [Array[String]] Directories to search in
|
108
|
-
# @param glob_suffix [Array[String]] File glob to use when searching for files. Defaults to ['**', '*']
|
109
|
-
#
|
110
|
-
# @return [Hash{String => String}] Key is the template file relative path and the value is the absolute path to the template directory
|
111
|
-
# @api private
|
112
|
-
def files_in_template(dirs, glob_suffix = ['**', '*'])
|
113
|
-
temp_paths = []
|
114
|
-
dirlocs = []
|
115
|
-
dirs.each do |dir|
|
116
|
-
raise ArgumentError, _("The directory '%{dir}' doesn't exist") % { dir: dir } unless PDK::Util::Filesystem.directory?(dir)
|
117
|
-
temp_paths += PDK::Util::Filesystem.glob(File.join(dir, *glob_suffix), File::FNM_DOTMATCH).select do |template_path|
|
118
|
-
if PDK::Util::Filesystem.file?(template_path) && !PDK::Util::Filesystem.symlink?(template_path)
|
119
|
-
dirlocs << dir
|
120
|
-
end
|
121
|
-
end
|
122
|
-
temp_paths.map do |template_path|
|
123
|
-
template_path.sub!(%r{\A#{Regexp.escape(dir)}#{Regexp.escape(File::SEPARATOR)}}, '')
|
124
|
-
end
|
125
|
-
end
|
126
|
-
Hash[temp_paths.zip dirlocs]
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
require 'pdk/template/renderer'
|
3
|
+
|
4
|
+
module PDK
|
5
|
+
module Template
|
6
|
+
module Renderer
|
7
|
+
module V1
|
8
|
+
class Renderer < PDK::Template::Renderer::AbstractRenderer
|
9
|
+
# @see PDK::Template::Renderer::AbstractRenderer.render
|
10
|
+
def render(template_type, _name, options = {})
|
11
|
+
render_module(options) { |*args| yield(*args) } if template_type == PDK::Template::MODULE_TEMPLATE_TYPE
|
12
|
+
end
|
13
|
+
|
14
|
+
# @see PDK::Template::Renderer::AbstractRenderer.has_single_item?
|
15
|
+
def has_single_item?(item_path) # rubocop:disable Naming/PredicateName
|
16
|
+
PDK::Util::Filesystem.exist?(single_item_path(item_path))
|
17
|
+
end
|
18
|
+
|
19
|
+
# @see PDK::Template::Renderer::AbstractRenderer.render_single_item
|
20
|
+
def render_single_item(relative_file_path, template_data_hash)
|
21
|
+
template_file = single_item_path(relative_file_path)
|
22
|
+
return nil unless PDK::Util::Filesystem.file?(template_file) && PDK::Util::Filesystem.readable?(template_file)
|
23
|
+
|
24
|
+
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
25
|
+
new_template_file(template_file, template_data_hash).render
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the full path for a single item
|
29
|
+
#
|
30
|
+
# @param item_path [String] The path of the single item to render
|
31
|
+
# @return [String]
|
32
|
+
# @api private
|
33
|
+
#:nocov:
|
34
|
+
def single_item_path(item_path)
|
35
|
+
File.join(template_root, 'object_templates', item_path)
|
36
|
+
end
|
37
|
+
#:nocov:
|
38
|
+
|
39
|
+
# Helper method used during testing
|
40
|
+
#:nocov:
|
41
|
+
# @api private
|
42
|
+
def new_template_file(template_file, template_data_hash)
|
43
|
+
TemplateFile.new(template_file, template_data_hash)
|
44
|
+
end
|
45
|
+
#:nocov:
|
46
|
+
|
47
|
+
# Helper method used during testing
|
48
|
+
#:nocov:
|
49
|
+
# @api private
|
50
|
+
def new_legacy_template_dir(context, uri, path, module_metadata = {})
|
51
|
+
LegacyTemplateDir.new(context, uri, path, module_metadata)
|
52
|
+
end
|
53
|
+
#:nocov:
|
54
|
+
|
55
|
+
# Renders a new module
|
56
|
+
#
|
57
|
+
# @param options [Hash{Object => Object}] A list of options to pass through to the renderer. See PDK::Template::TemplateDir helper methods for other options
|
58
|
+
# @see #render
|
59
|
+
# @api private
|
60
|
+
#:nocov: This is tested in acceptance and packaging tests
|
61
|
+
def render_module(options = {})
|
62
|
+
require 'pdk/template/renderer/v1/template_file'
|
63
|
+
|
64
|
+
moduleroot_dir = File.join(template_root, 'moduleroot')
|
65
|
+
moduleroot_init = File.join(template_root, 'moduleroot_init')
|
66
|
+
|
67
|
+
dirs = [moduleroot_dir]
|
68
|
+
dirs << moduleroot_init if options[:include_first_time]
|
69
|
+
|
70
|
+
legacy_template_dir = new_legacy_template_dir(context, template_uri, template_root, options[:module_metadata] || {})
|
71
|
+
|
72
|
+
files_in_template(dirs).each do |template_file, template_loc|
|
73
|
+
template_file = template_file.to_s
|
74
|
+
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
75
|
+
dest_path = template_file.sub(%r{\.erb\Z}, '')
|
76
|
+
config = legacy_template_dir.config_for(dest_path)
|
77
|
+
|
78
|
+
dest_status = if template_loc.start_with?(moduleroot_init)
|
79
|
+
:init
|
80
|
+
else
|
81
|
+
:manage
|
82
|
+
end
|
83
|
+
|
84
|
+
if config['unmanaged']
|
85
|
+
dest_status = :unmanage
|
86
|
+
elsif config['delete']
|
87
|
+
dest_status = :delete
|
88
|
+
else
|
89
|
+
begin
|
90
|
+
dest_content = new_template_file(File.join(template_loc, template_file), configs: config, template_dir: legacy_template_dir).render
|
91
|
+
rescue => error
|
92
|
+
error_msg = _(
|
93
|
+
"Failed to render template '%{template}'\n" \
|
94
|
+
'%{exception}: %{message}',
|
95
|
+
) % { template: template_file, exception: error.class, message: error.message }
|
96
|
+
raise PDK::CLI::FatalError, error_msg
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
yield dest_path, dest_content, dest_status
|
101
|
+
end
|
102
|
+
end
|
103
|
+
#:nocov:
|
104
|
+
|
105
|
+
# Returns all files in the given template directories
|
106
|
+
#
|
107
|
+
# @param dirs [Array[String]] Directories to search in
|
108
|
+
# @param glob_suffix [Array[String]] File glob to use when searching for files. Defaults to ['**', '*']
|
109
|
+
#
|
110
|
+
# @return [Hash{String => String}] Key is the template file relative path and the value is the absolute path to the template directory
|
111
|
+
# @api private
|
112
|
+
def files_in_template(dirs, glob_suffix = ['**', '*'])
|
113
|
+
temp_paths = []
|
114
|
+
dirlocs = []
|
115
|
+
dirs.each do |dir|
|
116
|
+
raise ArgumentError, _("The directory '%{dir}' doesn't exist") % { dir: dir } unless PDK::Util::Filesystem.directory?(dir)
|
117
|
+
temp_paths += PDK::Util::Filesystem.glob(File.join(dir, *glob_suffix), File::FNM_DOTMATCH).select do |template_path|
|
118
|
+
if PDK::Util::Filesystem.file?(template_path) && !PDK::Util::Filesystem.symlink?(template_path)
|
119
|
+
dirlocs << dir
|
120
|
+
end
|
121
|
+
end
|
122
|
+
temp_paths.map do |template_path|
|
123
|
+
template_path.sub!(%r{\A#{Regexp.escape(dir)}#{Regexp.escape(File::SEPARATOR)}}, '')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
Hash[temp_paths.zip dirlocs]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|