feat: with agent db

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-27 19:42:33 +02:00
parent 75d99c2461
commit 43ed89d0d8
10 changed files with 286 additions and 68 deletions

View File

@@ -15,11 +15,11 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::routing::{get, post};
use axum::{Json, Router};
use churn_domain::{LeaseResp, LogEvent, ServerEnrollReq, ServerMonitorResp};
use churn_domain::{Agent, LeaseResp, LogEvent, ServerEnrollReq, ServerMonitorResp};
use clap::{Args, Parser, Subcommand, ValueEnum};
use event::EventService;
use lease::LeaseService;
use serde::{Deserialize, Serialize};
use serde::{Deserialize};
use serde_json::json;
use crate::db::Db;
@@ -56,11 +56,6 @@ enum Commands {
},
}
#[derive(Clone, Debug, Deserialize, Serialize)]
struct Agent {
pub name: String,
}
#[derive(Clone)]
struct AppState {
agent: AgentService,
@@ -94,9 +89,9 @@ async fn main() -> anyhow::Result<()> {
.route("/lease", post(agent_lease)),
)
.with_state(AppState {
agent: AgentService::default(),
agent: AgentService::new(db.clone()),
leases: LeaseService::default(),
events: EventService::new(db),
events: EventService::new(db.clone()),
});
tracing::info!("churn server listening on {}", host);
@@ -221,7 +216,7 @@ async fn logs(
if events.is_empty() {
return Ok(Json(ServerMonitorResp {
cursor: cursor.cursor.clone(),
cursor: cursor.cursor,
logs: Vec::new(),
}));
}