feat: add configurable GFS retention per orbit
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
mod http;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use tessera_core::decay::RetentionPolicy;
|
||||
use tessera_store::Vault;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -33,6 +34,16 @@ enum Commands {
|
||||
schedule: Option<String>,
|
||||
#[arg(long)]
|
||||
dry_run: bool,
|
||||
#[command(flatten)]
|
||||
retention: RetentionArgs,
|
||||
},
|
||||
/// Change an orbit's retention for future captures.
|
||||
Retention {
|
||||
orbit_id: Uuid,
|
||||
#[arg(long)]
|
||||
preset: Option<String>,
|
||||
#[command(flatten)]
|
||||
counts: RetentionArgs,
|
||||
},
|
||||
Snap {
|
||||
#[arg(long)]
|
||||
@@ -64,6 +75,45 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
struct RetentionArgs {
|
||||
#[arg(long)]
|
||||
keep_daily: Option<u32>,
|
||||
#[arg(long)]
|
||||
keep_weekly: Option<u32>,
|
||||
#[arg(long)]
|
||||
keep_monthly: Option<u32>,
|
||||
#[arg(long)]
|
||||
keep_yearly: Option<u32>,
|
||||
}
|
||||
|
||||
impl RetentionArgs {
|
||||
fn policy(self) -> Result<Option<RetentionPolicy>> {
|
||||
if [
|
||||
self.keep_daily,
|
||||
self.keep_weekly,
|
||||
self.keep_monthly,
|
||||
self.keep_yearly,
|
||||
]
|
||||
.iter()
|
||||
.all(Option::is_none)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let policy = RetentionPolicy {
|
||||
keep_daily: self.keep_daily.unwrap_or(0),
|
||||
keep_weekly: self.keep_weekly.unwrap_or(0),
|
||||
keep_monthly: self.keep_monthly.unwrap_or(0),
|
||||
keep_yearly: self.keep_yearly.unwrap_or(0),
|
||||
};
|
||||
anyhow::ensure!(
|
||||
policy.has_tiers(),
|
||||
"set at least one retention count above zero"
|
||||
);
|
||||
Ok(Some(policy))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Clone)]
|
||||
enum WormholeCmd {
|
||||
Pair {
|
||||
@@ -85,7 +135,32 @@ fn main() -> Result<()> {
|
||||
path,
|
||||
schedule,
|
||||
dry_run,
|
||||
} => cmd_orbit(&cli, name, provider, path, schedule, dry_run)?,
|
||||
retention,
|
||||
} => cmd_orbit(
|
||||
&cli,
|
||||
name,
|
||||
provider,
|
||||
path,
|
||||
schedule,
|
||||
dry_run,
|
||||
retention.policy()?,
|
||||
)?,
|
||||
Commands::Retention {
|
||||
orbit_id,
|
||||
preset,
|
||||
counts,
|
||||
} => {
|
||||
let retention = counts.policy()?;
|
||||
anyhow::ensure!(
|
||||
preset.is_some() != retention.is_some(),
|
||||
"choose --preset or custom --keep-* counts"
|
||||
);
|
||||
http::put_json(
|
||||
&format!("{}/api/v1/orbits/{orbit_id}/retention", cli.hub_url),
|
||||
&serde_json::json!({ "decay_preset": preset, "retention": retention }),
|
||||
)?;
|
||||
println!("Retention saved for {orbit_id}.");
|
||||
}
|
||||
Commands::Snap { orbit } => cmd_snap(&cli, orbit)?,
|
||||
Commands::List => cmd_list(&cli)?,
|
||||
Commands::Reconstitute {
|
||||
@@ -174,6 +249,7 @@ fn cmd_orbit(
|
||||
path: Option<String>,
|
||||
schedule: Option<String>,
|
||||
dry_run: bool,
|
||||
retention: Option<RetentionPolicy>,
|
||||
) -> Result<()> {
|
||||
let config = match provider.as_str() {
|
||||
"filesystem" => serde_json::json!({ "paths": [path.unwrap_or_else(|| ".".into())] }),
|
||||
@@ -193,6 +269,7 @@ fn cmd_orbit(
|
||||
"provider_config": config,
|
||||
"schedule": schedule,
|
||||
"dry_run": dry_run,
|
||||
"retention": retention,
|
||||
});
|
||||
let raw = http::post_json(&format!("{}/api/v1/orbits", cli.hub_url), &body)?;
|
||||
let orbit: serde_json::Value = serde_json::from_str(&raw)?;
|
||||
|
||||
Reference in New Issue
Block a user