Class: Dependabot::Maven::Utils::AuthHeadersFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/maven/utils/auth_headers_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ AuthHeadersFinder

Returns a new instance of AuthHeadersFinder.



7
8
9
# File 'lib/dependabot/maven/utils/auth_headers_finder.rb', line 7

def initialize(credentials)
  @credentials = credentials
end

Instance Method Details

#auth_headers(maven_repo_url) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dependabot/maven/utils/auth_headers_finder.rb', line 11

def auth_headers(maven_repo_url)
  cred =
    credentials.select { |c| c["type"] == "maven_repository" }.
    find do |c|
      cred_url = c.fetch("url").gsub(%r{/+$}, "")
      next false unless cred_url == maven_repo_url

      c.fetch("username", nil)
    end

  return gitlab_auth_headers(maven_repo_url) unless cred

  token = cred.fetch("username") + ":" + cred.fetch("password")
  encoded_token = Base64.strict_encode64(token)
  { "Authorization" => "Basic #{encoded_token}" }
end