1use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Clone, Serialize, Deserialize)]
7#[serde(deny_unknown_fields)]
8pub struct RemoteRegistration {
9 pub account: Uuid,
10 pub project: Uuid,
11 pub deployment: String,
12 pub channel: String,
13 pub endpoint: String,
14 pub name: String,
15 pub addresses: RemoteAddresses,
16 pub accepting_connections: bool,
17 pub window: Option<RemoteWindowInit>,
18}
19
20#[derive(Clone, Default, Serialize, Deserialize)]
22#[serde(deny_unknown_fields)]
23pub struct RemoteAddresses {
24 pub relays: Vec<String>,
25 pub direct: Vec<String>,
26}
27
28#[derive(Clone, Serialize, Deserialize)]
29#[serde(deny_unknown_fields)]
30pub struct RemoteWindowInit {
31 pub id: Uuid,
32 pub remaining_seconds: u32,
33}
34
35impl RemoteRegistration {
36 pub fn proof_message(&self) -> Result<Vec<u8>, serde_json::Error> {
39 let mut bytes = b"maple.remote.registration.v1\0".to_vec();
40 bytes.extend(serde_json::to_vec(self)?);
41 Ok(bytes)
42 }
43}
44
45#[derive(Clone, Serialize, Deserialize)]
46#[serde(deny_unknown_fields)]
47pub struct RegisterRemoteDevice {
48 pub registration: RemoteRegistration,
49 pub signature: String,
50}
51
52#[derive(Clone, Serialize, Deserialize)]
53#[serde(deny_unknown_fields)]
54pub struct RemoteDevice {
55 pub channel: String,
56 pub endpoint: String,
57 pub name: String,
58 pub addresses: RemoteAddresses,
59 pub accepting_connections: bool,
60 pub window: Option<RemoteWindow>,
61 pub expires_at: i64,
62}
63
64#[derive(Clone, Serialize, Deserialize)]
65#[serde(deny_unknown_fields)]
66pub struct RemoteWindow {
67 pub id: Uuid,
68 pub expires_at: i64,
69}
70
71#[derive(Clone, Serialize, Deserialize)]
72#[serde(deny_unknown_fields)]
73pub struct RemoteAdmissionRequest {
74 pub controller: String,
75 pub execution: String,
76 pub window: Uuid,
77}
78
79#[derive(Serialize, Deserialize)]
81#[serde(deny_unknown_fields)]
82pub struct RemoteAdmission {
83 pub handle: String,
84 pub expires_at: i64,
85}
86
87#[derive(Clone, Serialize, Deserialize)]
88#[serde(deny_unknown_fields)]
89pub struct CheckRemoteAdmission {
90 pub handle: String,
91 pub controller: String,
92 pub execution: String,
93 pub window: Uuid,
94}
95
96#[derive(Serialize, Deserialize)]
97#[serde(deny_unknown_fields)]
98pub struct RemoteAdmissionCheck {
99 pub valid: bool,
100}
101
102#[derive(Serialize, Deserialize)]
103#[serde(deny_unknown_fields)]
104pub struct RemoteDeviceList {
105 pub devices: Vec<RemoteDevice>,
106}
107
108#[cfg(test)]
109mod tests {
110 use super::*;
111 #[test]
112 fn proof_schema_matches_shared_version_one_fixture() {
113 let fixture = include_str!("remote_registration_v1.json").trim_end();
114 let registration: RemoteRegistration = serde_json::from_str(fixture).unwrap();
115 let mut expected = b"maple.remote.registration.v1\0".to_vec();
116 expected.extend_from_slice(fixture.as_bytes());
117 assert_eq!(registration.proof_message().unwrap(), expected);
118 }
119}