Skip to content

Commit 447b50f

Browse files
authored
Fix for network device config (#2587)
1 parent c408dfb commit 447b50f

5 files changed

Lines changed: 37 additions & 44 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/defguard_core/src/handlers/proxy.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,14 @@ pub(crate) async fn proxy_cert_self_signed(
324324
WebError::Http(StatusCode::INTERNAL_SERVER_ERROR)
325325
})?;
326326

327-
let (ca_cert_der, ca_key_der) = match (certs.ca_cert_der.clone(), certs.ca_key_der.clone()) {
328-
(Some(c), Some(k)) => (c, k),
329-
_ => {
330-
warn!("CA not configured; cannot issue self-signed proxy cert");
331-
return Ok(ApiResponse::json(
332-
serde_json::json!({"msg": "Core CA is not configured"}),
333-
StatusCode::BAD_REQUEST,
334-
));
335-
}
327+
let (Some(ca_cert_der), Some(ca_key_der)) =
328+
(certs.ca_cert_der.clone(), certs.ca_key_der.clone())
329+
else {
330+
warn!("CA not configured; cannot issue self-signed proxy cert");
331+
return Ok(ApiResponse::json(
332+
serde_json::json!({"msg": "Core CA is not configured"}),
333+
StatusCode::BAD_REQUEST,
334+
));
336335
};
337336

338337
// Build CA from stored DER blobs.

crates/defguard_core/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use handlers::{
5353
};
5454
use ipnetwork::IpNetwork;
5555
use regex::Regex;
56-
use reqwest::Url;
5756
use secrecy::ExposeSecret;
5857
use semver::Version;
5958
use sqlx::PgPool;
@@ -740,8 +739,7 @@ pub async fn init_dev_env(config: &DefGuardConfig) {
740739
settings.public_proxy_url = config
741740
.enrollment_url
742741
.clone()
743-
.unwrap_or(Url::parse("http://localhost:8080").unwrap())
744-
.to_string();
742+
.map_or(String::from("http://localhost:8080"), |url| url.to_string());
745743
settings.defguard_url = config.url.clone().unwrap().to_string();
746744
update_current_settings(&pool, settings)
747745
.await

web/src/pages/NetworkDevicesPage/NetworkDevicesTable.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ export const NetworkDevicesTable = ({ networkDevices }: Props) => {
227227
text: m.network_devices_action_view_config(),
228228
icon: 'config',
229229
onClick: async () => {
230-
const { data: config } = await api.network_device.getDeviceConfig(row.id);
230+
const { data: configs } = await api.network_device.getDeviceConfig(
231+
row.id,
232+
);
231233
openModal(ModalName.NetworkDeviceConfig, {
232-
config,
234+
config: configs[0].config,
233235
device: row,
234236
});
235237
},

web/src/shared/api/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ const api = {
320320
client.put(`/device/network/${id}`, data),
321321
getDevice: (id: number) => client.get<NetworkDevice>(`/device/network/${id}`),
322322
getDevices: () => fetchAllPages<NetworkDevice>('/device/network'),
323-
getDeviceConfig: (id: number) => client.get<string>(`/device/network/${id}/config`),
323+
getDeviceConfig: (id: number) =>
324+
client.get<AddDeviceResponseConfig[]>(`/device/network/${id}/config`),
324325
generateToken: (id: number) =>
325326
client.post<StartEnrollmentResponse>(`/device/network/start_cli/${id}`),
326327
addCliDevice: (data: AddNetworkDeviceRequest) =>

0 commit comments

Comments
 (0)