diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 37d5ae7e..ebc88ca4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -765,6 +765,8 @@ version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -1284,6 +1286,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", + "vergen-git2", "webbrowser", "windows-service", "x25519-dalek", @@ -1351,6 +1354,37 @@ dependencies = [ "syn 2.0.75", ] +[[package]] +name = "derive_builder" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.75", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" +dependencies = [ + "derive_builder_core", + "syn 2.0.75", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -2075,6 +2109,18 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "getset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "gimli" version = "0.29.0" @@ -2111,6 +2157,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags 2.6.0", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glib" version = "0.15.12" @@ -2850,6 +2909,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -2948,6 +3016,18 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libloading" version = "0.7.4" @@ -2996,6 +3076,18 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -6500,6 +6592,46 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vergen" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c32e7318e93a9ac53693b6caccfb05ff22e04a44c7cf8a279051f24c09da286f" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", + "time", + "vergen-lib", +] + +[[package]] +name = "vergen-git2" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62c52cd2b2b8b7ec75fc20111b3022ac3ff83e4fc14b9497cfcfd39c54f9c67" +dependencies = [ + "anyhow", + "derive_builder", + "git2", + "rustversion", + "time", + "vergen", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e06bee42361e43b60f363bad49d63798d0f42fb1768091812270eca00c784720" +dependencies = [ + "anyhow", + "derive_builder", + "getset", + "rustversion", +] + [[package]] name = "version-compare" version = "0.0.11" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index f6bbf6d7..9cd61414 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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" diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 36881822..bcb19fb1 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,4 +1,10 @@ +use vergen_git2::{Emitter, Git2Builder}; + fn main() -> Result<(), Box> { + // 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 diff --git a/src-tauri/src/bin/defguard-client.rs b/src-tauri/src/bin/defguard-client.rs index 65f47559..66229d3e 100644 --- a/src-tauri/src/bin/defguard-client.rs +++ b/src-tauri/src/bin/defguard-client.rs @@ -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}; @@ -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"); diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 8d6093ed..c87b2b90 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -163,37 +163,66 @@ pub async fn save_device_config( app_state: State<'_, AppState>, handle: AppHandle, ) -> Result { - 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) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 847a4bdf..dc9e3216 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -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 {