Class: Dependabot::Maven::Utils::AuthHeadersFinder
- Inherits:
-
Object
- Object
- Dependabot::Maven::Utils::AuthHeadersFinder
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/maven/utils/auth_headers_finder.rb
Instance Method Summary collapse
- #auth_headers(maven_repo_url) ⇒ Object
-
#initialize(credentials) ⇒ AuthHeadersFinder
constructor
A new instance of AuthHeadersFinder.
Constructor Details
#initialize(credentials) ⇒ AuthHeadersFinder
Returns a new instance of AuthHeadersFinder.
13 14 15 |
# File 'lib/dependabot/maven/utils/auth_headers_finder.rb', line 13 def initialize(credentials) @credentials = credentials end |
Instance Method Details
#auth_headers(maven_repo_url) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dependabot/maven/utils/auth_headers_finder.rb', line 18 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 |