fmt : rustrover formatter is different from cargo fmt ¯\_(ツ)_/¯
This commit is contained in:
parent
0638f48397
commit
2e0ba6e53c
3 changed files with 138 additions and 135 deletions
|
@ -1,6 +1,6 @@
|
|||
use skynet_ldap_backend::{
|
||||
db_init, get_config,
|
||||
methods::{account_new, account_recover, account_update, account_ssh},
|
||||
methods::{account_new, account_recover, account_ssh, account_update},
|
||||
State,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashSet;
|
||||
use crate::{State, LdapAuthResult, LdapAuth};
|
||||
use crate::{LdapAuth, LdapAuthResult, State};
|
||||
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
||||
use std::collections::HashSet;
|
||||
use tide::{
|
||||
prelude::{json, Deserialize},
|
||||
Request,
|
||||
|
@ -34,9 +34,7 @@ pub async fn add_ssh_key(mut req: Request<State>) -> tide::Result {
|
|||
Some(x) => x,
|
||||
};
|
||||
|
||||
let mods = vec![
|
||||
Mod::Add("sshPublicKey".to_string(), HashSet::from([key])),
|
||||
];
|
||||
let mods = vec![Mod::Add("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||
match ldap.modify(&dn, mods) {
|
||||
Ok(_) => {
|
||||
ldap.unbind()?;
|
||||
|
@ -70,15 +68,13 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
|||
let LdapAuthResult {
|
||||
mut ldap,
|
||||
dn,
|
||||
is_skynet_user: _
|
||||
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::Delete("sshPublicKey".to_string(), HashSet::from([key])),
|
||||
];
|
||||
let mods = vec![Mod::Delete("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||
|
||||
match ldap.modify(&dn, mods) {
|
||||
Ok(_) => {
|
||||
|
@ -96,7 +92,7 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
|||
pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
||||
let LdapAuth {
|
||||
user,
|
||||
pass
|
||||
pass,
|
||||
} = req.body_json().await?;
|
||||
let config = &req.state().config;
|
||||
|
||||
|
@ -109,16 +105,25 @@ pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
|||
mut ldap,
|
||||
dn,
|
||||
is_skynet_user: _,
|
||||
} = match crate::auth_user(&LdapAuth { user, pass }, config).await {
|
||||
} = match crate::auth_user(
|
||||
&LdapAuth {
|
||||
user,
|
||||
pass,
|
||||
},
|
||||
config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
None => return Ok(json!({"result": "error", "error": "Failed to authenticate"}).into()),
|
||||
Some(x) => if x.is_skynet_user {
|
||||
Some(x) => {
|
||||
if x.is_skynet_user {
|
||||
x
|
||||
} else {
|
||||
return Ok(json!({"result": "error", "error": "Not a skynet user"}).into());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mut keys: Vec<String> = vec![];
|
||||
let (rs, _res) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["sshPublicKey"])?.success()?;
|
||||
for entry in rs {
|
||||
|
@ -133,5 +138,3 @@ pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
|||
|
||||
Ok(json!({"result": "success", "success": keys}).into())
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub mod account_new;
|
||||
pub mod account_recover;
|
||||
pub mod account_update;
|
||||
pub mod account_ssh;
|
||||
pub mod account_update;
|
Loading…
Reference in a new issue