Class: Dependabot::Docker::Utils::CredentialsFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/docker/utils/credentials_finder.rb

Constant Summary collapse

AWS_ECR_URL =
/dkr\.ecr\.(?<region>[^.]+)\.amazonaws\.com/
DEFAULT_DOCKER_HUB_REGISTRY =
"registry.hub.docker.com"

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ CredentialsFinder

Returns a new instance of CredentialsFinder.



21
22
23
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 21

def initialize(credentials)
  @credentials = credentials
end

Instance Method Details

#base_registryObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 38

def base_registry
  @base_registry ||= T.let(
    credentials.find do |cred|
      cred["type"] == "docker_registry" && cred.replaces_base?
    end,
    T.nilable(Dependabot::Credential)
  )
  @base_registry ||= Dependabot::Credential.new({ "registry" => DEFAULT_DOCKER_HUB_REGISTRY,
                                                  "credentials" => nil })
  @base_registry["registry"]
end

#credentials_for_registry(registry_hostname) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 26

def credentials_for_registry(registry_hostname)
  registry_details =
    credentials
    .select { |cred| cred["type"] == "docker_registry" }
    .find { |cred| cred.fetch("registry") == registry_hostname }
  return unless registry_details
  return registry_details unless registry_hostname.match?(AWS_ECR_URL)

  build_aws_credentials(registry_details)
end

#using_dockerhub?(registry) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 51

def using_dockerhub?(registry)
  registry == DEFAULT_DOCKER_HUB_REGISTRY
end