Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/puppetfile-resolver/spec_searchers/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def self.fetch_all_module_releases(owner, name, resolver_ui, config, &block)
err_msg += config.proxy ? " with proxy #{config.proxy}: " : ': '
response = nil

auth_token = config.token if config.respond_to?(:token)

begin
response = ::PuppetfileResolver::Util.net_http_get(uri, config.proxy)
response = ::PuppetfileResolver::Util.net_http_get(uri, config.proxy, auth_token)
rescue ::StandardError => e
raise err_msg + e.message
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def forge_api

attr_writer :forge_api

attr_accessor :proxy
attr_accessor :proxy, :token
end
end
end
8 changes: 6 additions & 2 deletions lib/puppetfile-resolver/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.static_ca_cert_file
# @param [String, URI] uri The URI to request
# @param [nil, String, URI] proxy The URI of the proxy server to use. Defaults to nil (No proxy server)
# @return [Net::HTTPResponse] the response of the request
def self.net_http_get(uri, proxy = nil)
def self.net_http_get(uri, proxy = nil, token = nil)
uri = URI.parse(uri) unless uri.is_a?(URI)

http_options = { :use_ssl => uri.instance_of?(URI::HTTPS) }
Expand All @@ -42,7 +42,11 @@ def self.net_http_get(uri, proxy = nil)
start_args.concat([proxy.host, proxy.port, proxy.user, proxy.password])
end

Net::HTTP.start(*start_args, http_options) { |http| return http.request(Net::HTTP::Get.new(uri)) }
Net::HTTP.start(*start_args, http_options) do |http|
request = Net::HTTP::Get.new(uri)
request['Authorization'] = token unless token.nil?
return http.request(request)
end
nil
end

Expand Down
Loading