Skip to content

Commit ea68ea5

Browse files
committed
Deal with net-ftp being unavailable
In Ruby 3.0 net-ftp changed from a bundled gem to a default gem. This means it may not be available, such as when running unit tests. Since ftp is becoming less and less common, this changes net-ftp to be an optional dependency. Users who do need ftp support should ensure the gem is installed.
1 parent 4b12e7b commit ea68ea5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/puppet/provider/apt_key/apt_key.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# frozen_string_literal: true
22

33
require 'open-uri'
4-
require 'net/ftp'
4+
begin
5+
require 'net/ftp'
6+
rescue LoadError
7+
# Ruby 3.0 changed net-ftp to a default gem
8+
end
59
require 'tempfile'
610

711
Puppet::Type.type(:apt_key).provide(:apt_key) do
@@ -124,6 +128,9 @@ def source_to_file(value)
124128
f.close
125129
f
126130
else
131+
exceptions = [OpenURI::HTTPError]
132+
exceptions << Net::FTPPermError if defined?(Net::FTPPermError)
133+
127134
begin
128135
# Only send basic auth if URL contains userinfo
129136
# Some webservers (e.g. Amazon S3) return code 400 if empty basic auth is sent
@@ -138,7 +145,7 @@ def source_to_file(value)
138145
parsed_value.userinfo = ''
139146
key = open(parsed_value, http_basic_authentication: user_pass).read
140147
end
141-
rescue OpenURI::HTTPError, Net::FTPPermError => e
148+
rescue *exceptions => e
142149
raise(_('%{_e} for %{_resource}') % { _e: e.message, _resource: resource[:source] })
143150
rescue SocketError
144151
raise(_('could not resolve %{_resource}') % { _resource: resource[:source] })

0 commit comments

Comments
 (0)