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

Registry: provide response body on auth token request failure #51

Merged
merged 2 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/tart/Commands/Clone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ struct Clone: AsyncParsableCommand {
let registry = try Registry(host: remoteName.host, namespace: remoteName.namespace)
try await VMStorageOCI().pull(remoteName, registry: registry)
}
let removeVM = try VMStorageHelper.open(sourceName)
let remoteVM = try VMStorageHelper.open(sourceName)

let removeConfig = try VMConfig.init(fromURL: removeVM.configURL)
let needToGenerateNewMAC = try localVMExistsWith(macAddress: removeConfig.macAddress.string)
let remoteConfig = try VMConfig.init(fromURL: remoteVM.configURL)
let needToGenerateNewMAC = try localVMExistsWith(macAddress: remoteConfig.macAddress.string)

try removeVM.clone(to: VMStorageLocal().create(newName), generateMAC: needToGenerateNewMAC)
try remoteVM.clone(to: VMStorageLocal().create(newName), generateMAC: needToGenerateNewMAC)
} else {
try VMStorageHelper.open(sourceName).clone(to: VMStorageLocal().create(newName), generateMAC: true)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/tart/OCI/Registry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
enum RegistryError: Error {
case UnexpectedHTTPStatusCode(when: String, code: Int, details: String = "")
case MissingLocationHeader
case AuthFailed(why: String)
case AuthFailed(why: String, details: String = "")
case MalformedHeader(why: String)
}

Expand Down Expand Up @@ -202,7 +202,7 @@ class Registry {
let (responseData, response) = try await rawRequest("GET", authenticateURL, headers: headers)
if response.statusCode != 200 {
throw RegistryError.AuthFailed(why: "received unexpected HTTP status code \(response.statusCode) "
+ "while retrieving an authentication token")
+ "while retrieving an authentication token", details: String(decoding: responseData, as: UTF8.self))
}

token = try JSONDecoder().decode(TokenResponse.self, from: responseData).token
Expand Down