From 4265f53cbba5923f09961eb202313bb15a7e6ade Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 2 Sep 2025 16:42:15 +0200 Subject: [PATCH 1/3] add basic CI --- .github/workflows/ci.yml | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d07e325c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: ci +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + rust: [1.84.0, stable, beta, nightly] + + # Test with no features, default features ("") and all features. + # Ordered fewest features to most features. + args: ["--no-default-features", "", "--all-features"] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + - run: cargo build --verbose ${{ matrix.args }} + + test: + name: test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + rust: [1.84.0, stable, beta, nightly] + + # Test with no features, default features ("") and all features. + # Ordered fewest features to most features. + args: ["--no-default-features", "", "--all-features"] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + - run: cargo test --verbose ${{ matrix.args }} + + clippy: + name: clippy + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + rust: [stable] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + - run: cargo clippy --all -- -D warnings + + fmt: + name: fmt + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + rust: [stable] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + - run: cargo fmt --check From 9c755f6fc2bacc252cfbda5c4a18addb1d803ba5 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 2 Sep 2025 16:53:24 +0200 Subject: [PATCH 2/3] refactor zone_server_unit_api_common with let-else --- src/units/http_server.rs | 110 +++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/src/units/http_server.rs b/src/units/http_server.rs index 70ebf3a9..ccaaac41 100644 --- a/src/units/http_server.rs +++ b/src/units/http_server.rs @@ -366,58 +366,64 @@ impl HttpServer { params: HashMap, ) -> Result<(), StatusCode> { let uri = uri.path_and_query().map(|p| p.as_str()).unwrap_or_default(); - let zone_name = params.get("zone"); - let zone_serial = params.get("serial"); - if matches!(action.as_ref(), "approve" | "reject") - && zone_name.is_some() - && zone_serial.is_some() - && token.len() > 0 - { - let zone_name = zone_name.unwrap(); - let zone_serial = zone_serial.unwrap(); - - if let Ok(zone_name) = Name::::from_str(zone_name) { - if let Ok(zone_serial) = Serial::from_str(zone_serial) { - let (tx, mut rx) = mpsc::channel(10); - state - .component - .read() - .await - .send_command( - unit, - ApplicationCommand::HandleZoneReviewApi { - zone_name, - zone_serial, - approval_token: token, - operation: action, - http_tx: tx, - }, - ) - .await; - - let res = rx.recv().await; - let Some(res) = res else { - // Failed to receive response... When would that happen? - return Err(StatusCode::INTERNAL_SERVER_ERROR); - }; - - let ret = match res { - Ok(_) => Ok(()), - Err(_) => Err(StatusCode::BAD_REQUEST), - }; - // TODO: make debug when setting log level is fixed - warn!("[{HTTP_UNIT_NAME}]: Handled HTTP request: {uri} :: {ret:?}"); - // debug!("[{HTTP_UNIT_NAME}]: Handled HTTP request: {uri} :: {ret:?}"); - - return ret; - } else { - warn!("[{HTTP_UNIT_NAME}]: Invalid zone serial '{zone_serial}' in request."); - } - } else { - warn!("[{HTTP_UNIT_NAME}]: Invalid zone name '{zone_name}' in request."); - } + + let Some(zone_name) = params.get("zone") else { + warn!("[{HTTP_UNIT_NAME}]: Invalid HTTP request: {uri}"); + return Err(StatusCode::BAD_REQUEST); + }; + + let Some(zone_serial) = params.get("serial") else { + warn!("[{HTTP_UNIT_NAME}]: Invalid HTTP request: {uri}"); + return Err(StatusCode::BAD_REQUEST); + }; + + if token.is_empty() || !["approve", "reject"].contains(&action.as_ref()) { + warn!("[{HTTP_UNIT_NAME}]: Invalid HTTP request: {uri}"); + return Err(StatusCode::BAD_REQUEST); } - warn!("[{HTTP_UNIT_NAME}]: Invalid HTTP request: {uri}"); - Err(StatusCode::BAD_REQUEST) + + let Ok(zone_name) = Name::::from_str(zone_name) else { + warn!("[{HTTP_UNIT_NAME}]: Invalid zone name '{zone_name}' in request."); + return Err(StatusCode::BAD_REQUEST); + }; + + let Ok(zone_serial) = Serial::from_str(zone_serial) else { + warn!("[{HTTP_UNIT_NAME}]: Invalid zone serial '{zone_serial}' in request."); + return Err(StatusCode::BAD_REQUEST); + }; + + let (tx, mut rx) = mpsc::channel(10); + state + .component + .read() + .await + .send_command( + unit, + ApplicationCommand::HandleZoneReviewApi { + zone_name, + zone_serial, + approval_token: token, + operation: action, + http_tx: tx, + }, + ) + .await; + + let res = rx.recv().await; + let Some(res) = res else { + // Failed to receive response... When would that happen? + return Err(StatusCode::INTERNAL_SERVER_ERROR); + }; + + let ret = match res { + Ok(_) => Ok(()), + Err(_) => Err(StatusCode::BAD_REQUEST), + }; + + // TODO: make debug when setting log level is fixed + warn!("[{HTTP_UNIT_NAME}]: Handled HTTP request: {uri} :: {ret:?}"); + // debug!("[{HTTP_UNIT_NAME}]: Handled HTTP request: {uri} :: {ret:?}"); + + ret } } From 762053217a27072046744f17676e5285d17452fd Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 2 Sep 2025 16:53:24 +0200 Subject: [PATCH 3/3] fix clippy warnings --- Cargo.toml | 1 + src/api.rs | 2 +- src/cli/commands/status.rs | 2 +- src/cli/commands/zone.rs | 1 - src/cli/error.rs | 2 +- src/manager.rs | 9 ++++++--- src/targets/mod.rs | 1 + src/units/http_server.rs | 2 +- src/units/mod.rs | 1 + src/units/zone_loader.rs | 18 ++++++++++++------ src/units/zone_server.rs | 10 +++------- 11 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bf153141..c176340a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" license = "BSD-3-Clause" exclude = [".github", ".gitignore"] readme = "README.md" +rust-version = "1.84" [[bin]] name = "cascaded" diff --git a/src/api.rs b/src/api.rs index d4c70381..6259a47e 100644 --- a/src/api.rs +++ b/src/api.rs @@ -30,7 +30,7 @@ pub enum ZoneSource { } impl Display for ZoneSource { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { todo!() } } diff --git a/src/cli/commands/status.rs b/src/cli/commands/status.rs index 5da23a61..8d9de0af 100644 --- a/src/cli/commands/status.rs +++ b/src/cli/commands/status.rs @@ -35,7 +35,7 @@ impl Status { // TODO: move to function that can be called by the general // status command with a zone arg? let url = format!("/zone/{name}/status"); - let response: ZoneStatusResult = client + let _response: ZoneStatusResult = client .get(&url) .send() .and_then(|r| r.json()) diff --git a/src/cli/commands/zone.rs b/src/cli/commands/zone.rs index 73d2b670..600a1267 100644 --- a/src/cli/commands/zone.rs +++ b/src/cli/commands/zone.rs @@ -1,5 +1,4 @@ use bytes::Bytes; -use camino::Utf8PathBuf; use domain::base::Name; use futures::TryFutureExt; use log::error; diff --git a/src/cli/error.rs b/src/cli/error.rs index b45372e8..68054f1c 100644 --- a/src/cli/error.rs +++ b/src/cli/error.rs @@ -1,4 +1,4 @@ #[derive(Clone, Debug)] pub struct CliError { - msg: String, + _msg: String, } diff --git a/src/manager.rs b/src/manager.rs index 6fd2eb2e..4794b44e 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -279,7 +279,7 @@ impl Manager { "tcp:127.0.0.1:8056".parse().unwrap(), "udp:127.0.0.1:8056".parse().unwrap(), ], - xfr_out: HashMap::from([(zone_name.clone(), xfr_out)]), + _xfr_out: HashMap::from([(zone_name.clone(), xfr_out)]), hooks: vec![String::from("/tmp/approve_or_deny.sh")], mode: zone_server::Mode::Prepublish, source: zone_server::Source::UnsignedZones, @@ -321,7 +321,10 @@ impl Manager { "tcp:127.0.0.1:8057".parse().unwrap(), "udp:127.0.0.1:8057".parse().unwrap(), ], - xfr_out: HashMap::from([(zone_name.clone(), "127.0.0.1:8055 KEY sec1-key".into())]), + _xfr_out: HashMap::from([( + zone_name.clone(), + "127.0.0.1:8055 KEY sec1-key".into(), + )]), hooks: vec![String::from("/tmp/approve_or_deny_signed.sh")], mode: zone_server::Mode::Prepublish, source: zone_server::Source::SignedZones, @@ -337,7 +340,7 @@ impl Manager { "tcp:127.0.0.1:8058".parse().unwrap(), "udp:127.0.0.1:8058".parse().unwrap(), ], - xfr_out: HashMap::from([(zone_name.into(), "127.0.0.1:8055".into())]), + _xfr_out: HashMap::from([(zone_name, "127.0.0.1:8055".into())]), hooks: vec![], mode: zone_server::Mode::Publish, source: zone_server::Source::PublishedZones, diff --git a/src/targets/mod.rs b/src/targets/mod.rs index 29352a95..b7115b73 100644 --- a/src/targets/mod.rs +++ b/src/targets/mod.rs @@ -42,6 +42,7 @@ impl Target { } } + #[allow(dead_code)] pub fn type_name(&self) -> &'static str { match self { Target::CentraLCommand(_) => "central-command", diff --git a/src/units/http_server.rs b/src/units/http_server.rs index ccaaac41..dd5b2a4f 100644 --- a/src/units/http_server.rs +++ b/src/units/http_server.rs @@ -167,7 +167,7 @@ impl HttpServer { }) } - async fn zone_remove(Path(payload): Path>) -> Json { + async fn zone_remove(Path(_payload): Path>) -> Json { todo!() } diff --git a/src/units/mod.rs b/src/units/mod.rs index 94c5bbae..8f3954e5 100644 --- a/src/units/mod.rs +++ b/src/units/mod.rs @@ -60,6 +60,7 @@ impl Unit { }; } + #[allow(dead_code)] pub fn type_name(&self) -> &'static str { match self { Unit::ZoneLoader(_) => "zone-loader", diff --git a/src/units/zone_loader.rs b/src/units/zone_loader.rs index 989d8088..fbe80a18 100644 --- a/src/units/zone_loader.rs +++ b/src/units/zone_loader.rs @@ -311,9 +311,12 @@ impl ZoneLoader { if let Some(xfr_out) = xfr_out.get(zone_name) { let mut notify_cfg = NotifyConfig::default(); - let mut xfr_cfg = XfrConfig::default(); - xfr_cfg.strategy = XfrStrategy::IxfrWithAxfrFallback; - xfr_cfg.ixfr_transport = TransportStrategy::Tcp; + + let mut xfr_cfg = XfrConfig { + strategy: XfrStrategy::IxfrWithAxfrFallback, + ixfr_transport: TransportStrategy::Tcp, + ..Default::default() + }; let dst = parse_xfr_acl(xfr_out, &mut xfr_cfg, &mut notify_cfg, tsig_key_store) .map_err(|_| { @@ -374,9 +377,12 @@ impl ZoneLoader { if let Some(xfr_in) = xfr_in.get(zone_name) { let mut notify_cfg = NotifyConfig::default(); - let mut xfr_cfg = XfrConfig::default(); - xfr_cfg.strategy = XfrStrategy::IxfrWithAxfrFallback; - xfr_cfg.ixfr_transport = TransportStrategy::Tcp; + + let mut xfr_cfg = XfrConfig { + strategy: XfrStrategy::IxfrWithAxfrFallback, + ixfr_transport: TransportStrategy::Tcp, + ..Default::default() + }; let src = parse_xfr_acl(xfr_in, &mut xfr_cfg, &mut notify_cfg, tsig_key_store) .map_err(|_| { diff --git a/src/units/zone_server.rs b/src/units/zone_server.rs index 89b8c642..6cd8b6c5 100644 --- a/src/units/zone_server.rs +++ b/src/units/zone_server.rs @@ -119,7 +119,7 @@ pub struct ZoneServerUnit { pub listen: Vec, /// XFR out per zone: Allow XFR to, and when with a port also send NOTIFY to. - pub xfr_out: HashMap, + pub _xfr_out: HashMap, pub hooks: Vec, @@ -532,12 +532,7 @@ impl ZoneServer { self.zone_review_api .as_ref() .expect("This should have been setup on startup.") - .process_request( - zone_name.clone(), - zone_serial.clone(), - approval_token, - operation, - ) + .process_request(zone_name.clone(), zone_serial, approval_token, operation) .await, ) .await @@ -773,6 +768,7 @@ struct ZoneReviewApi { update_tx: mpsc::UnboundedSender, #[allow(clippy::type_complexity)] pending_approvals: Arc, Serial), Vec>>>, + #[allow(clippy::type_complexity)] last_approvals: Arc, Serial), Instant>>>, zones: XfrDataProvidingZonesWrapper, mode: Mode,