lexe_api_core/revocable_clients/
models.rs1use lexe_common::{
4 api::{
5 auth::{BearerAuthToken, LexeScope},
6 user::UserPk,
7 },
8 time::TimestampMs,
9};
10use lexe_crypto::ed25519;
11use lexe_serde::{
12 base64_or_bytes,
13 optopt::{self, none},
14};
15#[cfg(any(test, feature = "test-utils"))]
16use proptest_derive::Arbitrary;
17use serde::{Deserialize, Serialize};
18
19use super::RevocableClient;
20
21#[derive(Clone, Debug, Serialize, Deserialize)]
23#[cfg_attr(any(test, feature = "test-utils"), derive(Eq, PartialEq, Arbitrary))]
24pub struct ListRevocableClients {
25 pub valid_only: bool,
27}
28
29#[derive(Clone, Debug, Serialize, Deserialize)]
31pub struct CreateRevocableClientRequest {
32 pub expires_at: Option<TimestampMs>,
35 pub label: Option<String>,
37 pub scope: LexeScope,
39}
40
41#[derive(Clone, Debug, Serialize, Deserialize)]
43pub struct CreateRevocableClientResponse {
44 #[serde(skip_serializing_if = "Option::is_none")]
47 pub user_pk: Option<UserPk>,
48
49 pub pubkey: ed25519::PublicKey,
51
52 pub created_at: TimestampMs,
54
55 #[serde(with = "base64_or_bytes")]
60 pub eph_ca_cert_der: Vec<u8>,
61
62 #[serde(with = "base64_or_bytes")]
65 pub rev_client_cert_der: Vec<u8>,
66
67 #[serde(with = "base64_or_bytes")]
69 pub rev_client_cert_key_der: Vec<u8>,
70
71 #[serde(skip_serializing_if = "Option::is_none")]
76 pub gateway_proxy_token: Option<BearerAuthToken>,
77}
78
79#[derive(Serialize, Deserialize)]
88#[cfg_attr(test, derive(Debug, Eq, PartialEq, Arbitrary))]
89pub struct UpdateClientRequest {
90 pub pubkey: ed25519::PublicKey,
92
93 #[serde(default, skip_serializing_if = "none", with = "optopt")]
95 pub expires_at: Option<Option<TimestampMs>>,
96
97 #[serde(default, skip_serializing_if = "none", with = "optopt")]
99 #[cfg_attr(test, proptest(strategy = "arb::any_label_update()"))]
100 pub label: Option<Option<String>>,
101
102 #[serde(skip_serializing_if = "none")]
104 pub scope: Option<LexeScope>,
105
106 #[serde(skip_serializing_if = "none")]
109 pub is_revoked: Option<bool>,
110}
111
112#[derive(Serialize, Deserialize)]
114pub struct UpdateClientResponse {
115 pub client: RevocableClient,
116}
117
118#[cfg(test)]
119mod arb {
120 use lexe_common::test_utils::arbitrary;
121 use proptest::{option, strategy::Strategy};
122
123 pub fn any_label_update() -> impl Strategy<Value = Option<Option<String>>> {
124 option::of(arbitrary::any_option_simple_string())
125 }
126}
127
128#[cfg(test)]
129mod test {
130 use lexe_common::test_utils::roundtrip;
131
132 use super::*;
133
134 #[test]
135 fn test_update_request_serde() {
136 roundtrip::json_string_roundtrip_proptest::<UpdateClientRequest>();
137 }
138
139 #[test]
140 fn test_list_revocable_clients_serde() {
141 roundtrip::query_string_roundtrip_proptest::<ListRevocableClients>();
142 }
143}