From 15b26f78ae2bfc5dc2d9118b698ec22ae957f9a5 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Mon, 5 Dec 2022 18:56:48 +0400 Subject: [PATCH] Registry: include port when looking up credentials (#346) --- Sources/tart/OCI/Registry.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/tart/OCI/Registry.swift b/Sources/tart/OCI/Registry.swift index 0b787aa..d904660 100644 --- a/Sources/tart/OCI/Registry.swift +++ b/Sources/tart/OCI/Registry.swift @@ -313,7 +313,7 @@ class Registry { let wwwAuthenticate = try WWWAuthenticate(rawHeaderValue: wwwAuthenticateRaw) if wwwAuthenticate.scheme.lowercased() == "basic" { - if let (user, password) = try lookupCredentials(host: baseURL.host!) { + if let (user, password) = try lookupCredentials() { currentAuthToken = BasicAuthentication(user: user, password: password) } @@ -350,7 +350,7 @@ class Registry { var headers: Dictionary = Dictionary() - if let (user, password) = try lookupCredentials(host: baseURL.host!) { + if let (user, password) = try lookupCredentials() { let encodedCredentials = "\(user):\(password)".data(using: .utf8)?.base64EncodedString() headers["Authorization"] = "Basic \(encodedCredentials!)" } @@ -364,7 +364,13 @@ class Registry { currentAuthToken = try TokenResponse.parse(fromData: data) } - private func lookupCredentials(host: String) throws -> (String, String)? { + private func lookupCredentials() throws -> (String, String)? { + var host = baseURL.host! + + if let port = baseURL.port { + host += ":\(port)" + } + for provider in credentialsProviders { if let (user, password) = try provider.retrieve(host: host) { return (user, password)