Skip to content

Commit

Permalink
Registry: provide response body on auth token request failure (#51)
Browse files Browse the repository at this point in the history
* Registry: provide response body on auth token request failure

* Clone.swift: fix typo
  • Loading branch information
edigaryev authored May 6, 2022
1 parent f20a98b commit 4a60c41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 4a60c41

Please sign in to comment.