feat: readable download names and PUT /capture-profiles/:id
- downloads are named <orbit>_<time>_<engine>_<id8>.<ext> (schedule zone or UTC), orbit names are reduced to [a-z0-9_-], and the header carries filename and filename* - operators can change a profile's schedule and retention (absent = keep, null = clear), validated like registration, audited, and a changed schedule never replays slots that already passed Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,10 @@ pub(super) fn routes() -> Router<HubState> {
|
||||
"/api/v1/capture-profiles",
|
||||
get(profiles).post(register_profile),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/capture-profiles/:id",
|
||||
axum::routing::put(update_profile),
|
||||
)
|
||||
.route("/api/v1/capture-profiles/:id/jobs", post(enqueue))
|
||||
.route("/api/v1/capture-jobs", get(history))
|
||||
.route("/api/v1/capture-jobs/:id", get(job))
|
||||
@@ -86,6 +90,73 @@ async fn register_profile(
|
||||
Ok((StatusCode::CREATED, Json(profile)))
|
||||
}
|
||||
|
||||
/// Editable parts of a profile. A field that is absent stays as it is; `null` clears it. Anything else
|
||||
/// (format, orbit, Outpost) is part of the profile's identity and is refused.
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct ProfileUpdate {
|
||||
#[serde(default, deserialize_with = "present")]
|
||||
schedule: Option<Option<tessera_core::job::CaptureSchedule>>,
|
||||
#[serde(default, deserialize_with = "present")]
|
||||
retention: Option<Option<tessera_core::decay::CaptureRetention>>,
|
||||
}
|
||||
|
||||
/// Tell `null` from an absent field: `Some(None)` for null, `Some(Some(v))` for a value.
|
||||
fn present<'de, D, T>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
T: serde::Deserialize<'de>,
|
||||
{
|
||||
<Option<T> as serde::Deserialize>::deserialize(deserializer).map(Some)
|
||||
}
|
||||
|
||||
async fn update_profile(
|
||||
ConnectInfo(peer): ConnectInfo<SocketAddr>,
|
||||
State(state): State<HubState>,
|
||||
headers: HeaderMap,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(update): Json<ProfileUpdate>,
|
||||
) -> Result<Json<CaptureProfile>, StatusCode> {
|
||||
let actor = admin_write(&state, peer, &headers)?;
|
||||
if let Some(Some(retention)) = &update.retention {
|
||||
if !retention.is_valid() {
|
||||
return Err(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if let Some(Some(schedule)) = &update.schedule {
|
||||
crate::scheduler::capture_schedule(schedule).ok_or(StatusCode::BAD_REQUEST)?;
|
||||
}
|
||||
let mut fields = Vec::new();
|
||||
if update.schedule.is_some() {
|
||||
fields.push("schedule");
|
||||
}
|
||||
if update.retention.is_some() {
|
||||
fields.push("retention");
|
||||
}
|
||||
let _vault = state.vault.write().await;
|
||||
let profile = state
|
||||
.db
|
||||
.update_capture_profile(
|
||||
id,
|
||||
crate::db::ProfileChange {
|
||||
schedule: update.schedule,
|
||||
retention: update.retention,
|
||||
},
|
||||
now(),
|
||||
)
|
||||
.map_err(internal)?
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
state
|
||||
.db
|
||||
.audit(
|
||||
"capture.profile_updated",
|
||||
&format!("actor={actor} application={id} fields={}", fields.join(",")),
|
||||
)
|
||||
.await
|
||||
.map_err(internal)?;
|
||||
Ok(Json(profile))
|
||||
}
|
||||
|
||||
async fn enqueue(
|
||||
ConnectInfo(peer): ConnectInfo<SocketAddr>,
|
||||
State(state): State<HubState>,
|
||||
|
||||
Reference in New Issue
Block a user