56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
mod bind;
|
|
mod cache;
|
|
mod config;
|
|
mod exec;
|
|
mod mcp;
|
|
mod remote;
|
|
mod server;
|
|
mod target;
|
|
mod unlock;
|
|
|
|
use anyhow::{Context, Result};
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let _ = dotenvy::dotenv();
|
|
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "secrets_mcp_local=info,tower_http=info".into()),
|
|
)
|
|
.init();
|
|
|
|
let config = config::load_config()?;
|
|
let remote = std::sync::Arc::new(remote::RemoteClient::new(config.remote_base_url.clone())?);
|
|
let cache = cache::new_cache();
|
|
let cleanup = cache::spawn_cleanup_task(cache.clone());
|
|
|
|
let app_state = server::AppState {
|
|
config: config.clone(),
|
|
cache,
|
|
remote,
|
|
};
|
|
let app = server::router(app_state);
|
|
|
|
tracing::info!(
|
|
bind = %config.bind,
|
|
remote = %config.remote_base_url,
|
|
"secrets-mcp-local service started"
|
|
);
|
|
|
|
let listener = tokio::net::TcpListener::bind(config.bind)
|
|
.await
|
|
.with_context(|| format!("failed to bind {}", config.bind))?;
|
|
|
|
let result = axum::serve(
|
|
listener,
|
|
app.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
|
)
|
|
.await
|
|
.context("server error");
|
|
cleanup.abort();
|
|
result
|
|
}
|