Skip to content

Commit 8b15f6f

Browse files
authored
Merge pull request #1050 from ekohl/deal-with-net-ftp-as-default-gem
Deal with net-ftp being unavailable
2 parents 06207c3 + ea68ea5 commit 8b15f6f

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)