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

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

Constant Summary collapse

AWS_ECR_URL =
/dkr\.ecr\.(?<region>[^.]+)\.amazonaws\.com/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ CredentialsFinder

Returns a new instance of CredentialsFinder.



14
15
16
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 14

def initialize(credentials)
  @credentials = credentials
end

Instance Method Details

#credentials_for_registry(registry_hostname) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/dependabot/docker/utils/credentials_finder.rb', line 18

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