feat: use Restic for encrypted incremental backups
Keep legacy restores readable while using Restic for new captures, scoped Wormhole repositories, and chunk garbage collection.
This commit is contained in:
@@ -9,7 +9,13 @@ use std::sync::Arc;
|
||||
|
||||
pub fn post_json(url: &str, body: &serde_json::Value, headers: &[(&str, &str)]) -> Result<String> {
|
||||
let payload = serde_json::to_string(body)?;
|
||||
request("POST", url, Some(&payload), Some("application/json"), headers)
|
||||
request(
|
||||
"POST",
|
||||
url,
|
||||
Some(&payload),
|
||||
Some("application/json"),
|
||||
headers,
|
||||
)
|
||||
}
|
||||
|
||||
fn request(
|
||||
@@ -42,8 +48,15 @@ fn request(
|
||||
stream.write_all(req.as_bytes())?;
|
||||
let mut buf = String::new();
|
||||
stream.read_to_string(&mut buf)?;
|
||||
let body_start = buf.find("\r\n\r\n").map(|i| i + 4).unwrap_or(0);
|
||||
Ok(buf[body_start..].trim().to_string())
|
||||
let (response_headers, body) = buf.split_once("\r\n\r\n").context("invalid hub response")?;
|
||||
let status = response_headers
|
||||
.lines()
|
||||
.next()
|
||||
.and_then(|line| line.split_whitespace().nth(1))
|
||||
.context("missing hub response status")?
|
||||
.parse::<u16>()?;
|
||||
anyhow::ensure!((200..300).contains(&status), "hub returned HTTP {status}");
|
||||
Ok(body.trim().to_string())
|
||||
}
|
||||
|
||||
trait ReadWrite: Read + Write {}
|
||||
|
||||
Reference in New Issue
Block a user