core_api/host/
management.rs1use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct HostRuntimeRequest<C> {
7 pub host_id: String,
8 #[serde(flatten)]
9 pub action: HostRuntimeAction<C>,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(tag = "action", rename_all = "camelCase")]
14pub enum HostRuntimeAction<C> {
15 AdministratorRequest {
16 proof: String,
17 },
18 AdministratorRequestStatus {
19 proof: String,
20 },
21 AdministratorRequestCancel {
22 proof: String,
23 },
24 Administrators,
25 AdministratorDecide {
26 #[serde(rename = "requestId")]
27 request_id: String,
28 approve: bool,
29 },
30 AdministratorRemove {
31 #[serde(rename = "userId")]
32 user_id: String,
33 },
34 ConfigureService {
35 #[serde(rename = "serviceId")]
36 service_id: String,
37 enabled: bool,
38 },
39 Inspect,
40 Metrics,
41 RestartOperation {
42 component: C,
43 #[serde(rename = "operationId")]
44 operation_id: String,
45 },
46 Plan {
47 components: Vec<C>,
48 #[serde(default)]
49 all: bool,
50 },
51 Start {
52 #[serde(rename = "planId")]
53 plan_id: String,
54 },
55 Operation {
56 #[serde(rename = "operationId")]
57 operation_id: String,
58 },
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(rename_all = "camelCase")]
63pub struct HostRuntimeResponse {
64 pub host_id: String,
65 pub data: serde_json::Value,
66}
67
68impl<C> HostRuntimeAction<C> {
69 pub fn applicant_proof(&self) -> Option<&str> {
71 match self {
72 Self::AdministratorRequest { proof }
73 | Self::AdministratorRequestStatus { proof }
74 | Self::AdministratorRequestCancel { proof } => Some(proof),
75 _ => None,
76 }
77 }
78 pub fn path(&self) -> &'static str {
79 if self.applicant_proof().is_some() {
80 "/v1/auth/administrators"
81 } else if matches!(self, Self::Metrics) {
82 "/metrics"
83 } else {
84 "/v1/runtime"
85 }
86 }
87}