pdk-akerl 1.9.1.1 → 1.14.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +180 -0
- data/README.md +43 -4
- data/lib/pdk.rb +4 -2
- data/lib/pdk/analytics.rb +44 -0
- data/lib/pdk/analytics/client/google_analytics.rb +141 -0
- data/lib/pdk/analytics/client/noop.rb +23 -0
- data/lib/pdk/analytics/util.rb +17 -0
- data/lib/pdk/answer_file.rb +4 -1
- data/lib/pdk/cli.rb +50 -3
- data/lib/pdk/cli/build.rb +10 -4
- data/lib/pdk/cli/bundle.rb +10 -8
- data/lib/pdk/cli/config.rb +20 -0
- data/lib/pdk/cli/config/get.rb +24 -0
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +7 -2
- data/lib/pdk/cli/exec.rb +22 -190
- data/lib/pdk/cli/exec/command.rb +238 -0
- data/lib/pdk/cli/exec/interactive_command.rb +114 -0
- data/lib/pdk/cli/exec_group.rb +6 -6
- data/lib/pdk/cli/module/build.rb +0 -2
- data/lib/pdk/cli/module/generate.rb +4 -2
- data/lib/pdk/cli/new.rb +2 -0
- data/lib/pdk/cli/new/class.rb +2 -2
- data/lib/pdk/cli/new/defined_type.rb +4 -2
- data/lib/pdk/cli/new/module.rb +5 -0
- data/lib/pdk/cli/new/provider.rb +4 -2
- data/lib/pdk/cli/new/task.rb +4 -1
- data/lib/pdk/cli/new/test.rb +53 -0
- data/lib/pdk/cli/new/transport.rb +27 -0
- data/lib/pdk/cli/test.rb +0 -1
- data/lib/pdk/cli/test/unit.rb +18 -13
- data/lib/pdk/cli/update.rb +25 -3
- data/lib/pdk/cli/util.rb +111 -14
- data/lib/pdk/cli/util/interview.rb +10 -2
- data/lib/pdk/cli/util/option_validator.rb +4 -0
- data/lib/pdk/cli/util/spinner.rb +13 -0
- data/lib/pdk/cli/validate.rb +16 -5
- data/lib/pdk/config.rb +121 -0
- data/lib/pdk/config/analytics_schema.json +26 -0
- data/lib/pdk/config/errors.rb +5 -0
- data/lib/pdk/config/json.rb +34 -0
- data/lib/pdk/config/json_schema_namespace.rb +143 -0
- data/lib/pdk/config/json_schema_setting.rb +53 -0
- data/lib/pdk/config/json_with_schema.rb +50 -0
- data/lib/pdk/config/namespace.rb +332 -0
- data/lib/pdk/config/setting.rb +132 -0
- data/lib/pdk/config/yaml.rb +43 -0
- data/lib/pdk/config/yaml_with_schema.rb +59 -0
- data/lib/pdk/generate.rb +10 -3
- data/lib/pdk/generate/defined_type.rb +1 -0
- data/lib/pdk/generate/module.rb +62 -35
- data/lib/pdk/generate/provider.rb +0 -5
- data/lib/pdk/generate/puppet_class.rb +1 -0
- data/lib/pdk/generate/puppet_object.rb +88 -41
- data/lib/pdk/generate/transport.rb +87 -0
- data/lib/pdk/logger.rb +21 -1
- data/lib/pdk/module.rb +2 -2
- data/lib/pdk/module/build.rb +103 -10
- data/lib/pdk/module/convert.rb +85 -19
- data/lib/pdk/module/metadata.rb +17 -12
- data/lib/pdk/module/templatedir.rb +108 -40
- data/lib/pdk/module/update.rb +27 -15
- data/lib/pdk/module/update_manager.rb +23 -15
- data/lib/pdk/report.rb +4 -3
- data/lib/pdk/report/event.rb +8 -6
- data/lib/pdk/template_file.rb +1 -1
- data/lib/pdk/tests/unit.rb +48 -21
- data/lib/pdk/util.rb +29 -63
- data/lib/pdk/util/bundler.rb +19 -15
- data/lib/pdk/util/filesystem.rb +64 -1
- data/lib/pdk/util/git.rb +52 -1
- data/lib/pdk/util/puppet_strings.rb +123 -0
- data/lib/pdk/util/puppet_version.rb +27 -12
- data/lib/pdk/util/ruby_version.rb +30 -7
- data/lib/pdk/util/template_uri.rb +281 -0
- data/lib/pdk/util/vendored_file.rb +28 -24
- data/lib/pdk/util/version.rb +7 -8
- data/lib/pdk/util/windows.rb +1 -0
- data/lib/pdk/util/windows/api_types.rb +0 -7
- data/lib/pdk/util/windows/file.rb +1 -1
- data/lib/pdk/util/windows/string.rb +1 -1
- data/lib/pdk/validate/base_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -4
- data/lib/pdk/validate/metadata/metadata_syntax.rb +5 -3
- data/lib/pdk/validate/metadata_validator.rb +0 -2
- data/lib/pdk/validate/puppet/puppet_epp.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
- data/lib/pdk/validate/puppet/puppet_syntax.rb +5 -5
- data/lib/pdk/validate/puppet_validator.rb +2 -3
- data/lib/pdk/validate/ruby/rubocop.rb +1 -6
- data/lib/pdk/validate/ruby_validator.rb +0 -2
- data/lib/pdk/validate/tasks/metadata_lint.rb +9 -5
- data/lib/pdk/validate/tasks/name.rb +5 -3
- data/lib/pdk/validate/tasks_validator.rb +0 -2
- data/lib/pdk/validate/yaml/syntax.rb +6 -4
- data/lib/pdk/validate/yaml_validator.rb +0 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +634 -307
- metadata +100 -45
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'forwardable'
|
2
2
|
|
3
3
|
module PDK
|
4
4
|
module Util
|
@@ -8,6 +8,8 @@ module PDK
|
|
8
8
|
|
9
9
|
def_delegators :instance, :gem_path, :gem_paths_raw, :gem_home, :available_puppet_versions, :bin_path
|
10
10
|
|
11
|
+
# TODO: resolve this
|
12
|
+
# rubocop:disable Lint/DuplicateMethods
|
11
13
|
attr_reader :instance
|
12
14
|
|
13
15
|
def instance(version = nil)
|
@@ -21,6 +23,7 @@ module PDK
|
|
21
23
|
end
|
22
24
|
@instance[active_ruby_version]
|
23
25
|
end
|
26
|
+
# rubocop:enable Lint/DuplicateMethods
|
24
27
|
|
25
28
|
def active_ruby_version
|
26
29
|
@active_ruby_version || default_ruby_version
|
@@ -37,6 +40,8 @@ module PDK
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def scan_for_packaged_rubies
|
43
|
+
require 'pdk/util'
|
44
|
+
|
40
45
|
ruby_basedir = File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', '*')
|
41
46
|
Dir[ruby_basedir].sort.map { |ruby_dir|
|
42
47
|
version = File.basename(ruby_dir)
|
@@ -45,12 +50,22 @@ module PDK
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def default_ruby_version
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
require 'pdk/util'
|
54
|
+
require 'pdk/util/puppet_version'
|
55
|
+
|
56
|
+
@default_ruby_version ||= if PDK::Util.package_install?
|
57
|
+
# Default to the ruby that supports the latest puppet gem. If you wish to default to a
|
58
|
+
# specific Puppet Gem version use the following example;
|
59
|
+
#
|
60
|
+
# PDK::Util::PuppetVersion.find_gem_for('5.5.10')[:ruby_version]
|
61
|
+
#
|
62
|
+
PDK::Util::PuppetVersion.latest_available[:ruby_version]
|
63
|
+
else
|
64
|
+
# TODO: may not be a safe assumption that highest available version should be default
|
65
|
+
# WARNING Do NOT use PDK::Util::PuppetVersion.*** methods as it can recurse into this
|
66
|
+
# method and cause Stack Level Too Deep errors.
|
67
|
+
latest_ruby_version
|
68
|
+
end
|
54
69
|
end
|
55
70
|
|
56
71
|
def latest_ruby_version
|
@@ -58,6 +73,8 @@ module PDK
|
|
58
73
|
end
|
59
74
|
|
60
75
|
def versions
|
76
|
+
require 'pdk/util'
|
77
|
+
|
61
78
|
@versions ||= if PDK::Util.package_install?
|
62
79
|
scan_for_packaged_rubies
|
63
80
|
else
|
@@ -73,6 +90,8 @@ module PDK
|
|
73
90
|
end
|
74
91
|
|
75
92
|
def bin_path
|
93
|
+
require 'pdk/util'
|
94
|
+
|
76
95
|
if PDK::Util.package_install?
|
77
96
|
File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', ruby_version, 'bin')
|
78
97
|
else
|
@@ -81,6 +100,8 @@ module PDK
|
|
81
100
|
end
|
82
101
|
|
83
102
|
def gem_paths_raw
|
103
|
+
require 'pdk/util'
|
104
|
+
|
84
105
|
if PDK::Util.package_install?
|
85
106
|
# Subprocesses use their own set of gems which are managed by pdk or
|
86
107
|
# installed with the package. We also include the separate gem path
|
@@ -104,6 +125,8 @@ module PDK
|
|
104
125
|
end
|
105
126
|
|
106
127
|
def gem_home
|
128
|
+
require 'pdk/util'
|
129
|
+
|
107
130
|
# `bundle install --path` ignores all "system" installed gems and
|
108
131
|
# causes unnecessary package installs. `bundle install` (without
|
109
132
|
# --path) installs into GEM_HOME, which by default is non-user
|
@@ -0,0 +1,281 @@
|
|
1
|
+
module PDK
|
2
|
+
module Util
|
3
|
+
class TemplateURI
|
4
|
+
SCP_PATTERN = %r{\A(?!\w+://)(?:(?<user>.+?)@)?(?<host>[^:/]+):(?<path>.+)\z}
|
5
|
+
|
6
|
+
PACKAGED_TEMPLATE_KEYWORD = 'pdk-default'.freeze
|
7
|
+
DEPRECATED_TEMPLATE_URL = 'https://github.com/puppetlabs/pdk-module-template'.freeze
|
8
|
+
|
9
|
+
LEGACY_PACKAGED_TEMPLATE_PATHS = {
|
10
|
+
'windows' => 'file:///C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git',
|
11
|
+
'macos' => 'file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git',
|
12
|
+
'linux' => 'file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git',
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
# XXX Previously
|
16
|
+
# - template_uri used to get the string form of the uri when generating the module and written to pdk answers and metadata
|
17
|
+
# - template_path or deuri_path used for humans to see and commands to run
|
18
|
+
# - uri_path used only internally by the template selection code; move out
|
19
|
+
# - template_ref used by git checkout
|
20
|
+
attr_reader :uri
|
21
|
+
|
22
|
+
# input/output formats:
|
23
|
+
#
|
24
|
+
# file:///c:/foo (git clone location)
|
25
|
+
# c:/foo (shell paths)
|
26
|
+
# file:///c:/foo#master (only for metadata)
|
27
|
+
# c:/foo#master (only for metadata)
|
28
|
+
#
|
29
|
+
# non output formats:
|
30
|
+
#
|
31
|
+
# /c:/foo (internal use only)
|
32
|
+
# /c:/foo#master (internal use only)
|
33
|
+
#
|
34
|
+
def initialize(opts_or_uri)
|
35
|
+
require 'addressable'
|
36
|
+
|
37
|
+
# If a uri string is passed, skip the valid uri finding code.
|
38
|
+
@uri = if opts_or_uri.is_a?(self.class)
|
39
|
+
opts_or_uri.uri
|
40
|
+
elsif opts_or_uri.is_a?(String)
|
41
|
+
begin
|
42
|
+
uri, ref = opts_or_uri.split('#', 2)
|
43
|
+
if self.class.packaged_template?(uri)
|
44
|
+
self.class.default_template_uri(ref).uri
|
45
|
+
else
|
46
|
+
Addressable::URI.parse(opts_or_uri)
|
47
|
+
end
|
48
|
+
rescue Addressable::URI::InvalidURIError
|
49
|
+
raise PDK::CLI::FatalError, _('PDK::Util::TemplateURI attempted initialization with a non-uri string: {string}') % { string: opts_or_uri }
|
50
|
+
end
|
51
|
+
elsif opts_or_uri.is_a?(Addressable::URI)
|
52
|
+
opts_or_uri.dup
|
53
|
+
else
|
54
|
+
self.class.first_valid_uri(self.class.templates(opts_or_uri))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def ==(other)
|
59
|
+
@uri == other.uri
|
60
|
+
end
|
61
|
+
|
62
|
+
# This is the URI represented in a format suitable for writing to
|
63
|
+
# metadata.
|
64
|
+
#
|
65
|
+
# @returns String
|
66
|
+
def metadata_format
|
67
|
+
if self.class.packaged_template?(git_remote)
|
68
|
+
self.class.human_readable("pdk-default##{git_ref}")
|
69
|
+
else
|
70
|
+
self.class.human_readable(@uri.to_s)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias to_s metadata_format
|
74
|
+
alias to_str metadata_format
|
75
|
+
|
76
|
+
# This is the url without a fragment, suitable for git clones.
|
77
|
+
#
|
78
|
+
# @returns String
|
79
|
+
def git_remote
|
80
|
+
self.class.git_remote(@uri)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.git_remote(uri)
|
84
|
+
require 'addressable'
|
85
|
+
|
86
|
+
if uri.is_a?(Addressable::URI) && uri.fragment
|
87
|
+
human_readable(uri.to_s.chomp('#' + uri.fragment))
|
88
|
+
else
|
89
|
+
human_readable(uri.to_s)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# This is the path of the URI, suitable for accessing directly from the shell.
|
94
|
+
# @returns String
|
95
|
+
def shell_path
|
96
|
+
self.class.human_readable(@uri.path)
|
97
|
+
end
|
98
|
+
|
99
|
+
# @returns String
|
100
|
+
def git_ref
|
101
|
+
@uri.fragment || self.class.default_template_ref(self)
|
102
|
+
end
|
103
|
+
|
104
|
+
def git_ref=(ref)
|
105
|
+
@uri.fragment = ref
|
106
|
+
end
|
107
|
+
|
108
|
+
# @returns PDK::Util::TemplateURI
|
109
|
+
def self.default_template_uri(ref = nil)
|
110
|
+
require 'pdk/util'
|
111
|
+
require 'addressable'
|
112
|
+
|
113
|
+
if PDK::Util.package_install?
|
114
|
+
PDK::Util::TemplateURI.new(Addressable::URI.new(scheme: 'file', host: '', path: File.join(PDK::Util.package_cachedir, 'pdk-templates.git'), fragment: ref))
|
115
|
+
else
|
116
|
+
PDK::Util::TemplateURI.new(Addressable::URI.new(scheme: 'https', host: 'github.com', path: '/puppetlabs/pdk-templates', fragment: ref))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def default?
|
121
|
+
git_remote == self.class.default_template_uri.git_remote
|
122
|
+
end
|
123
|
+
|
124
|
+
def ref_is_tag?
|
125
|
+
require 'pdk/util/git'
|
126
|
+
|
127
|
+
PDK::Util::Git.git('ls-remote', '--tags', '--exit-code', git_remote, git_ref)[:exit_code].zero?
|
128
|
+
end
|
129
|
+
|
130
|
+
# `C:...` urls are not URI-safe. They should be of the form `/C:...` to
|
131
|
+
# be URI-safe. scp-like urls like `user@host:/path` are not URI-safe
|
132
|
+
# either and so are subsequently converted to ssh:// URIs.
|
133
|
+
#
|
134
|
+
# @returns String
|
135
|
+
def self.uri_safe(string)
|
136
|
+
url = (Gem.win_platform? && string =~ %r{^[a-zA-Z][\|:]}) ? "/#{string}" : string
|
137
|
+
parse_scp_url(url)
|
138
|
+
end
|
139
|
+
|
140
|
+
# If the passed value is a URI-safe windows path such as `/C:...` then it
|
141
|
+
# should be changed to a human-friendly `C:...` form. Otherwise the
|
142
|
+
# passed value is left alone.
|
143
|
+
#
|
144
|
+
# @returns String
|
145
|
+
def self.human_readable(string)
|
146
|
+
(Gem.win_platform? && string =~ %r{^\/[a-zA-Z][\|:]}) ? string[1..-1] : string
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.parse_scp_url(url)
|
150
|
+
require 'pathname'
|
151
|
+
require 'addressable'
|
152
|
+
|
153
|
+
# Valid URIs to avoid catching:
|
154
|
+
# - absolute local paths
|
155
|
+
# - have :'s in paths when preceeded by a slash
|
156
|
+
# - have only digits following the : and preceeding a / or end-of-string that is 0-65535
|
157
|
+
# The last item is ambiguous in the case of scp/git paths vs. URI port
|
158
|
+
# numbers, but can be made unambiguous by making the form to
|
159
|
+
# ssh://git@github.com/1234/repo.git or
|
160
|
+
# ssh://git@github.com:1234/user/repo.git
|
161
|
+
scp_url = url.match(SCP_PATTERN)
|
162
|
+
return url unless Pathname.new(url).relative? && scp_url
|
163
|
+
|
164
|
+
uri = Addressable::URI.new(scheme: 'ssh', user: scp_url[:user], host: scp_url[:host], path: scp_url[:path])
|
165
|
+
PDK.logger.warn _('%{scp_uri} appears to be an SCP style URL; it will be converted to an RFC compliant URI: %{rfc_uri}') % {
|
166
|
+
scp_uri: url,
|
167
|
+
rfc_uri: uri.to_s,
|
168
|
+
}
|
169
|
+
|
170
|
+
uri.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
# @return [Array<Hash{Symbol => Object}>] an array of hashes. Each hash
|
174
|
+
# contains 3 keys: :type contains a String that describes the template
|
175
|
+
# directory, :url contains a String with the URL to the template
|
176
|
+
# directory, and :allow_fallback contains a Boolean that specifies if
|
177
|
+
# the lookup process should proceed to the next template directory if
|
178
|
+
# the template file is not in this template directory.
|
179
|
+
#
|
180
|
+
def self.templates(opts)
|
181
|
+
require 'pdk/answer_file'
|
182
|
+
require 'pdk/util'
|
183
|
+
require 'addressable'
|
184
|
+
|
185
|
+
explicit_url = opts.fetch(:'template-url', nil)
|
186
|
+
explicit_ref = opts.fetch(:'template-ref', nil)
|
187
|
+
|
188
|
+
# 1. Get the CLI, metadata (or answers if no metadata), and default URIs
|
189
|
+
# 2. Construct the hash
|
190
|
+
if explicit_url
|
191
|
+
explicit_uri = Addressable::URI.parse(uri_safe(explicit_url))
|
192
|
+
explicit_uri.fragment = explicit_ref || default_template_ref(new(explicit_uri))
|
193
|
+
else
|
194
|
+
explicit_uri = nil
|
195
|
+
end
|
196
|
+
metadata_uri = if PDK::Util.module_root && File.file?(File.join(PDK::Util.module_root, 'metadata.json'))
|
197
|
+
if PDK::Util.module_metadata['template-url']
|
198
|
+
new(uri_safe(PDK::Util.module_metadata['template-url'])).uri
|
199
|
+
else
|
200
|
+
nil
|
201
|
+
end
|
202
|
+
else
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
answers_uri = if [PACKAGED_TEMPLATE_KEYWORD, DEPRECATED_TEMPLATE_URL].include?(PDK.answers['template-url'])
|
206
|
+
Addressable::URI.parse(default_template_uri)
|
207
|
+
elsif PDK.answers['template-url']
|
208
|
+
new(uri_safe(PDK.answers['template-url'])).uri
|
209
|
+
else
|
210
|
+
nil
|
211
|
+
end
|
212
|
+
default_uri = default_template_uri.uri
|
213
|
+
default_uri.fragment = default_template_ref(default_template_uri)
|
214
|
+
|
215
|
+
ary = []
|
216
|
+
ary << { type: _('--template-url'), uri: explicit_uri, allow_fallback: false } if explicit_url
|
217
|
+
ary << { type: _('metadata.json'), uri: metadata_uri, allow_fallback: true } if metadata_uri
|
218
|
+
ary << { type: _('PDK answers'), uri: answers_uri, allow_fallback: true } if answers_uri
|
219
|
+
ary << { type: _('default'), uri: default_uri, allow_fallback: false }
|
220
|
+
ary
|
221
|
+
end
|
222
|
+
|
223
|
+
# @returns String
|
224
|
+
def self.default_template_ref(uri = nil)
|
225
|
+
require 'pdk/util'
|
226
|
+
require 'pdk/version'
|
227
|
+
|
228
|
+
return 'master' if PDK::Util.development_mode?
|
229
|
+
return PDK::TEMPLATE_REF if uri.nil?
|
230
|
+
|
231
|
+
uri = new(uri) unless uri.is_a?(self)
|
232
|
+
uri.default? ? PDK::TEMPLATE_REF : 'master'
|
233
|
+
end
|
234
|
+
|
235
|
+
# @returns Addressable::URI
|
236
|
+
def self.first_valid_uri(templates_array)
|
237
|
+
# 1. Get the four sources of URIs
|
238
|
+
# 2. Pick the first non-nil URI
|
239
|
+
# 3. Error if the URI is not a valid git repo (missing directory or http 404)
|
240
|
+
# 4. Leave updating answers/metadata to other code
|
241
|
+
found_template = templates_array.find { |t| valid_template?(t) }
|
242
|
+
|
243
|
+
raise PDK::CLI::FatalError, _('Unable to find a valid module template to use.') if found_template.nil?
|
244
|
+
found_template[:uri]
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.valid_template?(template)
|
248
|
+
require 'addressable'
|
249
|
+
require 'pdk/util/git'
|
250
|
+
require 'pdk/module/templatedir'
|
251
|
+
|
252
|
+
return false if template.nil? || !template.is_a?(Hash)
|
253
|
+
return false if template[:uri].nil? || !template[:uri].is_a?(Addressable::URI)
|
254
|
+
|
255
|
+
return true if PDK::Util::Git.repo?(git_remote(template[:uri]))
|
256
|
+
|
257
|
+
path = human_readable(template[:uri].path)
|
258
|
+
if File.directory?(path)
|
259
|
+
begin
|
260
|
+
PDK::Module::TemplateDir.new(path) {}
|
261
|
+
return true
|
262
|
+
rescue ArgumentError
|
263
|
+
nil
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
unless template[:allow_fallback]
|
268
|
+
raise PDK::CLI::FatalError, _('Unable to find a valid template at %{uri}') % {
|
269
|
+
uri: template[:uri].to_s,
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
273
|
+
false
|
274
|
+
end
|
275
|
+
|
276
|
+
def self.packaged_template?(path)
|
277
|
+
path == PACKAGED_TEMPLATE_KEYWORD || LEGACY_PACKAGED_TEMPLATE_PATHS.value?(path)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
@@ -1,51 +1,50 @@
|
|
1
|
-
require 'pdk/util'
|
2
|
-
require 'net/https'
|
3
|
-
require 'openssl'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'pdk/util/filesystem'
|
6
|
-
|
7
1
|
module PDK
|
8
2
|
module Util
|
9
3
|
class VendoredFile
|
10
4
|
class DownloadError < StandardError; end
|
11
5
|
|
12
|
-
HTTP_ERRORS = [
|
13
|
-
EOFError,
|
14
|
-
Errno::ECONNRESET,
|
15
|
-
Errno::EINVAL,
|
16
|
-
Errno::ECONNREFUSED,
|
17
|
-
Net::HTTPBadResponse,
|
18
|
-
Net::HTTPHeaderSyntaxError,
|
19
|
-
Net::ProtocolError,
|
20
|
-
Timeout::Error,
|
21
|
-
].freeze
|
22
|
-
|
23
6
|
attr_reader :file_name
|
24
7
|
attr_reader :url
|
25
8
|
|
26
|
-
include PDK::Util::Filesystem
|
27
|
-
|
28
9
|
def initialize(file_name, url)
|
29
10
|
@file_name = file_name
|
30
11
|
@url = url
|
31
12
|
end
|
32
13
|
|
33
14
|
def read
|
34
|
-
|
35
|
-
|
15
|
+
require 'pdk/util'
|
16
|
+
require 'pdk/util/filesystem'
|
17
|
+
|
18
|
+
return PDK::Util::Filesystem.read_file(package_vendored_path) if PDK::Util.package_install?
|
19
|
+
return PDK::Util::Filesystem.read_file(gem_vendored_path) if PDK::Util::Filesystem.file?(gem_vendored_path)
|
36
20
|
|
37
21
|
content = download_file
|
38
22
|
|
39
23
|
# TODO: should only write if it's valid JSON
|
40
24
|
# TODO: need a way to invalidate if out of date
|
41
|
-
|
42
|
-
write_file(gem_vendored_path, content)
|
25
|
+
PDK::Util::Filesystem.mkdir_p(File.dirname(gem_vendored_path))
|
26
|
+
PDK::Util::Filesystem.write_file(gem_vendored_path, content)
|
43
27
|
content
|
44
28
|
end
|
45
29
|
|
46
30
|
private
|
47
31
|
|
48
32
|
def download_file
|
33
|
+
require 'uri'
|
34
|
+
require 'net/https'
|
35
|
+
require 'openssl'
|
36
|
+
|
37
|
+
http_errors = [
|
38
|
+
EOFError,
|
39
|
+
Errno::ECONNRESET,
|
40
|
+
Errno::EINVAL,
|
41
|
+
Errno::ECONNREFUSED,
|
42
|
+
Net::HTTPBadResponse,
|
43
|
+
Net::HTTPHeaderSyntaxError,
|
44
|
+
Net::ProtocolError,
|
45
|
+
Timeout::Error,
|
46
|
+
]
|
47
|
+
|
49
48
|
PDK.logger.debug _('%{file_name} was not found in the cache, downloading it from %{url}.') % {
|
50
49
|
file_name: file_name,
|
51
50
|
url: url,
|
@@ -69,7 +68,7 @@ module PDK
|
|
69
68
|
end
|
70
69
|
|
71
70
|
response.body
|
72
|
-
rescue *
|
71
|
+
rescue *http_errors => e
|
73
72
|
raise DownloadError, _('Unable to download %{url}. Check internet connectivity and try again. %{error}') % {
|
74
73
|
url: url,
|
75
74
|
error: e,
|
@@ -77,10 +76,15 @@ module PDK
|
|
77
76
|
end
|
78
77
|
|
79
78
|
def package_vendored_path
|
79
|
+
require 'pdk/util'
|
80
|
+
|
80
81
|
@package_vendored_path ||= File.join(PDK::Util.package_cachedir, file_name)
|
81
82
|
end
|
82
83
|
|
83
84
|
def gem_vendored_path
|
85
|
+
require 'pdk/util'
|
86
|
+
require 'pdk/version'
|
87
|
+
|
84
88
|
@gem_vendored_path ||= File.join(PDK::Util.cachedir, PDK::VERSION, file_name)
|
85
89
|
end
|
86
90
|
end
|