Skip to content

Commit

Permalink
Merge pull request #1050 from ekohl/deal-with-net-ftp-as-default-gem
Browse files Browse the repository at this point in the history
Deal with net-ftp being unavailable
  • Loading branch information
chelnak authored Aug 17, 2022
2 parents 06207c3 + ea68ea5 commit 8b15f6f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/puppet/provider/apt_key/apt_key.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

require 'open-uri'
require 'net/ftp'
begin
require 'net/ftp'
rescue LoadError
# Ruby 3.0 changed net-ftp to a default gem
end
require 'tempfile'

Puppet::Type.type(:apt_key).provide(:apt_key) do
Expand Down Expand Up @@ -124,6 +128,9 @@ def source_to_file(value)
f.close
f
else
exceptions = [OpenURI::HTTPError]
exceptions << Net::FTPPermError if defined?(Net::FTPPermError)

begin
# Only send basic auth if URL contains userinfo
# Some webservers (e.g. Amazon S3) return code 400 if empty basic auth is sent
Expand All @@ -138,7 +145,7 @@ def source_to_file(value)
parsed_value.userinfo = ''
key = open(parsed_value, http_basic_authentication: user_pass).read
end
rescue OpenURI::HTTPError, Net::FTPPermError => e
rescue *exceptions => e
raise(_('%{_e} for %{_resource}') % { _e: e.message, _resource: resource[:source] })
rescue SocketError
raise(_('could not resolve %{_resource}') % { _resource: resource[:source] })
Expand Down

0 comments on commit 8b15f6f

Please sign in to comment.