fix : remove redundant code + fmt
This commit is contained in:
parent
2e0ba6e53c
commit
08ce4c3942
2 changed files with 9 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::{LdapAuth, LdapAuthResult, State};
|
use crate::{LdapAuth, LdapAuthResult, State};
|
||||||
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
use ldap3::{Mod, Scope, SearchEntry};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use tide::{
|
use tide::{
|
||||||
prelude::{json, Deserialize},
|
prelude::{json, Deserialize},
|
||||||
|
@ -17,14 +17,8 @@ pub async fn add_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||||
auth,
|
auth,
|
||||||
key,
|
key,
|
||||||
} = req.body_json().await?;
|
} = req.body_json().await?;
|
||||||
|
|
||||||
let config = &req.state().config;
|
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 {
|
let LdapAuthResult {
|
||||||
mut ldap,
|
mut ldap,
|
||||||
dn,
|
dn,
|
||||||
|
@ -54,16 +48,6 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||||
key,
|
key,
|
||||||
} = req.body_json().await?;
|
} = req.body_json().await?;
|
||||||
let config = &req.state().config;
|
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 {
|
let LdapAuthResult {
|
||||||
mut ldap,
|
mut ldap,
|
||||||
|
@ -71,7 +55,13 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||||
is_skynet_user: _,
|
is_skynet_user: _,
|
||||||
} = match crate::auth_user(&auth, config).await {
|
} = match crate::auth_user(&auth, config).await {
|
||||||
None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()),
|
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]))];
|
let mods = vec![Mod::Delete("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||||
|
@ -96,11 +86,6 @@ pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
||||||
} = req.body_json().await?;
|
} = req.body_json().await?;
|
||||||
let config = &req.state().config;
|
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 {
|
let LdapAuthResult {
|
||||||
mut ldap,
|
mut ldap,
|
||||||
dn,
|
dn,
|
||||||
|
|
Loading…
Reference in a new issue