Skip to content

Commit

Permalink
Strict type Dependabot::Maven::AuthHeadersFinder. (#10000)
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-meka committed Jun 14, 2024
1 parent 7d291b8 commit ba31c4f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions maven/lib/dependabot/maven/utils/auth_headers_finder.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "sorbet-runtime"

module Dependabot
module Maven
module Utils
class AuthHeadersFinder
extend T::Sig

sig { params(credentials: T::Array[Dependabot::Credential]).void }
def initialize(credentials)
@credentials = credentials
end

sig { params(maven_repo_url: String).returns(T::Hash[String, String]) }
def auth_headers(maven_repo_url)
cred =
credentials.select { |c| c["type"] == "maven_repository" }
Expand All @@ -28,10 +34,12 @@ def auth_headers(maven_repo_url)

private

sig { returns(T::Array[Dependabot::Credential]) }
attr_reader :credentials

sig { params(maven_repo_url: T.any(URI::Generic, String)).returns(T::Hash[T.untyped, T.untyped]) }
def gitlab_auth_headers(maven_repo_url)
return {} unless gitlab_maven_repo?(URI(maven_repo_url).path)
return {} unless gitlab_maven_repo?(T.must(URI(maven_repo_url).path))

cred =
credentials.select { |c| c["type"] == "git_source" }
Expand All @@ -47,6 +55,7 @@ def gitlab_auth_headers(maven_repo_url)
{ "Private-Token" => cred.fetch("password") }
end

sig { params(maven_repo_path: String).returns(T::Boolean) }
def gitlab_maven_repo?(maven_repo_path)
gitlab_maven_repo_reg = %r{^/api/v4.*/packages/maven/?$}
maven_repo_path.match?(gitlab_maven_repo_reg)
Expand Down

0 comments on commit ba31c4f

Please sign in to comment.