Skip to main content

ai_agent/utils/
session_ingress_auth.rs

1//! Session ingress authentication utilities.
2
3use crate::constants::env::ai;
4use serde::{Deserialize, Serialize};
5
6/// Ingress authentication configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct IngressAuthConfig {
9    pub enabled: bool,
10    pub token: Option<String>,
11    pub oauth_token: Option<String>,
12}
13
14/// Check if ingress authentication is required
15pub fn is_ingress_auth_required() -> bool {
16    std::env::var(ai::CODE_INGRESS_AUTH_REQUIRED)
17        .map(|v| v == "true")
18        .unwrap_or(false)
19}
20
21/// Get ingress authentication token
22pub fn get_ingress_token() -> Option<String> {
23    std::env::var(ai::CODE_INGRESS_TOKEN).ok()
24}
25
26/// Validate an ingress token
27pub fn validate_ingress_token(token: &str) -> bool {
28    // Compare with configured token
29    if let Some(configured) = get_ingress_token() {
30        return token == configured;
31    }
32
33    // If no token configured, accept any non-empty token
34    !token.is_empty()
35}