1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct GresiqApp {
7 pub id: i64,
8 pub name: String,
9 pub project_id: i64,
10 pub tenant_id: i64,
11 pub table_prefix: String,
12 pub status: String,
13 #[serde(default)]
16 pub api_key: Option<String>,
17 #[serde(default)]
18 pub server_key_last4: Option<String>,
19 #[serde(default)]
20 pub server_key_rotated_at: Option<String>,
21 #[serde(default)]
22 pub ingest_key_last4: Option<String>,
23 #[serde(default)]
24 pub ingest_key_rotated_at: Option<String>,
25 #[serde(default)]
26 pub created_at: Option<String>,
27}
28
29#[derive(Clone, Deserialize)]
31pub struct GresiqAppCredentials {
32 #[serde(default)]
33 pub api_key: Option<String>,
34 #[serde(default)]
35 pub api_secret: Option<String>,
36}
37
38impl std::fmt::Debug for GresiqAppCredentials {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.debug_struct("GresiqAppCredentials")
41 .field("api_key", &self.api_key)
42 .field(
43 "api_secret",
44 &self.api_secret.as_ref().map(|_| "<redacted>"),
45 )
46 .finish()
47 }
48}
49
50#[derive(Clone)]
52pub struct RotatedKey {
53 pub key: String,
54 pub last4: String,
55}
56
57impl std::fmt::Debug for RotatedKey {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 f.debug_struct("RotatedKey")
60 .field("key", &"<redacted>")
61 .field("last4", &self.last4)
62 .finish()
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn debug_never_shows_a_secret() {
72 let credentials = GresiqAppCredentials {
73 api_key: Some("gq_key".into()),
74 api_secret: Some("SECRET".into()),
75 };
76 assert!(!format!("{credentials:?}").contains("SECRET"));
77 let rotated = RotatedKey {
78 key: "gqs_SECRET".into(),
79 last4: "CRET".into(),
80 };
81 assert!(!format!("{rotated:?}").contains("gqs_SECRET"));
82 }
83
84 #[test]
85 fn an_app_reads_from_the_api_shape() {
86 let app: GresiqApp = serde_json::from_str(
87 r#"{"id":7,"name":"splitfire-ai-gresiq","project_id":38,"tenant_id":2,
88 "table_prefix":"splitfire_ai_gresiq","status":"active","api_key":"gq_x",
89 "server_key_last4":null,"post_databases_count":0}"#,
90 )
91 .unwrap();
92 assert_eq!(app.project_id, 38);
93 assert_eq!(app.status, "active");
94 }
95}