Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict type Dependabot::Docker::Requirement::CredentialsFinder #9889

Merged
Merged
14 changes: 7 additions & 7 deletions docker/lib/dependabot/docker/utils/credentials_finder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "aws-sdk-ecr"
Expand All @@ -16,6 +16,7 @@ class CredentialsFinder
AWS_ECR_URL = /dkr\.ecr\.(?<region>[^.]+)\.amazonaws\.com/
DEFAULT_DOCKER_HUB_REGISTRY = "registry.hub.docker.com"

sig { params(credentials: T::Array[Dependabot::Credential]).void }
def initialize(credentials)
@credentials = credentials
end
Expand All @@ -32,14 +33,13 @@ def credentials_for_registry(registry_hostname)
build_aws_credentials(registry_details)
end

sig { returns(String) }
def base_registry
@base_registry ||= credentials.find do |cred|
cred["type"] == "docker_registry" && cred.replaces_base?
end
@base_registry ||= { "registry" => DEFAULT_DOCKER_HUB_REGISTRY, "credentials" => nil }
@base_registry["registry"]
@base_registry ||= T.let(nil, T.nilable(Dependabot::Credential))
@base_registry&.fetch("registry") || DEFAULT_DOCKER_HUB_REGISTRY
raj-meka marked this conversation as resolved.
Show resolved Hide resolved
end

sig { params(registry: String).returns(T::Boolean) }
def using_dockerhub?(registry)
registry == DEFAULT_DOCKER_HUB_REGISTRY
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def build_aws_credentials(registry_details)

# Otherwise, we need to use the provided Access Key ID and secret to
# generate a temporary username and password
@authorization_tokens ||= {}
@authorization_tokens ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
@authorization_tokens[registry_hostname] ||=
raj-meka marked this conversation as resolved.
Show resolved Hide resolved
ecr_client.get_authorization_token.authorization_data.first.authorization_token
username, password =
Expand Down
7 changes: 6 additions & 1 deletion docker/lib/dependabot/docker/utils/helpers.rb
raj-meka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "sorbet-runtime"
abdulapopoola marked this conversation as resolved.
Show resolved Hide resolved

module Dependabot
module Docker
module Utils
HELM_REGEXP = /values[\-a-zA-Z_0-9]*\.ya?ml$/i

extend T::Sig

sig { params(file: DependencyFile).returns(T::Boolean) }
def self.likely_helm_chart?(file)
file.name.match?(HELM_REGEXP)
end
Expand Down
Loading