feat: add labels to config
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-12-01 14:38:10 +01:00
parent d6fdda0e4e
commit 2387a70778
4 changed files with 90 additions and 53 deletions

View File

@@ -1,3 +1,5 @@
use std::collections::BTreeMap;
use anyhow::Context;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
@@ -23,6 +25,8 @@ impl AgentConfig {
struct ConfigFile {
agent_id: String,
discovery: String,
labels: BTreeMap<String, String>,
}
impl ConfigFile {
@@ -43,10 +47,15 @@ impl ConfigFile {
toml::from_str(&contents).context("failed to parse the contents of the churn agent config")
}
pub async fn write_default(discovery: impl Into<String>, force: bool) -> anyhow::Result<Self> {
pub async fn write_default(
discovery: impl Into<String>,
force: bool,
labels: impl Into<BTreeMap<String, String>>,
) -> anyhow::Result<Self> {
let s = Self {
agent_id: Uuid::new_v4().to_string(),
discovery: discovery.into(),
labels: labels.into(),
};
let directory = dirs::data_dir()
@@ -73,8 +82,12 @@ impl ConfigFile {
}
}
pub async fn setup_config(discovery: impl Into<String>, force: bool) -> anyhow::Result<()> {
ConfigFile::write_default(discovery, force).await?;
pub async fn setup_config(
discovery: impl Into<String>,
force: bool,
labels: impl Into<BTreeMap<String, String>>,
) -> anyhow::Result<()> {
ConfigFile::write_default(discovery, force, labels).await?;
Ok(())
}