/
mcmare
/
RustAPI
Обзор
Документация
Войти
/
mcmare
/
RustAPI
Код
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
engine/src/config/auth.rs
31 строка
1 KB
mcmare
Wire up server binary, sample config, and README
18 июл 2026, 16:41
18 июл 2026, 16:41
f181395
Код
Авторство
О чём код?
use anyhow::{Context, Result}; use serde::Deserialize; use std::path::Path; use super::connections::resolve_env_placeholders; #[derive(Debug, Deserialize)] struct RawAuthFile { #[serde(default)] tokens: Vec<String>, } /// Loads the static Bearer/API-key tokens from `auth.yaml`. Missing file means no tokens /// are configured — every declared endpoint will then reject all requests with 401, /// which is a safe (if inconvenient) default rather than silently allowing anonymous access. pub fn load_auth_tokens(path: &Path) -> Result<Vec<String>> { if !path.exists() { return Ok(Vec::new()); } let raw_text = std::fs::read_to_string(path) .with_context(|| format!("failed to read {}", path.display()))?; let raw: RawAuthFile = serde_yaml::from_str(&raw_text) .with_context(|| format!("failed to parse {}", path.display()))?; raw.tokens .iter() .map(|t| { resolve_env_placeholders(t).with_context(|| format!("{}: field 'tokens'", path.display())) }) .collect() }