feat: reset

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-11-23 22:38:25 +01:00
parent 0f5249f620
commit cfe21ad23c
35 changed files with 0 additions and 5254 deletions

View File

@@ -1 +0,0 @@
/target

View File

@@ -1,53 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.1.0 (2023-08-26)
<csr-id-1ae70ac5258ae9f8f5471923fefd3e8ab02f46c1/>
### Chore
- <csr-id-1ae70ac5258ae9f8f5471923fefd3e8ab02f46c1/> with changelog
### New Features
- <csr-id-8f8c5fd41aaa82a495dd0933060f0a3a095bbaf1/> with basic package
- <csr-id-821e14fb1256957a107220c6c775565f5abc58c4/> with publish
- <csr-id-e0545c726c44dccfb8ea179266c1da93389c07e4/> with monitoring
- <csr-id-569f5272e667deeef9f269db5eaf3dec57e2df1c/> with monitor
- <csr-id-10eae9b36cfe82b86fe0bf4d7c02f99d727b839d/> with extra churning repl thingy
- <csr-id-97978df287ee42f523f509ac686a13fa0400a026/> add initial churn
- <csr-id-f61d0bbf120607e59145a80b65985ab93c938522/> add simple health check
### Commit Statistics
<csr-read-only-do-not-edit/>
- 11 commits contributed to the release over the course of 2 calendar days.
- 8 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Release churn v0.1.0 (d5212f0)
- Release churn-domain v0.1.0, churn v0.1.0 (e4e05bc)
- With changelog (1ae70ac)
- Release churn-domain v0.1.0, churn v0.1.0 (34bc81e)
- With basic package (8f8c5fd)
- With publish (821e14f)
- With monitoring (e0545c7)
- With monitor (569f527)
- With extra churning repl thingy (10eae9b)
- Add initial churn (97978df)
- Add simple health check (f61d0bb)
</details>

View File

@@ -1,21 +0,0 @@
[package]
name = "churn"
authors.workspace = true
description.workspace = true
license-file.workspace = true
version= "0.1.0"
edition.workspace = true
publish.workspace = true
[dependencies]
churn-domain.workspace = true
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true
dotenv.workspace = true
axum.workspace = true
reqwest.workspace = true
uuid.workspace = true

View File

@@ -1,154 +0,0 @@
use churn_domain::{AgentEnrollReq, LeaseResp, ServerMonitorResp};
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(author, version, about, long_about = None, subcommand_required = true)]
struct Command {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Auth {
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_SERVER_TOKEN", long)]
server_token: String,
},
Bootstrap {
#[arg(env = "CHURN_AGENT", long)]
agent: String,
#[arg(env = "CHURN_AGENT_NAME", long)]
agent_name: String,
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_SERVER_TOKEN", long)]
server_token: String,
},
Health {
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_AGENT", long)]
agent: String,
},
Monitor {
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_SERVER_TOKEN", long)]
server_token: String,
},
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
let cli = Command::parse();
handle_command(cli).await?;
Ok(())
}
async fn handle_command(cmd: Command) -> anyhow::Result<()> {
if let Some(cmd) = cmd.command {
match cmd {
Commands::Bootstrap {
agent,
agent_name,
server,
server_token: _,
} => {
tracing::info!("enrolling agent: {} for server: {}", agent, server);
let client = reqwest::Client::new();
let req = client.post(format!("{server}/agent/lease")).build()?;
let lease_resp = client.execute(req).await?;
let lease = lease_resp.json::<LeaseResp>().await?;
let req = client
.post(format!("{agent}/enroll"))
.json(&AgentEnrollReq {
lease: lease.token,
server,
agent_name,
})
.build()?;
let lease_resp = client.execute(req).await?;
if !lease_resp.status().is_success() {
if let Ok(text) = lease_resp.text().await {
tracing::warn!(
"could not enroll because agent server encoutered error: {}",
text
);
anyhow::bail!("encountered error: {}", text);
}
anyhow::bail!("encountered error");
}
Ok(())
}
Commands::Health { server, agent } => {
tracing::info!("connecting to server: {}", server);
reqwest::get(format!("{server}/ping")).await?;
tracing::info!("connected to server successfully");
tracing::info!("connecting to agent: {}", agent);
reqwest::get(format!("{agent}/ping")).await?;
tracing::info!("connected to agent successfully");
Ok(())
}
Commands::Auth {
server: _,
server_token: _,
} => todo!(),
Commands::Monitor {
server,
server_token: _,
} => {
tracing::info!("monitoring server: {}", server);
let mut cursor: Option<uuid::Uuid> = None;
loop {
tracing::debug!("reading logs from server: {}", server);
let resp = reqwest::get(format!(
"{server}/logs{}",
match &cursor {
None => "".to_string(),
Some(cursor) => format!("?cursor={}", cursor),
}
))
.await?;
if !resp.status().is_success() {
if let Ok(text) = resp.text().await {
anyhow::bail!("encountered error: {}", text);
}
anyhow::bail!("encountered error");
}
match resp.json::<ServerMonitorResp>().await {
Ok(resp) => {
for line in resp.logs {
tracing::info!("event: {}", line);
}
cursor = resp.cursor;
}
Err(e) => {
tracing::warn!("failed to call server (error={})", e);
}
}
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
}
}
} else {
panic!("no command supplied")
}
}