pdk 1.9.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +744 -711
- data/README.md +23 -21
- data/lib/pdk/answer_file.rb +3 -112
- data/lib/pdk/bolt.rb +20 -0
- data/lib/pdk/cli/build.rb +51 -54
- data/lib/pdk/cli/bundle.rb +33 -29
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +46 -37
- data/lib/pdk/cli/env.rb +51 -0
- data/lib/pdk/cli/errors.rb +4 -3
- data/lib/pdk/cli/exec/command.rb +285 -0
- data/lib/pdk/cli/exec/interactive_command.rb +109 -0
- data/lib/pdk/cli/exec.rb +32 -201
- data/lib/pdk/cli/exec_group.rb +79 -43
- data/lib/pdk/cli/get/config.rb +26 -0
- data/lib/pdk/cli/get.rb +22 -0
- data/lib/pdk/cli/new/class.rb +20 -22
- data/lib/pdk/cli/new/defined_type.rb +21 -21
- data/lib/pdk/cli/new/fact.rb +27 -0
- data/lib/pdk/cli/new/function.rb +27 -0
- data/lib/pdk/cli/new/module.rb +40 -29
- data/lib/pdk/cli/new/provider.rb +18 -18
- data/lib/pdk/cli/new/task.rb +23 -22
- data/lib/pdk/cli/new/test.rb +52 -0
- data/lib/pdk/cli/new/transport.rb +27 -0
- data/lib/pdk/cli/new.rb +15 -9
- data/lib/pdk/cli/release/prep.rb +39 -0
- data/lib/pdk/cli/release/publish.rb +46 -0
- data/lib/pdk/cli/release.rb +185 -0
- data/lib/pdk/cli/remove/config.rb +83 -0
- data/lib/pdk/cli/remove.rb +22 -0
- data/lib/pdk/cli/set/config.rb +121 -0
- data/lib/pdk/cli/set.rb +22 -0
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -8
- data/lib/pdk/cli/update.rb +38 -21
- data/lib/pdk/cli/util/command_redirector.rb +13 -3
- data/lib/pdk/cli/util/interview.rb +25 -9
- data/lib/pdk/cli/util/option_normalizer.rb +6 -6
- data/lib/pdk/cli/util/option_validator.rb +19 -9
- data/lib/pdk/cli/util/spinner.rb +13 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/util.rb +105 -48
- data/lib/pdk/cli/validate.rb +96 -111
- data/lib/pdk/cli.rb +134 -87
- data/lib/pdk/config/errors.rb +5 -0
- data/lib/pdk/config/ini_file.rb +184 -0
- data/lib/pdk/config/ini_file_setting.rb +35 -0
- data/lib/pdk/config/json.rb +35 -0
- data/lib/pdk/config/json_schema_namespace.rb +137 -0
- data/lib/pdk/config/json_schema_setting.rb +51 -0
- data/lib/pdk/config/json_with_schema.rb +47 -0
- data/lib/pdk/config/namespace.rb +362 -0
- data/lib/pdk/config/setting.rb +134 -0
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +31 -0
- data/lib/pdk/config/yaml.rb +41 -0
- data/lib/pdk/config/yaml_with_schema.rb +51 -0
- data/lib/pdk/config.rb +304 -0
- data/lib/pdk/context/control_repo.rb +61 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/context.rb +98 -0
- data/lib/pdk/control_repo.rb +89 -0
- data/lib/pdk/generate/defined_type.rb +27 -33
- data/lib/pdk/generate/fact.rb +26 -0
- data/lib/pdk/generate/function.rb +49 -0
- data/lib/pdk/generate/module.rb +160 -153
- data/lib/pdk/generate/provider.rb +16 -69
- data/lib/pdk/generate/puppet_class.rb +27 -32
- data/lib/pdk/generate/puppet_object.rb +100 -159
- data/lib/pdk/generate/task.rb +34 -51
- data/lib/pdk/generate/transport.rb +34 -0
- data/lib/pdk/generate.rb +21 -8
- data/lib/pdk/logger.rb +24 -6
- data/lib/pdk/module/build.rb +125 -37
- data/lib/pdk/module/convert.rb +146 -65
- data/lib/pdk/module/metadata.rb +72 -71
- data/lib/pdk/module/release.rb +255 -0
- data/lib/pdk/module/update.rb +48 -37
- data/lib/pdk/module/update_manager.rb +75 -39
- data/lib/pdk/module.rb +10 -2
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +36 -48
- data/lib/pdk/report.rb +35 -22
- data/lib/pdk/template/fetcher/git.rb +84 -0
- data/lib/pdk/template/fetcher/local.rb +29 -0
- data/lib/pdk/template/fetcher.rb +100 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +108 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +131 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +100 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer.rb +97 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/template.rb +52 -0
- data/lib/pdk/tests/unit.rb +101 -51
- data/lib/pdk/util/bundler.rb +44 -42
- data/lib/pdk/util/changelog_generator.rb +138 -0
- data/lib/pdk/util/env.rb +48 -0
- data/lib/pdk/util/filesystem.rb +139 -2
- data/lib/pdk/util/git.rb +108 -8
- data/lib/pdk/util/json_finder.rb +86 -0
- data/lib/pdk/util/puppet_strings.rb +125 -0
- data/lib/pdk/util/puppet_version.rb +71 -87
- data/lib/pdk/util/ruby_version.rb +49 -25
- data/lib/pdk/util/template_uri.rb +283 -0
- data/lib/pdk/util/vendored_file.rb +34 -42
- data/lib/pdk/util/version.rb +11 -10
- data/lib/pdk/util/windows/api_types.rb +74 -44
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +74 -0
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util/windows.rb +2 -0
- data/lib/pdk/util.rb +111 -124
- 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 +213 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +101 -0
- data/lib/pdk/validate/invokable_validator.rb +238 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +84 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +76 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +131 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +135 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +22 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +79 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +83 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +45 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +120 -0
- data/lib/pdk/validate/validator_group.rb +107 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +86 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/validate.rb +86 -12
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +60 -10
- metadata +138 -100
- data/lib/pdk/cli/module/build.rb +0 -14
- data/lib/pdk/cli/module/generate.rb +0 -45
- data/lib/pdk/cli/module.rb +0 -14
- data/lib/pdk/i18n.rb +0 -4
- data/lib/pdk/module/templatedir.rb +0 -321
- data/lib/pdk/template_file.rb +0 -95
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -86
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -109
- data/lib/pdk/validate/metadata_validator.rb +0 -30
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -67
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -112
- data/lib/pdk/validate/puppet_validator.rb +0 -30
- data/lib/pdk/validate/ruby/rubocop.rb +0 -77
- data/lib/pdk/validate/ruby_validator.rb +0 -29
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -126
- data/lib/pdk/validate/tasks/name.rb +0 -88
- data/lib/pdk/validate/tasks_validator.rb +0 -33
- data/lib/pdk/validate/yaml/syntax.rb +0 -109
- data/lib/pdk/validate/yaml_validator.rb +0 -31
- data/locales/config.yaml +0 -21
- data/locales/pdk.pot +0 -1291
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'pdk
|
2
|
-
require '
|
1
|
+
require 'pdk'
|
2
|
+
require 'json'
|
3
|
+
require 'forwardable'
|
3
4
|
|
4
5
|
module PDK
|
5
6
|
module Util
|
@@ -18,45 +19,55 @@ module PDK
|
|
18
19
|
|
19
20
|
PE_VERSIONS_URL = 'https://forgeapi.puppet.com/private/versions/pe'.freeze
|
20
21
|
DEFAULT_PUPPET_DEV_URL = 'https://github.com/puppetlabs/puppet'.freeze
|
21
|
-
DEFAULT_PUPPET_DEV_BRANCH = '
|
22
|
+
DEFAULT_PUPPET_DEV_BRANCH = 'main'.freeze
|
22
23
|
|
23
24
|
def puppet_dev_env
|
25
|
+
require 'pdk/util/ruby_version'
|
26
|
+
|
24
27
|
{
|
25
|
-
gem_version: 'file://%{path}'
|
26
|
-
ruby_version: PDK::Util::RubyVersion.latest_ruby_version
|
28
|
+
gem_version: format('file://%{path}', path: puppet_dev_path),
|
29
|
+
ruby_version: PDK::Util::RubyVersion.latest_ruby_version
|
27
30
|
}
|
28
31
|
end
|
29
32
|
|
30
33
|
def puppet_dev_path
|
34
|
+
require 'pdk/util'
|
35
|
+
|
31
36
|
File.join(PDK::Util.cachedir, 'src', 'puppet')
|
32
37
|
end
|
33
38
|
|
34
39
|
def latest_available
|
35
40
|
latest = find_gem(Gem::Requirement.create('>= 0'))
|
36
41
|
|
37
|
-
if latest.nil?
|
38
|
-
raise ArgumentError, _('Unable to find a Puppet gem in current Ruby environment or from Rubygems.org.')
|
39
|
-
end
|
42
|
+
raise ArgumentError, 'Unable to find a Puppet gem in current Ruby environment or from Rubygems.org.' if latest.nil?
|
40
43
|
|
41
44
|
latest
|
42
45
|
end
|
43
46
|
|
44
|
-
def
|
47
|
+
def puppet_dev_fetched?
|
48
|
+
!@puppet_dev_fetched.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch_puppet_dev(options = {})
|
52
|
+
return if options[:run] == :once && puppet_dev_fetched?
|
53
|
+
|
54
|
+
require 'pdk/util/git'
|
55
|
+
|
45
56
|
# Check if the source is cloned and is a readable git repo
|
46
57
|
unless PDK::Util::Git.remote_repo? puppet_dev_path
|
47
58
|
# Check if the path has something in it already. Delete it and prepare for clone if so.
|
48
|
-
if
|
49
|
-
|
50
|
-
|
59
|
+
if PDK::Util::Filesystem.exist? puppet_dev_path
|
60
|
+
PDK::Util::Filesystem.delete(puppet_dev_path) if PDK::Util::Filesystem.file? puppet_dev_path
|
61
|
+
PDK::Util::Filesystem.rm_rf(puppet_dev_path) if PDK::Util::Filesystem.directory? puppet_dev_path
|
51
62
|
end
|
52
63
|
|
53
|
-
|
64
|
+
PDK::Util::Filesystem.mkdir_p puppet_dev_path
|
54
65
|
clone_result = PDK::Util::Git.git('clone', DEFAULT_PUPPET_DEV_URL, puppet_dev_path)
|
55
66
|
return if clone_result[:exit_code].zero?
|
56
67
|
|
57
68
|
PDK.logger.error clone_result[:stdout]
|
58
69
|
PDK.logger.error clone_result[:stderr]
|
59
|
-
raise PDK::CLI::FatalError,
|
70
|
+
raise PDK::CLI::FatalError, format("Unable to clone git repository from '%{repo}'.", repo: DEFAULT_PUPPET_DEV_URL)
|
60
71
|
end
|
61
72
|
|
62
73
|
# Fetch Updates from remote repository
|
@@ -65,16 +76,18 @@ module PDK
|
|
65
76
|
unless fetch_result[:exit_code].zero?
|
66
77
|
PDK.logger.error fetch_result[:stdout]
|
67
78
|
PDK.logger.error fetch_result[:stderr]
|
68
|
-
raise PDK::CLI::FatalError,
|
79
|
+
raise PDK::CLI::FatalError, format("Unable to fetch from git remote at '%{repo}'.", repo: DEFAULT_PUPPET_DEV_URL)
|
69
80
|
end
|
70
81
|
|
71
82
|
# Reset local repo to latest
|
72
|
-
reset_result = PDK::Util::Git.git('-C', puppet_dev_path, 'reset', '--hard',
|
83
|
+
reset_result = PDK::Util::Git.git('-C', puppet_dev_path, 'reset', '--hard', "origin/#{DEFAULT_PUPPET_DEV_BRANCH}")
|
84
|
+
|
85
|
+
@puppet_dev_fetched = true
|
73
86
|
return if reset_result[:exit_code].zero?
|
74
87
|
|
75
88
|
PDK.logger.error reset_result[:stdout]
|
76
89
|
PDK.logger.error reset_result[:stderr]
|
77
|
-
raise PDK::CLI::FatalError,
|
90
|
+
raise PDK::CLI::FatalError, format("Unable to update git repository at '%{cachedir}'.", cachedir: puppet_dev_path)
|
78
91
|
end
|
79
92
|
|
80
93
|
def find_gem_for(version_str)
|
@@ -91,21 +104,14 @@ module PDK
|
|
91
104
|
requirement_string = version.approximate_recommendation
|
92
105
|
requirement_string += '.0' unless version.segments.length == 1
|
93
106
|
latest_requirement = Gem::Requirement.create(requirement_string)
|
94
|
-
|
95
107
|
latest_available_gem = find_gem(latest_requirement)
|
96
108
|
|
97
|
-
if latest_available_gem.nil?
|
98
|
-
raise ArgumentError, _('Unable to find a Puppet gem matching %{requirement}.') % {
|
99
|
-
requirement: latest_requirement,
|
100
|
-
}
|
101
|
-
end
|
109
|
+
raise ArgumentError, format('Unable to find a Puppet gem matching %{requirement}.', requirement: latest_requirement) if latest_available_gem.nil?
|
102
110
|
|
103
111
|
# Only issue this warning if they requested an exact version that isn't available.
|
104
112
|
if version.segments.length == 3
|
105
|
-
PDK.logger.warn(
|
106
|
-
|
107
|
-
found_version: latest_available_gem[:gem_version].version,
|
108
|
-
})
|
113
|
+
PDK.logger.warn(format('Puppet %{requested_version} is not available, activating %{found_version} instead.', requested_version: version_str,
|
114
|
+
found_version: latest_available_gem[:gem_version].version))
|
109
115
|
end
|
110
116
|
|
111
117
|
latest_available_gem
|
@@ -114,31 +120,33 @@ module PDK
|
|
114
120
|
def from_pe_version(version_str)
|
115
121
|
version = parse_specified_version(version_str)
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
# Due to the issue with concurrent ruby in older puppet gems
|
124
|
+
# we are locking the pe to puppet version mapping to the latest
|
125
|
+
# puppet version that is compatible with the pe version.
|
126
|
+
safe_versions = {
|
127
|
+
2023 => '7.23.0',
|
128
|
+
2021 => '7.23.0',
|
129
|
+
2019 => '6.29.0'
|
130
|
+
}
|
120
131
|
|
121
|
-
|
122
|
-
|
123
|
-
pe_version: version_str,
|
124
|
-
}
|
125
|
-
end
|
132
|
+
gem_version = safe_versions[version.segments[0]]
|
133
|
+
raise ArgumentError, format('Unable to map Puppet Enterprise version %{pe_version} to a Puppet version.', pe_version: version_str) if gem_version.nil?
|
126
134
|
|
127
|
-
PDK.logger.info
|
128
|
-
pe_version: version_str,
|
129
|
-
puppet_version: gem_version[:gem_version],
|
130
|
-
}
|
135
|
+
PDK.logger.info format('Puppet Enterprise %{pe_version} maps to Puppet %{puppet_version}.', pe_version: version_str, puppet_version: gem_version)
|
131
136
|
|
132
|
-
find_gem_for(gem_version
|
137
|
+
find_gem_for(gem_version)
|
133
138
|
end
|
134
139
|
|
135
140
|
def from_module_metadata(metadata = nil)
|
141
|
+
require 'pdk/module/metadata'
|
142
|
+
require 'pdk/util'
|
143
|
+
|
136
144
|
if metadata.nil?
|
137
145
|
metadata_file = PDK::Util.find_upwards('metadata.json')
|
138
146
|
|
139
147
|
unless metadata_file
|
140
|
-
PDK.logger.warn
|
141
|
-
return
|
148
|
+
PDK.logger.warn 'Unable to determine Puppet version for module: no metadata.json present in module.'
|
149
|
+
return
|
142
150
|
end
|
143
151
|
|
144
152
|
metadata = PDK::Module::Metadata.from_file(metadata_file)
|
@@ -149,7 +157,7 @@ module PDK
|
|
149
157
|
|
150
158
|
# Split combined requirements like ">= 4.7.0 < 6.0.0" into their
|
151
159
|
# component requirements [">= 4.7.0", "< 6.0.0"]
|
152
|
-
pattern =
|
160
|
+
pattern = /#{Gem::Requirement::PATTERN_RAW}/o
|
153
161
|
requirement_strings = metadata_requirement['version_requirement'].scan(pattern).map do |req|
|
154
162
|
req.compact.join(' ')
|
155
163
|
end
|
@@ -163,59 +171,27 @@ module PDK
|
|
163
171
|
def parse_specified_version(version_str)
|
164
172
|
Gem::Version.new(version_str)
|
165
173
|
rescue ArgumentError
|
166
|
-
raise ArgumentError,
|
167
|
-
version: version_str,
|
168
|
-
}
|
169
|
-
end
|
170
|
-
|
171
|
-
def pe_version_map
|
172
|
-
@pe_version_map ||= fetch_pe_version_map.map { |version_map|
|
173
|
-
maps = version_map['versions'].map do |pe_release|
|
174
|
-
requirements = ["= #{pe_release['version']}"]
|
175
|
-
|
176
|
-
# Some PE release have a .0 Z release, which causes problems when
|
177
|
-
# the user specifies "X.Y" expecting to get the latest Z and
|
178
|
-
# instead getting the oldest.
|
179
|
-
requirements << "!= #{pe_release['version'].gsub(%r{\.\d+\Z}, '')}" if pe_release['version'].end_with?('.0')
|
180
|
-
{
|
181
|
-
requirement: Gem::Requirement.create(requirements),
|
182
|
-
gem_version: pe_release['puppet'],
|
183
|
-
}
|
184
|
-
end
|
185
|
-
|
186
|
-
maps << {
|
187
|
-
requirement: requirement_from_forge_range(version_map['release']),
|
188
|
-
gem_version: version_map['versions'].find { |r| r['version'] == version_map['latest'] }['puppet'],
|
189
|
-
}
|
190
|
-
}.flatten
|
191
|
-
end
|
192
|
-
|
193
|
-
def fetch_pe_version_map
|
194
|
-
map = PDK::Util::VendoredFile.new('pe_versions.json', PE_VERSIONS_URL).read
|
195
|
-
|
196
|
-
JSON.parse(map)
|
197
|
-
rescue PDK::Util::VendoredFile::DownloadError => e
|
198
|
-
raise PDK::CLI::FatalError, e.message
|
199
|
-
rescue JSON::ParserError
|
200
|
-
raise PDK::CLI::FatalError, _('Failed to parse Puppet Enterprise version map file.')
|
174
|
+
raise ArgumentError, format('%{version} is not a valid version number.', version: version_str)
|
201
175
|
end
|
202
176
|
|
203
177
|
def requirement_from_forge_range(range_str)
|
204
|
-
Gem::Requirement.create("~> #{range_str.gsub(
|
178
|
+
Gem::Requirement.create("~> #{range_str.gsub(/\.x\Z/, '.0')}")
|
205
179
|
end
|
206
180
|
|
207
181
|
def rubygems_puppet_versions
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
182
|
+
@rubygems_puppet_versions ||= begin
|
183
|
+
fetcher = Gem::SpecFetcher.fetcher
|
184
|
+
puppet_tuples = fetcher.detect(:released) do |spec_tuple|
|
185
|
+
spec_tuple.name == 'puppet' && Gem::Platform.match(spec_tuple.platform)
|
186
|
+
end
|
187
|
+
puppet_versions = puppet_tuples.map { |name, _| name.version }.uniq
|
188
|
+
puppet_versions.sort.reverse
|
213
189
|
end
|
214
|
-
puppet_versions = puppet_tuples.map { |name, _| name.version }.uniq
|
215
|
-
@rubygems_puppet_versions = puppet_versions.sort { |a, b| b <=> a }
|
216
190
|
end
|
217
191
|
|
218
192
|
def find_gem(requirement)
|
193
|
+
require 'pdk/util'
|
194
|
+
|
219
195
|
if PDK::Util.package_install?
|
220
196
|
find_in_package_cache(requirement)
|
221
197
|
else
|
@@ -224,12 +200,20 @@ module PDK
|
|
224
200
|
end
|
225
201
|
|
226
202
|
def find_in_rubygems(requirement)
|
203
|
+
require 'pdk/util/ruby_version'
|
204
|
+
|
227
205
|
version = rubygems_puppet_versions.find { |r| requirement.satisfied_by?(r) }
|
228
206
|
version.nil? ? nil : { gem_version: version, ruby_version: PDK::Util::RubyVersion.default_ruby_version }
|
229
207
|
end
|
230
208
|
|
209
|
+
# Finds the specified requirement in the package cache.
|
210
|
+
#
|
211
|
+
# @param requirement [Gem::Requirement] The requirement to search for.
|
212
|
+
# @return [Hash] A hash containing the gem version and ruby version if found, or nil if not found.
|
231
213
|
def find_in_package_cache(requirement)
|
232
|
-
|
214
|
+
require 'pdk/util/ruby_version'
|
215
|
+
|
216
|
+
PDK::Util::RubyVersion.versions.each_key do |ruby_version|
|
233
217
|
PDK::Util::RubyVersion.use(ruby_version)
|
234
218
|
version = PDK::Util::RubyVersion.available_puppet_versions.find { |r| requirement.satisfied_by?(r) }
|
235
219
|
return { gem_version: version, ruby_version: ruby_version } unless version.nil?
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'pdk
|
1
|
+
require 'pdk'
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
module PDK
|
4
5
|
module Util
|
@@ -8,6 +9,8 @@ module PDK
|
|
8
9
|
|
9
10
|
def_delegators :instance, :gem_path, :gem_paths_raw, :gem_home, :available_puppet_versions, :bin_path
|
10
11
|
|
12
|
+
# TODO: resolve this
|
13
|
+
# rubocop:disable Lint/DuplicateMethods
|
11
14
|
attr_reader :instance
|
12
15
|
|
13
16
|
def instance(version = nil)
|
@@ -21,43 +24,55 @@ module PDK
|
|
21
24
|
end
|
22
25
|
@instance[active_ruby_version]
|
23
26
|
end
|
27
|
+
# rubocop:enable Lint/DuplicateMethods
|
24
28
|
|
25
29
|
def active_ruby_version
|
26
30
|
@active_ruby_version || default_ruby_version
|
27
31
|
end
|
28
32
|
|
29
33
|
def use(version)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
raise ArgumentError, _('Unknown Ruby version "%{ruby_version}"') % {
|
34
|
-
ruby_version: version,
|
35
|
-
}
|
36
|
-
end
|
34
|
+
raise ArgumentError, format('Unknown Ruby version "%{ruby_version}"', ruby_version: version) unless versions.key?(version)
|
35
|
+
|
36
|
+
@active_ruby_version = version
|
37
37
|
end
|
38
38
|
|
39
39
|
def scan_for_packaged_rubies
|
40
|
+
require 'pdk/util'
|
41
|
+
|
40
42
|
ruby_basedir = File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', '*')
|
41
|
-
|
43
|
+
PDK::Util::Filesystem.glob(ruby_basedir).sort.map do |ruby_dir|
|
42
44
|
version = File.basename(ruby_dir)
|
43
|
-
[version, version.split('.').take(2).
|
44
|
-
|
45
|
+
[version, version.split('.').take(2).push('0').join('.')]
|
46
|
+
end.reverse.to_h
|
45
47
|
end
|
46
48
|
|
47
49
|
def default_ruby_version
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
require 'pdk/util'
|
51
|
+
require 'pdk/util/puppet_version'
|
52
|
+
|
53
|
+
@default_ruby_version ||= if PDK::Util.package_install?
|
54
|
+
# Default to the ruby that supports the latest puppet gem. If you wish to default to a
|
55
|
+
# specific Puppet Gem version use the following example;
|
56
|
+
#
|
57
|
+
# PDK::Util::PuppetVersion.find_gem_for('5.5.10')[:ruby_version]
|
58
|
+
#
|
59
|
+
# For using the latest puppet gem:
|
60
|
+
PDK::Util::PuppetVersion.latest_available[:ruby_version]
|
61
|
+
else
|
62
|
+
# TODO: may not be a safe assumption that highest available version should be default
|
63
|
+
# WARNING Do NOT use PDK::Util::PuppetVersion.*** methods as it can recurse into this
|
64
|
+
# method and cause Stack Level Too Deep errors.
|
65
|
+
latest_ruby_version
|
66
|
+
end
|
54
67
|
end
|
55
68
|
|
56
69
|
def latest_ruby_version
|
57
|
-
versions.keys.
|
70
|
+
versions.keys.min { |a, b| Gem::Version.new(b) <=> Gem::Version.new(a) }
|
58
71
|
end
|
59
72
|
|
60
73
|
def versions
|
74
|
+
require 'pdk/util'
|
75
|
+
|
61
76
|
@versions ||= if PDK::Util.package_install?
|
62
77
|
scan_for_packaged_rubies
|
63
78
|
else
|
@@ -73,6 +88,8 @@ module PDK
|
|
73
88
|
end
|
74
89
|
|
75
90
|
def bin_path
|
91
|
+
require 'pdk/util'
|
92
|
+
|
76
93
|
if PDK::Util.package_install?
|
77
94
|
File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', ruby_version, 'bin')
|
78
95
|
else
|
@@ -81,6 +98,8 @@ module PDK
|
|
81
98
|
end
|
82
99
|
|
83
100
|
def gem_paths_raw
|
101
|
+
require 'pdk/util'
|
102
|
+
|
84
103
|
if PDK::Util.package_install?
|
85
104
|
# Subprocesses use their own set of gems which are managed by pdk or
|
86
105
|
# installed with the package. We also include the separate gem path
|
@@ -88,14 +107,12 @@ module PDK
|
|
88
107
|
[
|
89
108
|
File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', ruby_version, 'lib', 'ruby', 'gems', versions[ruby_version]),
|
90
109
|
File.join(PDK::Util.package_cachedir, 'ruby', versions[ruby_version]),
|
91
|
-
File.join(PDK::Util.pdk_package_basedir, 'private', 'puppet', 'ruby', versions[ruby_version])
|
110
|
+
File.join(PDK::Util.pdk_package_basedir, 'private', 'puppet', 'ruby', versions[ruby_version])
|
92
111
|
]
|
93
112
|
else
|
94
113
|
# This allows the subprocess to find the 'bundler' gem, which isn't
|
95
114
|
# in GEM_HOME for gem installs.
|
96
|
-
|
97
|
-
# gem... Perhaps can be replaced with "Gem.path"?
|
98
|
-
[File.absolute_path(File.join(`gem which bundler`, '..', '..', '..', '..'))]
|
115
|
+
[File.absolute_path(File.join(bundler_basedir, '..', '..', '..'))]
|
99
116
|
end
|
100
117
|
end
|
101
118
|
|
@@ -104,6 +121,9 @@ module PDK
|
|
104
121
|
end
|
105
122
|
|
106
123
|
def gem_home
|
124
|
+
require 'pdk/util'
|
125
|
+
|
126
|
+
# TODO: bundle install --path is deprecated
|
107
127
|
# `bundle install --path` ignores all "system" installed gems and
|
108
128
|
# causes unnecessary package installs. `bundle install` (without
|
109
129
|
# --path) installs into GEM_HOME, which by default is non-user
|
@@ -118,10 +138,10 @@ module PDK
|
|
118
138
|
def available_puppet_versions
|
119
139
|
return @available_puppet_versions unless @available_puppet_versions.nil?
|
120
140
|
|
121
|
-
puppet_spec_files =
|
141
|
+
puppet_spec_files = PDK::Util::Filesystem.glob(File.join(gem_home, 'specifications', '**', 'puppet*.gemspec'))
|
122
142
|
|
123
143
|
gem_path.split(File::PATH_SEPARATOR).each do |path|
|
124
|
-
puppet_spec_files +=
|
144
|
+
puppet_spec_files += PDK::Util::Filesystem.glob(File.join(path, 'specifications', '**', 'puppet*.gemspec'))
|
125
145
|
end
|
126
146
|
|
127
147
|
puppet_specs = []
|
@@ -131,7 +151,7 @@ module PDK
|
|
131
151
|
puppet_specs << spec if spec.name == 'puppet'
|
132
152
|
end
|
133
153
|
|
134
|
-
@available_puppet_versions = puppet_specs.map(&:version).sort
|
154
|
+
@available_puppet_versions = puppet_specs.map(&:version).sort.reverse
|
135
155
|
end
|
136
156
|
|
137
157
|
private
|
@@ -143,6 +163,10 @@ module PDK
|
|
143
163
|
def versions
|
144
164
|
self.class.versions
|
145
165
|
end
|
166
|
+
|
167
|
+
def bundler_basedir
|
168
|
+
Gem::Specification.latest_specs.find { |spec| spec.name.eql?('bundler') }.base_dir
|
169
|
+
end
|
146
170
|
end
|
147
171
|
end
|
148
172
|
end
|