Skip to content

Commit

Permalink
feat: add /health route(s)
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 17, 2024
1 parent 9fc6cd6 commit 32dc6e1
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 58 deletions.
31 changes: 23 additions & 8 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,39 @@ set shell := ["bash", "-uc"]
export RUST_BACKTRACE := "1"
export RUST_LOG := ""

build:
cargo build --all-features
cargo build -r --all-features

b: build

check:
cargo check --no-default-features
cargo check --all-features

c: check

ci:
just loop . dev

dev:
just format
just lint
just test
dev: format lint test

format:
just format-cargo
just format-dprint
d: dev

format-dprint:
dprint fmt

format-cargo:
cargo fmt --all

inverse-deps *crate:
format: format-cargo format-dprint

fmt: format

rev:
cargo insta review

inverse-deps crate:
cargo tree -e features -i {{ crate }}

lint: check
Expand All @@ -56,6 +66,11 @@ loop dir action:
test: check lint
cargo test --all-targets --all-features --workspace

test-ignored: check lint
cargo test --all-targets --all-features --workspace -- --ignored

t: test test-ignored

test-restic $RESTIC_REPOSITORY="rest:http://restic:restic@127.0.0.1:8080/ci_repo" $RESTIC_PASSWORD="restic":
restic init
restic backup tests/fixtures/test_data/test_repo_source
Expand Down
160 changes: 156 additions & 4 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ eula = false
abscissa_tokio = "0.8.0"
anyhow = "1"
async-trait = "0.1"
axum = { version = "0.7", features = ["tracing", "multipart", "http2"] }
axum = { version = "0.7", features = ["tracing", "multipart", "http2", "macros"] }
axum-auth = "0.7"
axum-extra = { version = "0.9", features = ["typed-header", "query", "async-read-body", "typed-routing"] }
axum-extra = { version = "0.9", features = ["typed-header", "query", "async-read-body", "typed-routing", "erased-json"] }
axum-macros = "0.4"
axum-range = "0.4"
axum-server = { version = "0.7", features = ["tls-rustls"] }
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4", features = ["derive", "env", "wrap_help"] }
conflate = "0.3.1"
displaydoc = "0.2"
Expand Down
8 changes: 4 additions & 4 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
htpasswd::{CredentialMap, Htpasswd},
};

//Static storage of our credentials
// Static storage of our credentials
pub static AUTH: OnceLock<Auth> = OnceLock::new();

pub(crate) fn init_auth(auth: Auth) -> AppResult<()> {
Expand Down Expand Up @@ -67,13 +67,13 @@ impl Auth {
}

#[derive(Deserialize, Debug)]
pub struct AuthFromRequest {
pub struct BasicAuthFromRequest {
pub(crate) user: String,
pub(crate) _password: SecretString,
}

#[async_trait::async_trait]
impl<S: Send + Sync> FromRequestParts<S> for AuthFromRequest {
impl<S: Send + Sync> FromRequestParts<S> for BasicAuthFromRequest {
type Rejection = ApiErrorKind;

// FIXME: We also have a configuration flag do run without authentication
Expand Down Expand Up @@ -156,7 +156,7 @@ mod test {
format!("Got {} and {:?}", id, password)
}

async fn format_handler_from_auth_request(auth: AuthFromRequest) -> String {
async fn format_handler_from_auth_request(auth: BasicAuthFromRequest) -> String {
format!("User = {}", auth.user)
}

Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod test {
fn test_default_config_passes() -> Result<()> {
let config = RusticServerConfig::default();
assert_toml_snapshot!(config, {
".storage.data-dir" => "[directory]",
".storage.data_dir" => "[directory]",
});

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod file_config;
pub(crate) mod file_exchange;
pub(crate) mod file_length;
pub(crate) mod files_list;
pub(crate) mod health;
pub(crate) mod repository;

// Support modules
Expand Down
Loading

0 comments on commit 32dc6e1

Please sign in to comment.