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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 | // Generated by scripts/gen-api.py from spec/openapi.json — do not edit.
import Foundation
// MARK: - Types
/// Shared by 3 operations.
public struct EmailBody: Codable, Sendable, Hashable {
public var email: String
public var totpCode: String?
public init(email: String, totpCode: String? = nil) {
self.email = email
self.totpCode = totpCode
}
enum CodingKeys: String, CodingKey {
case email
case totpCode = "totp_code"
}
}
/// Values this build does not know decode as `.unrecognized`.
public enum TransferResourceType: RawRepresentable, Codable, Sendable, Hashable {
case instance
case volume
case image
/// A value the server sent that this version of the package does not list.
case unrecognized(String)
/// Every value the spec listed when this file was generated.
public static let known: [TransferResourceType] = [.instance, .volume, .image]
public init(rawValue: String) {
switch rawValue {
case "instance": self = .instance
case "volume": self = .volume
case "image": self = .image
default: self = .unrecognized(rawValue)
}
}
public var rawValue: String {
switch self {
case .instance: return "instance"
case .volume: return "volume"
case .image: return "image"
case .unrecognized(let raw): return raw
}
}
public init(from decoder: any Decoder) throws {
self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// Values this build does not know decode as `.unrecognized`.
public enum TransferState: RawRepresentable, Codable, Sendable, Hashable {
case pending
case accepted
case declined
case cancelled
/// A value the server sent that this version of the package does not list.
case unrecognized(String)
/// Every value the spec listed when this file was generated.
public static let known: [TransferState] = [.pending, .accepted, .declined, .cancelled]
public init(rawValue: String) {
switch rawValue {
case "pending": self = .pending
case "accepted": self = .accepted
case "declined": self = .declined
case "cancelled": self = .cancelled
default: self = .unrecognized(rawValue)
}
}
public var rawValue: String {
switch self {
case .pending: return "pending"
case .accepted: return "accepted"
case .declined: return "declined"
case .cancelled: return "cancelled"
case .unrecognized(let raw): return raw
}
}
public init(from decoder: any Decoder) throws {
self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// Shared by 9 operations.
public struct Transfer: Codable, Sendable, Hashable, Identifiable {
public var id: String
public var resourceType: TransferResourceType
public var resourceId: String
public var state: TransferState
public var invitedEmail: String
public var createdAt: String
public var resolvedAt: String?
public var resourceName: String?
public var resourceState: String?
public var fromEmail: String?
public init(id: String, resourceType: TransferResourceType, resourceId: String, state: TransferState, invitedEmail: String, createdAt: String, resolvedAt: String? = nil, resourceName: String? = nil, resourceState: String? = nil, fromEmail: String? = nil) {
self.id = id
self.resourceType = resourceType
self.resourceId = resourceId
self.state = state
self.invitedEmail = invitedEmail
self.createdAt = createdAt
self.resolvedAt = resolvedAt
self.resourceName = resourceName
self.resourceState = resourceState
self.fromEmail = fromEmail
}
enum CodingKeys: String, CodingKey {
case id
case resourceType = "resource_type"
case resourceId = "resource_id"
case state
case invitedEmail = "invited_email"
case createdAt = "created_at"
case resolvedAt = "resolved_at"
case resourceName = "resource_name"
case resourceState = "resource_state"
case fromEmail = "from_email"
}
/// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(resourceType, forKey: .resourceType)
try container.encode(resourceId, forKey: .resourceId)
try container.encode(state, forKey: .state)
try container.encode(invitedEmail, forKey: .invitedEmail)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(resolvedAt, forKey: .resolvedAt)
try container.encodeIfPresent(resourceName, forKey: .resourceName)
try container.encodeIfPresent(resourceState, forKey: .resourceState)
try container.encodeIfPresent(fromEmail, forKey: .fromEmail)
}
}
/// Shared by 8 operations.
public struct TransferResponse: Codable, Sendable, Hashable {
public var transfer: Transfer
public init(transfer: Transfer) {
self.transfer = transfer
}
enum CodingKeys: String, CodingKey {
case transfer
}
}
/// Used by GET /vps/transfers.
public struct TransferListResponse: Codable, Sendable, Hashable {
public var incoming: [Transfer]
public var outgoing: [Transfer]
public init(incoming: [Transfer], outgoing: [Transfer]) {
self.incoming = incoming
self.outgoing = outgoing
}
enum CodingKeys: String, CodingKey {
case incoming
case outgoing
}
}
// MARK: - Operations
extension IrdOperation {
public static let transfers_offerInstance = IrdOperation(method: .post, pathTemplate: "/vps/instances/{id}/transfer", module: "transfers", name: "offerInstance", security: .jwtOnly)
public static let transfers_withdrawInstanceOffer = IrdOperation(method: .delete, pathTemplate: "/vps/instances/{id}/transfer", module: "transfers", name: "withdrawInstanceOffer", security: .jwtOnly)
public static let transfers_offerVolume = IrdOperation(method: .post, pathTemplate: "/vps/volumes/{id}/transfer", module: "transfers", name: "offerVolume", security: .jwtOnly)
public static let transfers_withdrawVolumeOffer = IrdOperation(method: .delete, pathTemplate: "/vps/volumes/{id}/transfer", module: "transfers", name: "withdrawVolumeOffer", security: .jwtOnly)
public static let transfers_offerImage = IrdOperation(method: .post, pathTemplate: "/vps/images/{id}/transfer", module: "transfers", name: "offerImage", security: .jwtOnly)
public static let transfers_withdrawImageOffer = IrdOperation(method: .delete, pathTemplate: "/vps/images/{id}/transfer", module: "transfers", name: "withdrawImageOffer", security: .jwtOnly)
public static let transfers_list = IrdOperation(method: .get, pathTemplate: "/vps/transfers", module: "transfers", name: "list", security: .jwtOnly)
public static let transfers_accept = IrdOperation(method: .post, pathTemplate: "/vps/transfers/{id}/accept", module: "transfers", name: "accept", security: .jwtOnly)
public static let transfers_decline = IrdOperation(method: .post, pathTemplate: "/vps/transfers/{id}/decline", module: "transfers", name: "decline", security: .jwtOnly)
static let transfersOperations: [IrdOperation] = [.transfers_offerInstance, .transfers_withdrawInstanceOffer, .transfers_offerVolume, .transfers_withdrawVolumeOffer, .transfers_offerImage, .transfers_withdrawImageOffer, .transfers_list, .transfers_accept, .transfers_decline]
}
/// The `transfers` operations (9).
public struct TransfersAPI: Sendable {
let client: IrdClient
/// Offer this server to another account
/// Creates a pending handover offer for the server to `email` (an existing ird account); nothing moves until they accept.
/// `POST /vps/instances/{id}/transfer` — 201
/// Requires an account session (JWT); API keys answer 401.
public func offerInstance(id: String, body: EmailBody) async throws -> TransferResponse {
try await client.request(.transfers_offerInstance, params: ["id": id], body: body)
}
/// Withdraw the pending server transfer offer
/// `DELETE /vps/instances/{id}/transfer` — 200
/// Requires an account session (JWT); API keys answer 401.
public func withdrawInstanceOffer(id: String) async throws -> TransferResponse {
try await client.request(.transfers_withdrawInstanceOffer, params: ["id": id])
}
/// Offer this volume to another account
/// Creates a pending handover offer for the volume to `email` (an existing ird account); nothing moves until they accept.
/// `POST /vps/volumes/{id}/transfer` — 201
/// Requires an account session (JWT); API keys answer 401.
public func offerVolume(id: String, body: EmailBody) async throws -> TransferResponse {
try await client.request(.transfers_offerVolume, params: ["id": id], body: body)
}
/// Withdraw the pending volume transfer offer
/// `DELETE /vps/volumes/{id}/transfer` — 200
/// Requires an account session (JWT); API keys answer 401.
public func withdrawVolumeOffer(id: String) async throws -> TransferResponse {
try await client.request(.transfers_withdrawVolumeOffer, params: ["id": id])
}
/// Offer this image to another account
/// Creates a pending handover offer for the image to `email` (an existing ird account); nothing moves until they accept.
/// `POST /vps/images/{id}/transfer` — 201
/// Requires an account session (JWT); API keys answer 401.
public func offerImage(id: String, body: EmailBody) async throws -> TransferResponse {
try await client.request(.transfers_offerImage, params: ["id": id], body: body)
}
/// Withdraw the pending image transfer offer
/// `DELETE /vps/images/{id}/transfer` — 200
/// Requires an account session (JWT); API keys answer 401.
public func withdrawImageOffer(id: String) async throws -> TransferResponse {
try await client.request(.transfers_withdrawImageOffer, params: ["id": id])
}
/// Pending handover offers, both directions
/// Offers waiting on this account (`incoming`) and offers it made (`outgoing`), with the resource's name/state and the offering account's email joined. Session JWT only.
/// `GET /vps/transfers` — 200
/// Requires an account session (JWT); API keys answer 401.
public func list() async throws -> TransferListResponse {
try await client.request(.transfers_list)
}
/// Take over the offered resource
/// Moves the resource and its hourly subscriptions to this account in one transaction — an instance brings its attached volumes; from the next hourly bill on, this account pays.
/// `POST /vps/transfers/{id}/accept` — 200
/// Requires an account session (JWT); API keys answer 401.
public func accept(id: String, body: TotpCodeBody? = nil) async throws -> TransferResponse {
try await client.request(.transfers_accept, params: ["id": id], body: body)
}
/// Decline an incoming transfer offer
/// `POST /vps/transfers/{id}/decline` — 200
/// Requires an account session (JWT); API keys answer 401.
public func decline(id: String) async throws -> TransferResponse {
try await client.request(.transfers_decline, params: ["id": id])
}
}
extension IrdClient {
public var transfers: TransfersAPI { TransfersAPI(client: self) }
}
|