1#![allow(non_upper_case_globals)]
7
8use serde::{Deserialize, Serialize};
9use std::{collections::BTreeMap, fmt, fmt::Display};
10use utoipa::ToSchema;
11use uuid::Uuid;
12
13mod auth;
14mod message;
15mod unix;
16
17pub use self::{auth::*, message::*, unix::*};
18
19#[derive(Serialize, Deserialize, Clone, Copy, Debug, ToSchema)]
21pub enum AccountType {
22 Person,
23 ServiceAccount,
24}
25
26impl Display for AccountType {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.write_str(match self {
29 AccountType::Person => "person",
30 AccountType::ServiceAccount => "service_account",
31 })
32 }
33}
34
35#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
44#[serde(rename_all = "lowercase")]
45pub enum UatPurposeStatus {
46 ReadOnly,
47 ReadWrite,
48 PrivilegeCapable,
49}
50
51#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
53#[serde(rename_all = "lowercase")]
54pub enum UatStatusState {
55 #[serde(with = "time::serde::timestamp")]
56 ExpiresAt(time::OffsetDateTime),
57 NeverExpires,
58 Revoked,
59}
60
61impl fmt::Display for UatStatusState {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 match self {
64 UatStatusState::ExpiresAt(odt) => write!(f, "expires at {odt}"),
65 UatStatusState::NeverExpires => write!(f, "never expires"),
66 UatStatusState::Revoked => write!(f, "revoked"),
67 }
68 }
69}
70
71#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
73#[serde(rename_all = "lowercase")]
74pub struct UatStatus {
75 pub account_id: Uuid,
76 pub session_id: Uuid,
77 pub state: UatStatusState,
78 #[serde(with = "time::serde::timestamp")]
79 pub issued_at: time::OffsetDateTime,
80 pub purpose: UatPurposeStatus,
81}
82
83impl fmt::Display for UatStatus {
84 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85 writeln!(f, "account_id: {}", self.account_id)?;
86 writeln!(f, "session_id: {}", self.session_id)?;
87 writeln!(f, "state: {}", self.state)?;
88 writeln!(f, "issued_at: {}", self.issued_at)?;
89 match &self.purpose {
90 UatPurposeStatus::ReadOnly => writeln!(f, "purpose: read only")?,
91 UatPurposeStatus::ReadWrite => writeln!(f, "purpose: read write")?,
92 UatPurposeStatus::PrivilegeCapable => writeln!(f, "purpose: privilege capable")?,
93 }
94 Ok(())
95 }
96}
97
98#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
100#[serde(rename_all = "lowercase")]
101pub struct ApiTokenGenerate {
102 pub label: String,
103 #[serde(with = "time::serde::timestamp::option")]
104 pub expiry: Option<time::OffsetDateTime>,
105 pub read_write: bool,
106 #[serde(default)]
107 pub compact: bool,
108}
109
110#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Default, ToSchema)]
114pub struct Entry {
115 pub attrs: BTreeMap<String, Vec<String>>,
116}
117
118impl fmt::Display for Entry {
119 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120 writeln!(f, "---")?;
121 self.attrs
122 .iter()
123 .try_for_each(|(k, vs)| vs.iter().try_for_each(|v| writeln!(f, "{k}: {v}")))
124 }
125}
126
127#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, ToSchema)]
129pub struct WhoamiResponse {
130 pub youare: Entry,
132}
133
134impl WhoamiResponse {
135 pub fn new(youare: Entry) -> Self {
136 WhoamiResponse { youare }
137 }
138}
139
140#[derive(Debug, Serialize, Deserialize, ToSchema)]
142pub struct SingleStringRequest {
143 pub value: String,
144}
145
146impl SingleStringRequest {
147 pub fn new(s: String) -> Self {
148 SingleStringRequest { value: s }
149 }
150}