Skip to content

Commit

Permalink
chore: more logs for enrollment process (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-chmielewski authored Sep 9, 2024
1 parent 46a870a commit c47601c
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 4 deletions.
132 changes: 132 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ authors = ["Defguard"]
tauri-build = { version = "1.5", features = [] }
tonic-build = { version = "0.12" }
prost-build = { version = "0.13" }
vergen-git2 = { version = "1.0", features = ["build"] }

[dependencies]
anyhow = "1.0"
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use vergen_git2::{Emitter, Git2Builder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// set VERGEN_GIT_SHA env variable based on git commit hash
let git2 = Git2Builder::default().branch(true).sha(true).build()?;
Emitter::default().add_instructions(&git2)?.emit()?;

// compiling protos using path on build time
let mut config = prost_build::Config::new();
// enable optional fields
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/bin/defguard-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use defguard_client::{
periodic::{config::poll_config, version::poll_version},
tray::{configure_tray_icon, handle_tray_event, reload_tray_menu},
utils::load_log_targets,
VERSION,
};
use std::{env, str::FromStr};

Expand Down Expand Up @@ -142,6 +143,7 @@ async fn main() {
.build(tauri::generate_context!())
.expect("error while running tauri application");

info!("Starting ... version v{}", VERSION);
// initialize database
let app_handle = app.handle();
debug!("Initializing database connection");
Expand Down
37 changes: 33 additions & 4 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,37 +163,66 @@ pub async fn save_device_config(
app_state: State<'_, AppState>,
handle: AppHandle,
) -> Result<SaveDeviceConfigResponse, Error> {
debug!("Received device configuration: {response:#?}.");
debug!("Saving device configuration: {response:#?}.");

let mut transaction = app_state.get_pool().begin().await?;
let instance_info = response
.instance
.expect("Missing instance info in device config response");
let mut instance: Instance = instance_info.into();
if response.token.is_some() {
info!("Received polling token for instance {}", instance.name);
} else {
warn!(
"Missing polling token for instance {}, core and/or proxy services may need an update, configuration polling won't work",
instance.name,
);
}
instance.token = response.token;

debug!("Saving instance {}", instance.name);
let instance = instance.save(&mut *transaction).await?;
info!("Saved instance {}", instance.name);

let device = response
.device
.expect("Missing device info in device config response");
debug!(
"Saving wireguard key {} for instance {}({})",
device.pubkey, instance.name, instance.id
);
let mut keys = WireguardKeys::new(instance.id, device.pubkey, private_key);
keys.save(&mut *transaction).await?;
info!(
"Saved wireguard key {} for instance {}({})",
keys.pubkey, instance.name, instance.id
);
for location in response.configs {
let new_location = device_config_to_location(location, instance.id);
new_location.save(&mut *transaction).await?;
debug!(
"Saving location {} for instance {}({})",
new_location.name, instance.name, instance.id
);
let new_location = new_location.save(&mut *transaction).await?;
info!(
"Saved location {} for instance {}({})",
new_location.name, instance.name, instance.id
);
}
transaction.commit().await?;
info!("Instance created.");
info!("Instance {}({:?}) created.", instance.name, instance.id);
trace!("Created following instance: {instance:#?}");
let locations = Location::find_by_instance_id(&app_state.get_pool(), instance.id).await?;
trace!("Created following locations: {locations:#?}");
handle.emit_all(INSTANCE_UPDATE, ())?;
info!(
"Device configuration saved for instance {}({})",
instance.name, instance.id,
);
let res: SaveDeviceConfigResponse = SaveDeviceConfigResponse {
locations,
instance,
};
info!("Device configuration saved.");
reload_tray_menu(&handle).await;
Ok(res)
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod proto {
tonic::include_proto!("defguard.proxy");
}

pub const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "-", env!("VERGEN_GIT_SHA"));

/// Location type used in commands to check if we using tunnel or location
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone, Copy)]
pub enum ConnectionType {
Expand Down

0 comments on commit c47601c

Please sign in to comment.