stackmachine 0.1.0

Async Rust SDK for StackMachine.
Documentation
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//! Typed API responses. Timestamps and URLs retain their API string representation.
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::BTreeMap;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Viewer {
    pub username: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Reference {
    pub id: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct App {
    pub id: String,
    pub name: String,
    pub url: String,
    pub admin_url: String,
    pub active_version: Option<Reference>,
    pub will_perish_at: Option<String>,
    pub favicon: Option<String>,
    pub screenshot: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AppVersion {
    pub id: String,
    pub app: App,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ExpectedDnsRecord {
    pub host: String,
    pub record_type: String,
    pub value: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AppDomain {
    pub id: String,
    pub hostname: String,
    pub url: String,
    pub state: String,
    pub redirection_http_code: Option<String>,
    pub redirects_from: Vec<Reference>,
    pub redirects_to: Option<Reference>,
    pub expected_dns_records: Vec<ExpectedDnsRecord>,
    pub first_checked_at: Option<String>,
    pub last_checked_at: Option<String>,
    pub updated_at: String,
    pub created_at: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AppVolume {
    pub id: String,
    pub volume_id: String,
    pub mount_path: String,
    #[serde(deserialize_with = "bigint")]
    pub max_size_bytes: i64,
    pub s3_enabled: bool,
    pub s3_url: Option<String>,
    pub explorer_url: Option<String>,
    pub is_added_by_ui: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AppDatabase {
    pub id: String,
    pub name: String,
    pub host: String,
    pub port: String,
    pub username: String,
    pub password: Option<String>,
    pub phpmyadmin_url: Option<String>,
    pub db_explorer_url: Option<String>,
    pub deleted_at: Option<String>,
    pub created_at: String,
    pub updated_at: String,
    pub app: App,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DatabaseCredentials {
    pub database: AppDatabase,
    pub password: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AppCache {
    pub id: String,
    #[serde(rename = "cdnCacheEnabled")]
    pub enabled: bool,
    #[serde(rename = "cdnCachePurgedAt")]
    pub purged_at: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "__typename")]
#[non_exhaustive]
pub enum CronJobTarget {
    #[serde(rename = "ExecuteCronJobTarget", rename_all = "camelCase")]
    Execute {
        command: Option<String>,
        cli_args: Value,
        env: Value,
        package_name: Option<String>,
    },
    #[serde(rename = "FetchCronJobTarget", rename_all = "camelCase")]
    Fetch {
        path: String,
        method: String,
        headers: Value,
        body: Option<String>,
        expect_body_includes: Option<String>,
        expect_body_regex: Option<String>,
        expect_status_codes: Value,
    },
    #[serde(other)]
    Unknown,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CronJob {
    pub id: String,
    pub name: String,
    pub schedule: String,
    pub enabled: bool,
    pub kind: String,
    pub source: String,
    pub is_managed: bool,
    pub max_retries: Option<i32>,
    pub max_schedule_drift: Option<String>,
    pub timeout: Option<String>,
    pub created_at: String,
    pub updated_at: String,
    pub target: CronJobTarget,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GitConnection {
    pub id: String,
    pub connected_at: String,
    pub deploy_branch: String,
    pub deployment_status_events: bool,
    pub pull_request_comments: bool,
    pub connected_by: UserSummary,
    pub app: App,
    pub github_repo_installation: GithubRepository,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UserSummary {
    pub id: String,
    pub username: String,
    pub global_name: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GithubRepository {
    pub id: String,
    pub name: String,
    pub namespace: String,
    pub repo_url: String,
    pub url: String,
    pub installation: GithubInstallation,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GithubInstallation {
    pub id: String,
    pub slug: String,
    pub github_configure_url: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Owner {
    #[serde(rename = "__typename")]
    pub kind: String,
    pub id: String,
    pub global_id: String,
    pub global_name: String,
    pub is_pro: bool,
    pub name: Option<String>,
    pub display_name: Option<String>,
    pub username: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DnsDomain {
    pub id: String,
    pub name: String,
    pub slug: String,
    pub zone_file: String,
    pub delegation_status: String,
    pub nameservers: Vec<String>,
    pub last_checked_at: Option<String>,
    pub verified_at: Option<String>,
    pub deleted_at: Option<String>,
    pub created_at: String,
    pub updated_at: String,
    pub owner: Owner,
    // Domain listing deliberately omits records; retrieve includes them.
    #[serde(default)]
    pub records: Option<Vec<Option<DnsRecord>>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DnsDomainSummary {
    pub id: String,
    pub name: String,
    pub slug: String,
}

/// Common DNS fields and the record-specific fields from GraphQL (e.g. `address`).
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DnsRecord {
    #[serde(rename = "__typename")]
    pub kind: String,
    pub id: String,
    pub name: String,
    pub text: String,
    pub ttl: Option<i32>,
    pub dns_class: Option<String>,
    pub domain: DnsDomainSummary,
    pub created_at: String,
    pub updated_at: String,
    pub deleted_at: Option<String>,
    #[serde(flatten)]
    pub fields: BTreeMap<String, Value>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EmailMessage {
    pub id: String,
    pub from: String,
    pub to: Vec<String>,
    pub cc: Vec<String>,
    pub bcc: Vec<String>,
    pub subject: String,
    pub text_body: Option<String>,
    pub html_body: Option<String>,
    pub reply_to: Option<String>,
    pub direction: String,
    pub status: String,
    pub created_at: String,
    pub received_at: Option<String>,
    pub sent_at: Option<String>,
    pub app: Option<Reference>,
    pub owner: Option<Owner>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Log {
    pub datetime: String,
    pub instance_id: String,
    pub message: String,
    pub stream: Option<String>,
    pub timestamp: f64,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SshServer {
    pub id: String,
    pub enabled: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SshUser {
    pub id: String,
    pub username: String,
    pub port: i32,
    pub server_host: String,
    pub sftp_root_folder: String,
    pub authentication_methods: Vec<Option<String>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SshPassword {
    pub password: Option<String>,
    pub ssh_user: SshUser,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SshAuthorizedKey {
    pub id: String,
    pub name: Option<String>,
    pub public_key: String,
    pub created_at: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PackageVersion {
    pub id: String,
    pub version: String,
    pub created_at: String,
    pub package: Package,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Package {
    pub id: String,
    pub package_name: String,
    pub namespace: String,
    pub private: bool,
    pub last_version: Option<PackageRelease>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PackageRelease {
    pub id: String,
    pub version: String,
    pub created_at: String,
    pub distribution: PackageDistribution,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PackageDistribution {
    pub pirita_sha256_hash: Option<String>,
    pub pirita_download_url: Option<String>,
    pub download_url: String,
    pub size: Option<f64>,
    pub pirita_size: Option<f64>,
    pub webc_version: Option<String>,
    pub webc_manifest: Option<Value>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UsageMetrics {
    pub start_at: String,
    pub end_at: String,
    pub grouped: Vec<GroupedUsageMetrics>,
    pub totals: MetricsTotals,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupedUsageMetrics {
    pub grouped_at: String,
    pub requests: RequestMetrics,
    pub workloads: WorkloadMetrics,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MetricsTotals {
    pub requests: RequestMetrics,
    pub workloads: WorkloadMetrics,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestMetrics {
    #[serde(deserialize_with = "bigint")]
    pub cached_requests: i64,
    #[serde(deserialize_with = "bigint")]
    pub data_cached_bytes: i64,
    #[serde(deserialize_with = "bigint")]
    pub data_served_bytes: i64,
    #[serde(deserialize_with = "bigint")]
    pub http2xx: i64,
    #[serde(deserialize_with = "bigint")]
    pub http3xx: i64,
    #[serde(deserialize_with = "bigint")]
    pub http4xx: i64,
    #[serde(deserialize_with = "bigint")]
    pub http5xx: i64,
    #[serde(deserialize_with = "bigint")]
    pub http_other: i64,
    pub percentage_cached: f64,
    #[serde(deserialize_with = "bigint")]
    pub request_duration_millis: i64,
    #[serde(deserialize_with = "bigint")]
    pub total_requests: i64,
    pub unique_users: i32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkloadMetrics {
    #[serde(deserialize_with = "bigint")]
    pub memory_bytes: i64,
    #[serde(deserialize_with = "bigint")]
    pub network_egress_bytes: i64,
    #[serde(deserialize_with = "bigint")]
    pub network_ingress_bytes: i64,
    #[serde(deserialize_with = "bigint")]
    pub real_cpu_time_millis: i64,
    #[serde(deserialize_with = "bigint")]
    pub wall_cpu_time_millis: i64,
    pub workloads: i32,
}

fn bigint<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<i64, D::Error> {
    #[derive(Deserialize)]
    #[serde(untagged)]
    enum BigInt {
        Number(i64),
        String(String),
    }
    match BigInt::deserialize(deserializer)? {
        BigInt::Number(number) => Ok(number),
        BigInt::String(number) => number.parse().map_err(serde::de::Error::custom),
    }
}