asurada 0.3.1

Asurada — a memory + cognition daemon that grows with the user. Local-first, BYOK, shared by Devist/Webchemist Core/etc.
#![allow(dead_code)]

// 자격증명 / 사용자 식별 로드.
//
// MVP: 환경 변수에서 로드.
//   ASURADA_DATABASE_URL  - postgresql://user:pass@host:5432/db
//   ASURADA_USER_ID       - 현재 사용자 식별자 (예: alice)
//
// 향후: macOS Keychain 통합으로 secret 분리 저장.

use anyhow::{anyhow, Result};

#[derive(Debug, Clone)]
pub struct Credentials {
    pub database_url: String,
    pub user_id: String,
}

impl Credentials {
    /// 환경 변수에서 자격증명 로드. 누락된 게 있으면 None.
    pub fn from_env() -> Option<Self> {
        let database_url = std::env::var("ASURADA_DATABASE_URL").ok()?;
        let user_id = std::env::var("ASURADA_USER_ID").ok()?;
        if database_url.is_empty() || user_id.is_empty() {
            return None;
        }
        Some(Self {
            database_url,
            user_id,
        })
    }

    /// 환경 변수에서 자격증명 강제 로드 (없으면 명확한 에러).
    pub fn require_env() -> Result<Self> {
        Self::from_env().ok_or_else(|| {
            anyhow!(
                "ASURADA_DATABASE_URL 와 ASURADA_USER_ID 환경 변수가 필요합니다.\n\
                 예:\n\
                 \texport ASURADA_DATABASE_URL='postgresql://postgres:postgres@127.0.0.1:54322/postgres'\n\
                 \texport ASURADA_USER_ID='alice'"
            )
        })
    }
}