From 08ce4c39427ecc26c08abe84f823b8fc737a1764 Mon Sep 17 00:00:00 2001 From: daragh Date: Sat, 30 Dec 2023 13:09:13 +0000 Subject: [PATCH] fix : remove redundant code + fmt --- src/methods/account_ssh.rs | 31 ++++++++----------------------- src/methods/mod.rs | 2 +- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/methods/account_ssh.rs b/src/methods/account_ssh.rs index e2b14e8..9488df3 100644 --- a/src/methods/account_ssh.rs +++ b/src/methods/account_ssh.rs @@ -1,5 +1,5 @@ use crate::{LdapAuth, LdapAuthResult, State}; -use ldap3::{LdapConn, Mod, Scope, SearchEntry}; +use ldap3::{Mod, Scope, SearchEntry}; use std::collections::HashSet; use tide::{ prelude::{json, Deserialize}, @@ -17,14 +17,8 @@ pub async fn add_ssh_key(mut req: Request) -> tide::Result { auth, key, } = req.body_json().await?; - let config = &req.state().config; - let mut ldap = LdapConn::new(&config.ldap_host)?; - - let dn = format!("uid={},ou=users,dc=skynet,dc=ie", auth.user); - ldap.simple_bind(&dn, &auth.pass)?.success()?; - let LdapAuthResult { mut ldap, dn, @@ -54,16 +48,6 @@ pub async fn remove_ssh_key(mut req: Request) -> tide::Result { key, } = req.body_json().await?; let config = &req.state().config; - let mut ldap = LdapConn::new(&config.ldap_host)?; - let dn = format!("uid={},ou=users,dc=skynet,dc=ie", auth.user); - - match ldap.simple_bind(&dn, &auth.pass) { - Ok(_) => {} - Err(e) => { - dbg!(e); - return Ok(json!({"result": "error", "error": "Failed to bind"}).into()); - } - } let LdapAuthResult { mut ldap, @@ -71,7 +55,13 @@ pub async fn remove_ssh_key(mut req: Request) -> tide::Result { is_skynet_user: _, } = match crate::auth_user(&auth, config).await { None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()), - Some(x) => x, + Some(x) => { + if x.is_skynet_user { + x + } else { + return Ok(json!({"result": "error", "error": "Not a skynet user"}).into()); + } + } }; let mods = vec![Mod::Delete("sshPublicKey".to_string(), HashSet::from([key]))]; @@ -96,11 +86,6 @@ pub async fn get_ssh_keys(mut req: Request) -> tide::Result { } = req.body_json().await?; let config = &req.state().config; - let mut ldap = LdapConn::new(&config.ldap_host)?; - - let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user); - ldap.simple_bind(&dn, &pass)?.success()?; - let LdapAuthResult { mut ldap, dn, diff --git a/src/methods/mod.rs b/src/methods/mod.rs index 311c6f1..0968f44 100644 --- a/src/methods/mod.rs +++ b/src/methods/mod.rs @@ -1,4 +1,4 @@ pub mod account_new; pub mod account_recover; pub mod account_ssh; -pub mod account_update; \ No newline at end of file +pub mod account_update;