Skip to content

Commit

Permalink
return valid flag
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander committed Dec 20, 2024
1 parent f117f68 commit 465de9e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/handlers/network_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,36 @@ pub(crate) async fn check_ip_availability(
);
WebError::BadRequest("Failed to check IP availability, network not found".to_string())
})?;
if let Err(e) = check_ip(ip.ip, &network, &mut transaction).await {
if !network.address.contains(ip.ip) {
warn!(
"Provided device IP is unavailable, reason: {}",
e.to_string()
"Provided device IP is not in the network ({}) range {}",
network.name, network.address
);
return Ok(ApiResponse {
json: json!({
"available": false,
"valid": false,
}),
status: StatusCode::OK,
});
}
if let Some(device) = Device::find_by_ip(&mut *transaction, ip.ip, network.id).await? {
warn!(
"Provided device IP is already assigned to device {} in network {}",
device.name, network.name
);
return Ok(ApiResponse {
json: json!({
"available": false,
"valid": true,
}),
status: StatusCode::OK,
});
}
Ok(ApiResponse {
json: json!({
"available": true,
"valid": true,
}),
status: StatusCode::OK,
})
Expand Down

0 comments on commit 465de9e

Please sign in to comment.