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
8 changes: 7 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,13 @@ pub async fn delete_instance(instance_id: Id, handle: AppHandle) -> Result<(), E
instance_id: instance.uuid.clone(),
})
.await
.unwrap();
.map_err(|err| {
error!(
"Error while deleting service locations from the daemon for instance {}({}): {err}",
instance.name, instance.id,
);
Error::InternalError(err.to_string())
})?;

reload_tray_menu(&handle).await;

Expand Down
20 changes: 16 additions & 4 deletions src-tauri/src/database/models/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ impl Location<Id> {
where
E: SqliteExecutor<'e>,
{
let max_mode = if include_service_locations { 2 } else { 0 }; // 0 to exclude service locations, 2 to include them
let max_service_location_mode =
Self::get_service_location_mode_filter(include_service_locations);
query_as!(
Self,
"SELECT id, instance_id, name, address, pubkey, endpoint, allowed_ips, dns, network_id,\
route_all_traffic, keepalive_interval, \
location_mfa_mode \"location_mfa_mode: LocationMfaMode\", service_location_mode \"service_location_mode: ServiceLocationMode\" \
FROM location WHERE service_location_mode <= $1 \
ORDER BY name ASC;",
max_mode
max_service_location_mode
)
.fetch_all(executor)
.await
Expand Down Expand Up @@ -163,15 +164,16 @@ impl Location<Id> {
where
E: SqliteExecutor<'e>,
{
let max_mode = if include_service_locations { 2 } else { 0 }; // 0 to exclude service locations, 2 to include them
let max_service_location_mode =
Self::get_service_location_mode_filter(include_service_locations);
query_as!(
Self,
"SELECT id \"id: _\", instance_id, name, address, pubkey, endpoint, allowed_ips, dns, \
network_id, route_all_traffic, keepalive_interval, location_mfa_mode \"location_mfa_mode: LocationMfaMode\", service_location_mode \"service_location_mode: ServiceLocationMode\" \
FROM location WHERE instance_id = $1 AND service_location_mode <= $2 \
ORDER BY name ASC",
instance_id,
max_mode
max_service_location_mode
)
.fetch_all(executor)
.await
Expand Down Expand Up @@ -228,6 +230,16 @@ impl Location<Id> {
LocationMfaMode::Internal | LocationMfaMode::External => true,
}
}

/// Returns a filter value that can be used in SQL queries like `service_location_mode <= ?` when querying locations
/// to exclude (<= 1) or include service locations (all service locations modes).
fn get_service_location_mode_filter(include_service_locations: bool) -> i32 {
if include_service_locations {
i32::MAX
} else {
ServiceLocationMode::Disabled as i32
}
}
}

impl Location<NoId> {
Expand Down
6 changes: 4 additions & 2 deletions src-tauri/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ use tracing::{debug, error, info, info_span, Instrument};

use self::config::Config;
use super::VERSION;
use crate::enterprise::service_locations::ServiceLocationError;
#[cfg(windows)]
use crate::enterprise::service_locations::ServiceLocationManager;
use crate::service::proto::{DeleteServiceLocationsRequest, SaveServiceLocationsRequest};
use crate::{
enterprise::service_locations::ServiceLocationError,
service::proto::{DeleteServiceLocationsRequest, SaveServiceLocationsRequest},
};

#[cfg(windows)]
const DAEMON_HTTP_PORT: u16 = 54127;
Expand Down