pdk 2.3.0 → 2.4.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 +1329 -1321
- data/LICENSE +201 -201
- data/README.md +163 -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 -277
- 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 +2094 -2094
- metadata +5 -6
@@ -1,125 +1,125 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Util
|
5
|
-
module PuppetStrings
|
6
|
-
class NoObjectError < StandardError; end
|
7
|
-
class RunError < StandardError; end
|
8
|
-
class NoGeneratorError < StandardError; end
|
9
|
-
|
10
|
-
# Runs Puppet for the purposes of generating puppet-strings output.
|
11
|
-
#
|
12
|
-
# @param *args [String] additional parameters to pass to puppet.
|
13
|
-
#
|
14
|
-
# @return [Hash{Symbol=>Object}] the result of the command execution.
|
15
|
-
def self.puppet(*args)
|
16
|
-
require 'pdk/cli/exec/command'
|
17
|
-
|
18
|
-
PDK::Util::Bundler.ensure_binstubs!('puppet')
|
19
|
-
|
20
|
-
argv = [File.join(PDK::Util.module_root, 'bin', 'puppet')] + args
|
21
|
-
argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe')) if Gem.win_platform?
|
22
|
-
|
23
|
-
command = PDK::CLI::Exec::Command.new(*argv).tap do |c|
|
24
|
-
c.context = :module
|
25
|
-
c.add_spinner(_('Examining module contents'))
|
26
|
-
end
|
27
|
-
|
28
|
-
command.execute!
|
29
|
-
end
|
30
|
-
|
31
|
-
# Generates and parses the JSON output from puppet-strings.
|
32
|
-
#
|
33
|
-
# @returns [Hash{String=>Object}] the parsed puppet-strings output.
|
34
|
-
#
|
35
|
-
# @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
|
36
|
-
# command exits non-zero.
|
37
|
-
# @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
|
38
|
-
# command outputs invalid JSON.
|
39
|
-
def self.generate_hash
|
40
|
-
result = puppet('strings', 'generate', '--format', 'json')
|
41
|
-
|
42
|
-
raise RunError, result[:stderr] unless result[:exit_code].zero?
|
43
|
-
|
44
|
-
JSON.parse(result[:stdout])
|
45
|
-
rescue JSON::ParserError => e
|
46
|
-
PDK.logger.debug(e)
|
47
|
-
raise RunError, _('Unable to parse puppet-strings output')
|
48
|
-
end
|
49
|
-
|
50
|
-
# Searches the puppet-strings result to find the definition of the named
|
51
|
-
# object.
|
52
|
-
#
|
53
|
-
# @param name [String] the name of the object definition to search for.
|
54
|
-
# If the object name is not prepended with the module name,
|
55
|
-
# "#{module_name}::#{object_name}" will also be search for.
|
56
|
-
#
|
57
|
-
# @returns [Array[PDK::Generate::PuppetObject, Hash{String=>Object}]] the
|
58
|
-
# appropriate generator class for the object as the first element and
|
59
|
-
# the puppet-strings description hash for the definition.
|
60
|
-
#
|
61
|
-
# @raises [PDK::Util::PuppetStrings::NoObjectError] if the named object
|
62
|
-
# can not be found in the puppet-strings output.
|
63
|
-
# @raises [PDK::Util::PuppetStrings::NoGeneratorError] if the named
|
64
|
-
# object does not have a corresponding PDK generator class.
|
65
|
-
def self.find_object(name)
|
66
|
-
module_name = PDK::Util.module_metadata['name'].rpartition('-').last
|
67
|
-
|
68
|
-
object_names = [name]
|
69
|
-
object_names << "#{module_name}::#{name}" unless name.start_with?("#{module_name}::")
|
70
|
-
|
71
|
-
known_objects = generate_hash
|
72
|
-
object_type = known_objects.keys.find do |obj_type|
|
73
|
-
known_objects[obj_type].any? { |obj| object_names.include?(obj['name']) }
|
74
|
-
end
|
75
|
-
|
76
|
-
raise NoObjectError if object_type.nil?
|
77
|
-
|
78
|
-
generator = find_generator(object_type)
|
79
|
-
|
80
|
-
raise NoGeneratorError, object_type if generator.nil?
|
81
|
-
|
82
|
-
[generator, known_objects[object_type].find { |obj| object_names.include?(obj['name']) }]
|
83
|
-
end
|
84
|
-
|
85
|
-
# Generate a list of all objects that PDK has a generator for.
|
86
|
-
#
|
87
|
-
# @returns [Array[Array[PDK::Generate::PuppetObject,
|
88
|
-
# Array[Hash{String=>Object}]]]] an associative array where the first
|
89
|
-
# element of each pair is the generator class and the second element of
|
90
|
-
# each pair is an array of description hashes from puppet-strings.
|
91
|
-
def self.all_objects
|
92
|
-
require 'pdk/generate'
|
93
|
-
|
94
|
-
generators = PDK::Generate.generators.select do |gen|
|
95
|
-
gen.const_defined?(:PUPPET_STRINGS_TYPE) && !gen::PUPPET_STRINGS_TYPE.nil?
|
96
|
-
end
|
97
|
-
|
98
|
-
known_objects = generate_hash
|
99
|
-
|
100
|
-
generators.map { |gen| [gen, known_objects[gen::PUPPET_STRINGS_TYPE]] }.reject do |_, obj|
|
101
|
-
obj.nil? || obj.empty?
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Evaluates the mapping of puppet-strings object type to PDK generator
|
106
|
-
# class.
|
107
|
-
#
|
108
|
-
# @param type [String] the object type as returned from puppet-strings.
|
109
|
-
#
|
110
|
-
# @returns [PDK:Generate::PuppetObject,nil] a child of
|
111
|
-
# PDK::Generate::PuppetObject or nil a suitable generator is not found.
|
112
|
-
#
|
113
|
-
# @example
|
114
|
-
# PDK::Util::PuppetStrings.find_generator('puppet_classes')
|
115
|
-
# => PDK::Generate::PuppetClass
|
116
|
-
def self.find_generator(type)
|
117
|
-
require 'pdk/generate'
|
118
|
-
|
119
|
-
PDK::Generate.generators.find do |gen|
|
120
|
-
gen.const_defined?(:PUPPET_STRINGS_TYPE) && gen::PUPPET_STRINGS_TYPE == type
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Util
|
5
|
+
module PuppetStrings
|
6
|
+
class NoObjectError < StandardError; end
|
7
|
+
class RunError < StandardError; end
|
8
|
+
class NoGeneratorError < StandardError; end
|
9
|
+
|
10
|
+
# Runs Puppet for the purposes of generating puppet-strings output.
|
11
|
+
#
|
12
|
+
# @param *args [String] additional parameters to pass to puppet.
|
13
|
+
#
|
14
|
+
# @return [Hash{Symbol=>Object}] the result of the command execution.
|
15
|
+
def self.puppet(*args)
|
16
|
+
require 'pdk/cli/exec/command'
|
17
|
+
|
18
|
+
PDK::Util::Bundler.ensure_binstubs!('puppet')
|
19
|
+
|
20
|
+
argv = [File.join(PDK::Util.module_root, 'bin', 'puppet')] + args
|
21
|
+
argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe')) if Gem.win_platform?
|
22
|
+
|
23
|
+
command = PDK::CLI::Exec::Command.new(*argv).tap do |c|
|
24
|
+
c.context = :module
|
25
|
+
c.add_spinner(_('Examining module contents'))
|
26
|
+
end
|
27
|
+
|
28
|
+
command.execute!
|
29
|
+
end
|
30
|
+
|
31
|
+
# Generates and parses the JSON output from puppet-strings.
|
32
|
+
#
|
33
|
+
# @returns [Hash{String=>Object}] the parsed puppet-strings output.
|
34
|
+
#
|
35
|
+
# @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
|
36
|
+
# command exits non-zero.
|
37
|
+
# @raises [PDK::Util::PuppetStrings::RunError] if the puppet-strings
|
38
|
+
# command outputs invalid JSON.
|
39
|
+
def self.generate_hash
|
40
|
+
result = puppet('strings', 'generate', '--format', 'json')
|
41
|
+
|
42
|
+
raise RunError, result[:stderr] unless result[:exit_code].zero?
|
43
|
+
|
44
|
+
JSON.parse(result[:stdout])
|
45
|
+
rescue JSON::ParserError => e
|
46
|
+
PDK.logger.debug(e)
|
47
|
+
raise RunError, _('Unable to parse puppet-strings output')
|
48
|
+
end
|
49
|
+
|
50
|
+
# Searches the puppet-strings result to find the definition of the named
|
51
|
+
# object.
|
52
|
+
#
|
53
|
+
# @param name [String] the name of the object definition to search for.
|
54
|
+
# If the object name is not prepended with the module name,
|
55
|
+
# "#{module_name}::#{object_name}" will also be search for.
|
56
|
+
#
|
57
|
+
# @returns [Array[PDK::Generate::PuppetObject, Hash{String=>Object}]] the
|
58
|
+
# appropriate generator class for the object as the first element and
|
59
|
+
# the puppet-strings description hash for the definition.
|
60
|
+
#
|
61
|
+
# @raises [PDK::Util::PuppetStrings::NoObjectError] if the named object
|
62
|
+
# can not be found in the puppet-strings output.
|
63
|
+
# @raises [PDK::Util::PuppetStrings::NoGeneratorError] if the named
|
64
|
+
# object does not have a corresponding PDK generator class.
|
65
|
+
def self.find_object(name)
|
66
|
+
module_name = PDK::Util.module_metadata['name'].rpartition('-').last
|
67
|
+
|
68
|
+
object_names = [name]
|
69
|
+
object_names << "#{module_name}::#{name}" unless name.start_with?("#{module_name}::")
|
70
|
+
|
71
|
+
known_objects = generate_hash
|
72
|
+
object_type = known_objects.keys.find do |obj_type|
|
73
|
+
known_objects[obj_type].any? { |obj| object_names.include?(obj['name']) }
|
74
|
+
end
|
75
|
+
|
76
|
+
raise NoObjectError if object_type.nil?
|
77
|
+
|
78
|
+
generator = find_generator(object_type)
|
79
|
+
|
80
|
+
raise NoGeneratorError, object_type if generator.nil?
|
81
|
+
|
82
|
+
[generator, known_objects[object_type].find { |obj| object_names.include?(obj['name']) }]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Generate a list of all objects that PDK has a generator for.
|
86
|
+
#
|
87
|
+
# @returns [Array[Array[PDK::Generate::PuppetObject,
|
88
|
+
# Array[Hash{String=>Object}]]]] an associative array where the first
|
89
|
+
# element of each pair is the generator class and the second element of
|
90
|
+
# each pair is an array of description hashes from puppet-strings.
|
91
|
+
def self.all_objects
|
92
|
+
require 'pdk/generate'
|
93
|
+
|
94
|
+
generators = PDK::Generate.generators.select do |gen|
|
95
|
+
gen.const_defined?(:PUPPET_STRINGS_TYPE) && !gen::PUPPET_STRINGS_TYPE.nil?
|
96
|
+
end
|
97
|
+
|
98
|
+
known_objects = generate_hash
|
99
|
+
|
100
|
+
generators.map { |gen| [gen, known_objects[gen::PUPPET_STRINGS_TYPE]] }.reject do |_, obj|
|
101
|
+
obj.nil? || obj.empty?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Evaluates the mapping of puppet-strings object type to PDK generator
|
106
|
+
# class.
|
107
|
+
#
|
108
|
+
# @param type [String] the object type as returned from puppet-strings.
|
109
|
+
#
|
110
|
+
# @returns [PDK:Generate::PuppetObject,nil] a child of
|
111
|
+
# PDK::Generate::PuppetObject or nil a suitable generator is not found.
|
112
|
+
#
|
113
|
+
# @example
|
114
|
+
# PDK::Util::PuppetStrings.find_generator('puppet_classes')
|
115
|
+
# => PDK::Generate::PuppetClass
|
116
|
+
def self.find_generator(type)
|
117
|
+
require 'pdk/generate'
|
118
|
+
|
119
|
+
PDK::Generate.generators.find do |gen|
|
120
|
+
gen.const_defined?(:PUPPET_STRINGS_TYPE) && gen::PUPPET_STRINGS_TYPE == type
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|