Skip to content

Commit

Permalink
add user public key (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzania authored Sep 21, 2023
1 parent edafc49 commit 02ff6a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub struct LocationInfo {
pub address: String,
pub endpoint: String,
pub active: bool,
pub pubkey: String,
}

#[tauri::command(async)]
Expand All @@ -175,6 +176,10 @@ pub async fn all_locations(
.map(|con| con.location_id)
.collect();
let mut location_info = vec![];
let keys = WireguardKeys::find_by_instance_id(&app_state.get_pool(), instance_id)
.await
.map_err(|err| err.to_string())?
.unwrap();
for location in locations {
let info = LocationInfo {
id: location.id.unwrap(),
Expand All @@ -183,6 +188,7 @@ pub async fn all_locations(
address: location.address,
endpoint: location.endpoint,
active: active_locations_ids.contains(&location.id.unwrap()),
pubkey: keys.pubkey.clone(),
};
location_info.push(info);
}
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/database/models/wireguard_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ impl WireguardKeys {
self.id = Some(result.id);
Ok(())
}
pub async fn find_by_location_id(
pub async fn find_by_instance_id(
pool: &DbPool,
location_id: i64,
instance_id: i64,
) -> Result<Option<Self>, SqlxError> {
query_as!(
Self,
"SELECT id \"id?\", instance_id, pubkey, prvkey \
FROM wireguard_keys WHERE instance_id = $1;",
location_id
instance_id
)
.fetch_optional(pool)
.await
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn setup_interface(location: Location, pool: &DbPool) -> Result<(), Er
address_interface(&location.name, &IpAddrMask::from_str(&location.address)?)?;
let api = WGApi::new(location.name.clone(), false);
let mut host = api.read_host()?;
if let Some(keys) = WireguardKeys::find_by_location_id(pool, location.instance_id).await? {
if let Some(keys) = WireguardKeys::find_by_instance_id(pool, location.instance_id).await? {
// TODO: handle unwrap
let private_key: Key = Key::from_str(&keys.prvkey).unwrap();
host.private_key = Some(private_key);
Expand Down

0 comments on commit 02ff6a3

Please sign in to comment.