Class: Dependabot::Python::AuthedUrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/python/authed_url_builder.rb

Class Method Summary collapse

Class Method Details

.authed_url(credential:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dependabot/python/authed_url_builder.rb', line 6

def self.authed_url(credential:)
  token = credential.fetch("token", nil)
  url = credential.fetch("index-url")
  return url unless token

  basic_auth_details =
    if token.ascii_only? && token.include?(":") then token
    elsif Base64.decode64(token).ascii_only? &&
          Base64.decode64(token).include?(":")
      Base64.decode64(token)
    else token
    end

  url.sub("://", "://#{basic_auth_details}@")
end