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() || std::env::var(ai_code::CLIENT_KEY).is_ok()
28}
29
30pub fn get_mtls_config() -> Option<MTLSConfig> {
32 let mut config = MTLSConfig::default();
33
34 if let Ok(cert_path) = std::env::var(ai_code::CLIENT_CERT) {
35 if let Ok(cert) = std::fs::read_to_string(&cert_path) {
36 config.cert = Some(cert);
37 }
38 }
39
40 if let Ok(key_path) = std::env::var(ai_code::CLIENT_KEY) {
41 if let Ok(key) = std::fs::read_to_string(&key_path) {
42 config.key = Some(key);
43 }
44 }
45
46 if let Ok(passphrase) = std::env::var(ai_code::CLIENT_KEY_PASSPHRASE) {
47 config.passphrase = Some(passphrase);
48 }
49
50 if config.cert.is_none() && config.key.is_none() && config.passphrase.is_none() {
51 None
52 } else {
53 Some(config)
54 }
55}
56
57pub fn get_ca_cert() -> Option<String> {
59 None
61}
62
63pub fn get_client_cert() -> Option<String> {
65 get_mtls_config().and_then(|c| c.cert)
66}
67
68pub fn get_client_key() -> Option<String> {
70 get_mtls_config().and_then(|c| c.key)
71}
72
73pub fn configure_mtls() {
75 }
78
79pub fn clear_mtls_cache() {
81 }