Skip to content

Commit d9b3a63

Browse files
committed
loadjson: do not send http_basic_authentication if not needed
1 parent 64d87d2 commit d9b3a63

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/puppet/parser/functions/loadjson.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ module Puppet::Parser::Functions
2828
require 'open-uri'
2929
begin
3030
if args[0].start_with?('http://', 'https://')
31-
username = ''
32-
password = ''
31+
http_options = {}
3332
if (match = args[0].match(%r{(http\://|https\://)(.*):(.*)@(.*)}))
3433
# If URL is in the format of https://username:password@example.local/my_hash.yaml
3534
protocol, username, password, path = match.captures
3635
url = "#{protocol}#{path}"
36+
http_options[:http_basic_authentication]= [username,password]
3737
elsif (match = args[0].match(%r{(http\:\/\/|https\:\/\/)(.*)@(.*)}))
3838
# If URL is in the format of https://username@example.local/my_hash.yaml
3939
protocol, username, path = match.captures
4040
url = "#{protocol}#{path}"
41+
http_options[:http_basic_authentication]= [username,password]
4142
else
4243
url = args[0]
4344
end
4445
begin
45-
contents = OpenURI.open_uri(url, http_basic_authentication: [username, password])
46+
contents = OpenURI.open_uri(url, **http_options)
4647
rescue OpenURI::HTTPError => err
4748
res = err.io
4849
warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'")

0 commit comments

Comments
 (0)