Skip to content

Commit

Permalink
restic init, backup, check, prune runs through
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 14, 2024
1 parent 6681a85 commit 87db902
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 129 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ tokio-util = { version = "0.7", features = ["io", "io-util"] }
toml = "0.8"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uuid = { version = "1.11.0", features = ["v4"] }
walkdir = "2"

[dependencies.abscissa_core]
Expand Down
29 changes: 25 additions & 4 deletions maskfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,11 @@ export RESTIC_REPOSITORY=rest:http://127.0.0.1:8000/ci_repo
export RESTIC_PASSWORD=restic
export RESTIC_REST_USERNAME=restic
export RESTIC_REST_PASSWORD=restic

restic init
restic backup src
restic backup tests/fixtures/test_data/test_repo_source
restic backup tests/fixtures/test_data/test_repo_source
restic check
restic forget --keep-last 1 --prune
```

PowerShell:
Expand All @@ -340,8 +342,11 @@ $env:RESTIC_REPOSITORY = "rest:http://127.0.0.1:8000/ci_repo";
$env:RESTIC_PASSWORD = "restic";
$env:RESTIC_REST_USERNAME = "restic";
$env:RESTIC_REST_PASSWORD = "restic";
# restic init
restic init
restic backup tests/fixtures/test_data/test_repo_source
restic backup tests/fixtures/test_data/test_repo_source
restic check
restic forget --keep-last 1 --prune
```

## test-server
Expand Down Expand Up @@ -385,5 +390,21 @@ PowerShell:
PowerShell:

```powershell
watchexec --stop-signal "CTRL+C" -r -w src -- "cargo run -- serve -c tests/fixtures/test_data/rustic_server.toml -v"
watchexec --stop-signal "CTRL+C" -r -w src -w tests -- "cargo run -- serve -c tests/fixtures/test_data/rustic_server.toml -v"
```

## hurl

> Run a hurl test against the server
Bash:

```bash
hurl -i tests/fixtures/hurl/endpoints.hurl
```

PowerShell:

```powershell
hurl -i tests/fixtures/hurl/endpoints.hurl
```
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<S: Send + Sync> FromRequestParts<S> for AuthFromRequest {

let auth_result = AuthBasic::from_request_parts(parts, state).await;

tracing::debug!(?auth_result, "[auth]");
tracing::debug!(?auth_result, "[AUTH]");

return match auth_result {
Ok(auth) => {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub(crate) async fn add_config<P: PathParts>(

/// delete_config
/// Interface: DELETE {repo}/config
#[allow(dead_code)]
pub(crate) async fn delete_config<P: PathParts>(
path: P,
auth: AuthFromRequest,
Expand Down
2 changes: 0 additions & 2 deletions src/handlers/file_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ pub(crate) async fn file_length<P: PathParts>(

#[cfg(test)]
mod test {
use std::path::PathBuf;

use axum::{
http::{header, Method, StatusCode},
middleware, Router,
Expand Down
2 changes: 0 additions & 2 deletions src/handlers/files_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ pub(crate) async fn list_files<P: PathParts>(

#[cfg(test)]
mod test {
use std::path::PathBuf;

use axum::{
body::Body,
http::{
Expand Down
1 change: 0 additions & 1 deletion src/handlers/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ mod test {
};
use axum::{middleware, Router};
use axum_extra::routing::RouterExt;
use std::env;
use std::path::PathBuf;
use tokio::fs;
use tower::ServiceExt;
Expand Down
32 changes: 14 additions & 18 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use axum::{
};
use axum_macros::debug_middleware;
use http_body_util::BodyExt;
use tracing::Instrument;

use crate::error::ApiErrorKind;

Expand All @@ -18,7 +17,7 @@ use crate::error::ApiErrorKind;
///
/// ```rust
/// use axum::Router;
///
///
/// app = Router::new()
/// .layer(middleware::from_fn(print_request_response))
/// ```
Expand All @@ -28,41 +27,38 @@ pub async fn print_request_response(
next: Next,
) -> Result<impl IntoResponse, ApiErrorKind> {
let (parts, body) = req.into_parts();
let uuid = uuid::Uuid::new_v4();

let span = tracing::span!(
tracing::Level::DEBUG,
"request",
tracing::debug!(
id = %uuid,
method = %parts.method,
uri = %parts.uri,
"[REQUEST]",
);

let _enter = span.enter();

tracing::debug!(headers = ?parts.headers, "[new request]");
tracing::debug!(id = %uuid, headers = ?parts.headers, "[HEADERS]");

let bytes = buffer_and_print(body).instrument(span.clone()).await?;
let bytes = buffer_and_print(&uuid, body).await?;

let req = Request::from_parts(parts, Body::from(bytes));

let res = next.run(req).instrument(span.clone()).await;
let res = next.run(req).await;
let (parts, body) = res.into_parts();

let span = tracing::span!(
tracing::Level::DEBUG,
"response",
tracing::debug!(
id = %uuid,
headers = ?parts.headers,
status = %parts.status,
"[RESPONSE]",
);

let _enter = span.enter();

let bytes = buffer_and_print(body).instrument(span.clone()).await?;
let bytes = buffer_and_print(&uuid, body).await?;
let res = Response::from_parts(parts, Body::from(bytes));

Ok(res)
}

async fn buffer_and_print<B>(body: B) -> Result<Bytes, ApiErrorKind>
async fn buffer_and_print<B>(uuid: &uuid::Uuid, body: B) -> Result<Bytes, ApiErrorKind>
where
B: axum::body::HttpBody<Data = Bytes>,
B::Error: std::fmt::Display,
Expand All @@ -77,7 +73,7 @@ where
};

if let Ok(body) = std::str::from_utf8(&bytes) {
tracing::debug!(body = %body);
tracing::debug!(id = %uuid, body = %body, "[BODY]");
}

Ok(bytes)
Expand Down
8 changes: 4 additions & 4 deletions src/typed_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ impl PathParts for RepositoryConfigPath {
}
}

// A type safe route with `"/:repo"` as its associated path.
// A type safe route with `"/:repo/"` as its associated path.
#[derive(TypedPath, Deserialize, Debug)]
#[typed_path("/:repo")]
#[typed_path("/:repo/")]
pub struct RepositoryPath {
pub repo: String,
}
Expand All @@ -93,9 +93,9 @@ impl PathParts for TpePath {
}
}

// A type safe route with `"/:repo/:tpe"` as its associated path.
// A type safe route with `"/:repo/:tpe/"` as its associated path.
#[derive(TypedPath, Deserialize, Debug)]
#[typed_path("/:repo/:tpe")]
#[typed_path("/:repo/:tpe/")]
pub struct RepositoryTpePath {
pub repo: String,
pub tpe: TpeKind,
Expand Down
Loading

0 comments on commit 87db902

Please sign in to comment.