Class: Dependabot::Shared::Utils::CredentialsFinder
- Inherits:
-
Object
- Object
- Dependabot::Shared::Utils::CredentialsFinder
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/shared/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
- #base_registry ⇒ Object
- #credentials_for_registry(registry_hostname) ⇒ Object
-
#initialize(credentials, private_repository_type: "docker_registry") ⇒ CredentialsFinder
constructor
A new instance of CredentialsFinder.
- #using_dockerhub?(registry) ⇒ Boolean
Constructor Details
#initialize(credentials, private_repository_type: "docker_registry") ⇒ CredentialsFinder
Returns a new instance of CredentialsFinder.
21 22 23 24 |
# File 'lib/dependabot/shared/utils/credentials_finder.rb', line 21 def initialize(credentials, private_repository_type: "docker_registry") @credentials = credentials @private_repository_type = private_repository_type end |
Instance Method Details
#base_registry ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dependabot/shared/utils/credentials_finder.rb', line 39 def base_registry @base_registry ||= T.let( credentials.find do |cred| cred["type"] == private_repository_type && 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
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dependabot/shared/utils/credentials_finder.rb', line 27 def credentials_for_registry(registry_hostname) registry_details = credentials .select { |cred| cred["type"] == private_repository_type } .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
52 53 54 |
# File 'lib/dependabot/shared/utils/credentials_finder.rb', line 52 def using_dockerhub?(registry) registry == DEFAULT_DOCKER_HUB_REGISTRY end |