Skip to content

Commit

Permalink
Fix up detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Nov 13, 2024
1 parent cc7c6b8 commit f14f2ab
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions default_i8_delegates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,28 @@ def httpsource_resource_info(options = {})
# Get hash of down-case'd headers to templates for an Authorization header.
def _auth_headers
{
'X-DGI-I8-Helper-Authorization-Token': "Bearer %{value}",
'Authorization': "%{value}",
}.transform_keys { |k| k.downcase }
# Bare token, needs to be formatted.
"X-DGI-I8-Helper-Authorization-Token" => "Bearer %{value}",
# Formatted token, just need to pass it along.
"Authorization" => "%{value}"
}.transform_keys! { |k| k.downcase }
end

# Get the auth headers present in the request headers.
def _context_auth_headers
request_headers = context['request_headers'].to_h.transform_keys { |k| k.downcase }
headers = request_headers.select { |k, v| _auth_headers.include?(k) }
raise "Too many auth headers. Only one of #{_auth_headers.keys} expected." if headers.size > 1
request_headers = context['request_headers'].to_h.transform_keys! { |k| k.downcase }
headers = _auth_headers.to_a.map do |item|
k, v = item
if request_headers.include?(k)
[k, request_headers[k]]
else
[k, nil]
end
end.to_h.compact

if headers.size > 1
raise "Too many auth headers. Only one of #{_auth_headers.keys} expected."
end
return headers
end

Expand Down Expand Up @@ -116,8 +128,6 @@ def _fetch(uri, limit = 10)
head[header] = value
end

$logger.debug("Fetching from #{uri}, headers assembled: #{head.to_hash}")

# XXX: Ideally, we could use some form of connection pooling or
# something here.
Net::HTTP.start head.uri.host, head.uri.port, :use_ssl => uri.is_a?(URI::HTTPS) do |http|
Expand Down

0 comments on commit f14f2ab

Please sign in to comment.