feat: rename orbits; snapshots and downloads show the orbit's current name

PUT /api/v1/orbits/:id changes only the name (admin, validated, case-insensitively unique, audited).
Snapshot metadata is immutable, so the list and the download file name look the orbit up by id and
fall back to the written name only when the orbit is gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 15:01:49 +07:00
parent c6dd52c700
commit f52fc1930f
7 changed files with 240 additions and 4 deletions

View File

@@ -373,6 +373,7 @@ pub fn router(state: HubState) -> Router {
.route("/health", get(health))
.route("/api/v1/snapshots", get(list_snapshots))
.route("/api/v1/orbits", get(list_orbits).post(create_orbit))
.route("/api/v1/orbits/:id", put(rename_orbit))
.route("/api/v1/orbits/:id/retention", put(update_orbit_retention))
.route("/api/v1/orbits/:id/run", post(trigger_orbit))
.route("/api/v1/orbits/:id/outpost", put(bind_outpost))
@@ -430,6 +431,10 @@ async fn list_snapshots(
let snaps = vault
.list_snapshots()
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let names = state
.db
.orbit_names()
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let out = snaps
.into_iter()
.filter(|s| s.manifest.provider != "legacy-history")
@@ -439,7 +444,11 @@ async fn list_snapshots(
orbit_id: s.manifest.orbit_id,
taken_at: s.taken_at,
capture: CaptureSnapshotSummary::from_manifest(&s.manifest),
orbit_name: s.manifest.orbit_name,
// the orbit's current name; the manifest keeps the one it was written under
orbit_name: names
.get(&s.manifest.orbit_id)
.cloned()
.unwrap_or(s.manifest.orbit_name),
size_bytes: s.size_bytes,
stored_bytes: s.stored_bytes,
new_data_chunks: s.new_data_chunks,
@@ -609,6 +618,42 @@ fn retention_settings(
))
}
#[derive(serde::Deserialize)]
#[serde(deny_unknown_fields)]
struct OrbitRename {
name: String,
}
/// Change an orbit's name and nothing else. Its snapshots are shown under the new name from now on.
async fn rename_orbit(
ConnectInfo(peer): ConnectInfo<SocketAddr>,
State(state): State<HubState>,
headers: HeaderMap,
Path(id): Path<Uuid>,
Json(req): Json<OrbitRename>,
) -> Result<StatusCode, StatusCode> {
let actor = admin_write(&state, peer, &headers)?;
let name = req.name.trim();
if name.is_empty() || name.len() > 128 || name.chars().any(char::is_control) {
return Err(StatusCode::BAD_REQUEST);
}
match state
.db
.rename_orbit(id, name)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
{
None => return Err(StatusCode::NOT_FOUND),
Some(false) => return Err(StatusCode::CONFLICT),
Some(true) => {}
}
state
.db
.audit("orbit.renamed", &format!("actor={actor} orbit={id}"))
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(StatusCode::NO_CONTENT)
}
#[utoipa::path(put, path = "/api/v1/orbits/{id}/retention", params(("id" = Uuid, Path, description = "orbit id")), request_body = RetentionUpdate, responses((status = 204), (status = 400), (status = 404)))]
async fn update_orbit_retention(
ConnectInfo(peer): ConnectInfo<SocketAddr>,