-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeployment.swift
36 lines (31 loc) · 1.29 KB
/
Deployment.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Foundation
public extension Client {
func buildInfo() async throws(SDKError) -> BuildInfoResponse {
let res = try await request("/api/v2/buildinfo", method: .get)
guard res.resp.statusCode == 200 else {
throw responseAsError(res)
}
return try decode(BuildInfoResponse.self, from: res.data)
}
func sshConfiguration() async throws(SDKError) -> SSHConfigResponse {
let res = try await request("/api/v2/deployment/ssh", method: .get)
guard res.resp.statusCode == 200 else {
throw responseAsError(res)
}
return try decode(SSHConfigResponse.self, from: res.data)
}
}
public struct BuildInfoResponse: Codable, Equatable, Sendable {
public let version: String
// `version` in the form `[0-9]+.[0-9]+.[0-9]+`
public var semver: String? {
try? NSRegularExpression(pattern: #"v(\d+\.\d+\.\d+)"#)
.firstMatch(in: version, range: NSRange(version.startIndex ..< version.endIndex, in: version))
.flatMap { Range($0.range(at: 1), in: version).map { String(version[$0]) } }
}
}
public struct SSHConfigResponse: Codable, Equatable, Sendable {
public let hostname_prefix: String?
public let hostname_suffix: String?
public let ssh_config_options: [String: String]
}