use lexe_common::{
api::{
auth::{BearerAuthToken, LexeScope},
user::UserPk,
},
time::TimestampMs,
};
use lexe_crypto::ed25519;
use lexe_serde::{
base64_or_bytes,
optopt::{self, none},
};
#[cfg(any(test, feature = "test-utils"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
use super::RevocableClient;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "test-utils"), derive(Eq, PartialEq, Arbitrary))]
pub struct ListRevocableClients {
pub valid_only: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CreateRevocableClientRequest {
pub expires_at: Option<TimestampMs>,
pub label: Option<String>,
pub scope: LexeScope,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CreateRevocableClientResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub user_pk: Option<UserPk>,
pub pubkey: ed25519::PublicKey,
pub created_at: TimestampMs,
#[serde(with = "base64_or_bytes")]
pub eph_ca_cert_der: Vec<u8>,
#[serde(with = "base64_or_bytes")]
pub rev_client_cert_der: Vec<u8>,
#[serde(with = "base64_or_bytes")]
pub rev_client_cert_key_der: Vec<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gateway_proxy_token: Option<BearerAuthToken>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(test, derive(Debug, Eq, PartialEq, Arbitrary))]
pub struct UpdateClientRequest {
pub pubkey: ed25519::PublicKey,
#[serde(default, skip_serializing_if = "none", with = "optopt")]
pub expires_at: Option<Option<TimestampMs>>,
#[serde(default, skip_serializing_if = "none", with = "optopt")]
#[cfg_attr(test, proptest(strategy = "arb::any_label_update()"))]
pub label: Option<Option<String>>,
#[serde(skip_serializing_if = "none")]
pub scope: Option<LexeScope>,
#[serde(skip_serializing_if = "none")]
pub is_revoked: Option<bool>,
}
#[derive(Serialize, Deserialize)]
pub struct UpdateClientResponse {
pub client: RevocableClient,
}
#[cfg(test)]
mod arb {
use lexe_common::test_utils::arbitrary;
use proptest::{option, strategy::Strategy};
pub fn any_label_update() -> impl Strategy<Value = Option<Option<String>>> {
option::of(arbitrary::any_option_simple_string())
}
}
#[cfg(test)]
mod test {
use lexe_common::test_utils::roundtrip;
use super::*;
#[test]
fn test_update_request_serde() {
roundtrip::json_string_roundtrip_proptest::<UpdateClientRequest>();
}
#[test]
fn test_list_revocable_clients_serde() {
roundtrip::query_string_roundtrip_proptest::<ListRevocableClients>();
}
}