Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
license = "BSD-3-Clause"
exclude = [".github", ".gitignore"]
readme = "README.md"
rust-version = "1.84"

[[bin]]
name = "cascaded"
Expand Down
2 changes: 1 addition & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/zone.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bytes::Bytes;
use camino::Utf8PathBuf;
use domain::base::Name;
use futures::TryFutureExt;
use log::error;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Debug)]
pub struct CliError {
msg: String,
_msg: String,
}
9 changes: 6 additions & 3 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Target {
}
}

#[allow(dead_code)]
pub fn type_name(&self) -> &'static str {
match self {
Target::CentraLCommand(_) => "central-command",
Expand Down
112 changes: 59 additions & 53 deletions src/units/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl HttpServer {
})
}

async fn zone_remove(Path(payload): Path<Name<Bytes>>) -> Json<ZoneRemoveResult> {
async fn zone_remove(Path(_payload): Path<Name<Bytes>>) -> Json<ZoneRemoveResult> {
todo!()
}

Expand Down Expand Up @@ -366,58 +366,64 @@ impl HttpServer {
params: HashMap<String, String>,
) -> 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::<Bytes>::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::<Bytes>::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
}
}
1 change: 1 addition & 0 deletions src/units/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Unit {
};
}

#[allow(dead_code)]
pub fn type_name(&self) -> &'static str {
match self {
Unit::ZoneLoader(_) => "zone-loader",
Expand Down
18 changes: 12 additions & 6 deletions src/units/zone_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {
Expand Down Expand Up @@ -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(|_| {
Expand Down
10 changes: 3 additions & 7 deletions src/units/zone_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct ZoneServerUnit {
pub listen: Vec<ListenAddr>,

/// XFR out per zone: Allow XFR to, and when with a port also send NOTIFY to.
pub xfr_out: HashMap<StoredName, String>,
pub _xfr_out: HashMap<StoredName, String>,

pub hooks: Vec<String>,

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -773,6 +768,7 @@ struct ZoneReviewApi {
update_tx: mpsc::UnboundedSender<Update>,
#[allow(clippy::type_complexity)]
pending_approvals: Arc<RwLock<HashMap<(Name<Bytes>, Serial), Vec<Uuid>>>>,
#[allow(clippy::type_complexity)]
last_approvals: Arc<RwLock<HashMap<(Name<Bytes>, Serial), Instant>>>,
zones: XfrDataProvidingZonesWrapper,
mode: Mode,
Expand Down
Loading