1use crate::constants::env::ai_code;
5use once_cell::sync::Lazy;
6use std::sync::Mutex;
7
8#[derive(Debug, Clone, Default)]
10pub struct MTLSConfig {
11 pub cert: Option<String>,
12 pub key: Option<String>,
13 pub passphrase: Option<String>,
14}
15
16#[derive(Debug, Clone, Default)]
18pub struct TLSConfig {
19 pub cert: Option<String>,
20 pub key: Option<String>,
21 pub passphrase: Option<String>,
22 pub ca: Option<Vec<String>>,
23}
24
25pub fn is_mtls_enabled() -> bool {
27 std::env::var(ai_code::CLIENT_CERT).is_ok()
28 || std::env::var(ai_code::CLIENT_KEY).is_ok()
29}
30
31pub fn get_mtls_config() -> Option<MTLSConfig> {
33 let mut config = MTLSConfig::default();
34
35 if let Ok(cert_path) = std::env::var(ai_code::CLIENT_CERT) {
36 if let Ok(cert) = std::fs::read_to_string(&cert_path) {
37 config.cert = Some(cert);
38 }
39 }
40
41 if let Ok(key_path) = std::env::var(ai_code::CLIENT_KEY) {
42 if let Ok(key) = std::fs::read_to_string(&key_path) {
43 config.key = Some(key);
44 }
45 }
46
47 if let Ok(passphrase) = std::env::var(ai_code::CLIENT_KEY_PASSPHRASE) {
48 config.passphrase = Some(passphrase);
49 }
50
51 if config.cert.is_none() && config.key.is_none() && config.passphrase.is_none() {
52 None
53 } else {
54 Some(config)
55 }
56}
57
58pub fn get_ca_cert() -> Option<String> {
60 None
62}
63
64pub fn get_client_cert() -> Option<String> {
66 get_mtls_config().and_then(|c| c.cert)
67}
68
69pub fn get_client_key() -> Option<String> {
71 get_mtls_config().and_then(|c| c.key)
72}
73
74pub fn configure_mtls() {
76 }
79
80pub fn clear_mtls_cache() {
82 }