fix : removed unused variables and made structs private
This commit is contained in:
parent
08ce4c3942
commit
79edb50f65
1 changed files with 34 additions and 50 deletions
|
@ -7,7 +7,7 @@ use tide::{
|
|||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SSHKey {
|
||||
struct SSHKey {
|
||||
auth: LdapAuth,
|
||||
key: String,
|
||||
}
|
||||
|
@ -22,24 +22,24 @@ pub async fn add_ssh_key(mut req: Request<State>) -> tide::Result {
|
|||
let LdapAuthResult {
|
||||
mut ldap,
|
||||
dn,
|
||||
is_skynet_user: _,
|
||||
..
|
||||
} = match crate::auth_user(&auth, config).await {
|
||||
None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()),
|
||||
Some(x) => x,
|
||||
};
|
||||
|
||||
let mods = vec![Mod::Add("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||
match ldap.modify(&dn, mods) {
|
||||
Ok(_) => {
|
||||
ldap.unbind()?;
|
||||
Ok(json!({"result": "success"}).into())
|
||||
}
|
||||
let mods = vec![Mod::Add("sshPublicKey".to_owned(), HashSet::from([key]))];
|
||||
let result = match ldap.modify(&dn, mods) {
|
||||
Ok(_) => Ok(json!({"result": "success"}).into()),
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
ldap.unbind()?;
|
||||
Ok(json!({"result": "error", "error": "Failed to add key"}).into())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ldap.unbind()?;
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||
|
@ -52,63 +52,46 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
|||
let LdapAuthResult {
|
||||
mut ldap,
|
||||
dn,
|
||||
is_skynet_user: _,
|
||||
..
|
||||
} = match crate::auth_user(&auth, config).await {
|
||||
None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()),
|
||||
Some(x) => {
|
||||
if x.is_skynet_user {
|
||||
x
|
||||
} else {
|
||||
return Ok(json!({"result": "error", "error": "Not a skynet user"}).into());
|
||||
}
|
||||
Some(x) => x,
|
||||
};
|
||||
|
||||
let mods = vec![Mod::Delete("sshPublicKey".to_owned(), HashSet::from([key]))];
|
||||
|
||||
let result = match ldap.modify(&dn, mods) {
|
||||
Ok(_) => Ok(json!({"result": "success"}).into()),
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
Ok(json!({"result": "error", "error": "Failed to add key"}).into())
|
||||
}
|
||||
};
|
||||
|
||||
let mods = vec![Mod::Delete("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||
ldap.unbind()?;
|
||||
|
||||
match ldap.modify(&dn, mods) {
|
||||
Ok(_) => {
|
||||
ldap.unbind()?;
|
||||
Ok(json!({"result": "success"}).into())
|
||||
}
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
ldap.unbind()?;
|
||||
Ok(json!({"result": "error", "error": "Failed to remove key"}).into())
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SSHKeyGet {
|
||||
auth: LdapAuth,
|
||||
}
|
||||
|
||||
pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
||||
let LdapAuth {
|
||||
user,
|
||||
pass,
|
||||
let SSHKeyGet {
|
||||
auth,
|
||||
} = req.body_json().await?;
|
||||
let config = &req.state().config;
|
||||
|
||||
let LdapAuthResult {
|
||||
mut ldap,
|
||||
dn,
|
||||
is_skynet_user: _,
|
||||
} = match crate::auth_user(
|
||||
&LdapAuth {
|
||||
user,
|
||||
pass,
|
||||
},
|
||||
config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
..
|
||||
} = match crate::auth_user(&auth, config).await {
|
||||
None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()),
|
||||
Some(x) => {
|
||||
if x.is_skynet_user {
|
||||
x
|
||||
} else {
|
||||
return Ok(json!({"result": "error", "error": "Not a skynet user"}).into());
|
||||
}
|
||||
}
|
||||
Some(x) => x,
|
||||
};
|
||||
|
||||
let mut keys: Vec<String> = vec![];
|
||||
let (rs, _res) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["sshPublicKey"])?.success()?;
|
||||
for entry in rs {
|
||||
|
@ -119,6 +102,7 @@ pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
ldap.unbind()?;
|
||||
|
||||
Ok(json!({"result": "success", "success": keys}).into())
|
||||
|
|
Loading…
Reference in a new issue