mirror of
https://github.com/cirruslabs/tart.git
synced 2026-10-17 19:36:10 +02:00
Registry: suport pulling public images (#50)
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
class Credentials {
|
||||
static func retrieve(host: String) throws -> (String, String) {
|
||||
do {
|
||||
return try retrieveKeychain(host: host)
|
||||
} catch RegistryError.AuthFailed {
|
||||
return try retrieveStdin()
|
||||
}
|
||||
}
|
||||
|
||||
static func retrieveKeychain(host: String) throws -> (String, String) {
|
||||
static func retrieveKeychain(host: String) throws -> (String, String)? {
|
||||
let query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
|
||||
kSecAttrProtocol as String: kSecAttrProtocolHTTPS,
|
||||
kSecAttrServer as String: host,
|
||||
@@ -24,7 +16,7 @@ class Credentials {
|
||||
|
||||
if status != errSecSuccess {
|
||||
if status == errSecItemNotFound {
|
||||
throw RegistryError.AuthFailed(why: "Keychain item not found")
|
||||
return nil
|
||||
}
|
||||
|
||||
throw RegistryError.AuthFailed(why: "Keychain returned unsuccessful status \(status)")
|
||||
|
||||
@@ -192,11 +192,12 @@ class Registry {
|
||||
}
|
||||
}
|
||||
|
||||
let (user, password) = try Credentials.retrieve(host: baseURL.host!)
|
||||
let encodedCredentials = "\(user):\(password)".data(using: .utf8)?.base64EncodedString()
|
||||
let headers = [
|
||||
"Authorization": "Basic \(encodedCredentials!)"
|
||||
]
|
||||
var headers: Dictionary<String, String> = Dictionary()
|
||||
|
||||
if let (user, password) = try Credentials.retrieveKeychain(host: baseURL.host!) {
|
||||
let encodedCredentials = "\(user):\(password)".data(using: .utf8)?.base64EncodedString()
|
||||
headers["Authorization"] = "Basic \(encodedCredentials!)"
|
||||
}
|
||||
|
||||
let (responseData, response) = try await rawRequest("GET", authenticateURL, headers: headers)
|
||||
if response.statusCode != 200 {
|
||||
|
||||
Reference in New Issue
Block a user