use serde::{Deserialize, Serialize};
use crate::config::secrets::decrypt_key;
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct RemoteSection {
pub enabled: Option<bool>,
pub session_timeout: Option<u64>,
pub default_streaming: Option<String>,
pub default_workspace: Option<String>,
pub workspace: Option<String>,
pub approval_mode: Option<String>,
#[serde(default)]
pub permissions: RemotePermissionsSection,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct RemotePermissionsSection {
#[serde(default)]
pub always_allow: Vec<String>,
#[serde(default)]
pub always_deny: Vec<String>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct TelegramSection {
pub token: Option<String>,
pub token_enc: Option<String>,
#[serde(default)]
pub allowed_users: Vec<i64>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SlackSection {
pub bot_token: Option<String>,
pub app_token: Option<String>,
pub bot_token_enc: Option<String>,
pub app_token_enc: Option<String>,
#[serde(default)]
pub allowed_users: Vec<String>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct DiscordSection {
pub token: Option<String>,
pub token_enc: Option<String>,
#[serde(default)]
pub allowed_users: Vec<u64>,
#[serde(default)]
pub guild_ids: Vec<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChannelMappingEntry {
pub platform: String,
pub channel: String,
#[serde(default)]
pub project: Option<String>,
#[serde(default)]
pub name: String,
#[serde(default)]
pub agent: Option<String>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct WebSection {
pub host: Option<String>,
pub port: Option<u16>,
pub username: Option<String>,
pub password_enc: Option<String>,
pub cors_origins: Option<String>,
}
#[derive(Debug, Clone)]
pub struct WebConfig {
pub host: String,
pub port: u16,
pub username: String,
pub password: Option<String>,
pub cors_origins: Vec<String>,
}
impl WebConfig {
pub fn from_section(section: &WebSection) -> Self {
let host = std::env::var("COLLET_WEB_HOST")
.ok()
.or_else(|| section.host.clone())
.unwrap_or_else(|| "127.0.0.1".to_string());
let port = std::env::var("COLLET_WEB_PORT")
.ok()
.and_then(|v| v.parse().ok())
.or(section.port)
.unwrap_or(3080);
let username = std::env::var("COLLET_WEB_USERNAME")
.ok()
.or_else(|| section.username.clone())
.unwrap_or_else(|| "collet".to_string());
let password = std::env::var("COLLET_WEB_PASSWORD").ok().or_else(|| {
section
.password_enc
.as_deref()
.and_then(|enc| decrypt_key(enc).ok())
});
let cors_origins = std::env::var("COLLET_WEB_CORS")
.ok()
.or_else(|| section.cors_origins.clone())
.map(|s| s.split(',').map(|o| o.trim().to_string()).collect())
.unwrap_or_default();
Self {
host,
port,
username,
password,
cors_origins,
}
}
}