Skip to main content

dvm_api/
cli_login.rs

1use serde::{Deserialize, Serialize};
2
3use crate::Timestamp;
4
5/// A login to start from a terminal: `POST /api/cli-logins`, with no session
6/// or key.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8pub struct NewCliLogin {
9    /// The terminal's machine, its hostname: the panel shows it, and the key
10    /// is named after it.
11    pub machine: String,
12}
13
14/// A login started: the panel's page that approves it, the code that page
15/// shows, and the token the terminal collects its key with, which only the
16/// terminal holds.
17#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
18pub struct StartedCliLogin {
19    pub approve_url: String,
20    /// `BCDF-GHJK`, which the terminal shows too, so the user sees the page
21    /// is their terminal's.
22    pub code: String,
23    pub collect_token: String,
24    pub expires_at: Timestamp,
25}
26
27/// A login from a terminal, as its page shows it to the user who may
28/// approve it.
29#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
30#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
31#[cfg_attr(feature = "typescript", ts(export_to = "controller-api.ts"))]
32pub struct CliLogin {
33    pub machine: String,
34    pub code: String,
35    pub created_at: Timestamp,
36    pub expires_at: Timestamp,
37    /// Approved by this user: its terminal has its key, or will on its next
38    /// ask.
39    pub approved: bool,
40}
41
42/// What a terminal asks for its key with: `POST /api/cli-logins/key`.
43#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
44pub struct CollectCliLogin {
45    pub collect_token: String,
46}