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::{
|
use skynet_ldap_backend::{
|
||||||
db_init, get_config,
|
db_init, get_config,
|
||||||
methods::{account_new, account_recover, account_update, account_ssh},
|
methods::{account_new, account_recover, account_ssh, account_update},
|
||||||
State,
|
State,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashSet;
|
use crate::{LdapAuth, LdapAuthResult, State};
|
||||||
use crate::{State, LdapAuthResult, LdapAuth};
|
|
||||||
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
||||||
|
use std::collections::HashSet;
|
||||||
use tide::{
|
use tide::{
|
||||||
prelude::{json, Deserialize},
|
prelude::{json, Deserialize},
|
||||||
Request,
|
Request,
|
||||||
|
@ -34,9 +34,7 @@ pub async fn add_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mods = vec![
|
let mods = vec![Mod::Add("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||||
Mod::Add("sshPublicKey".to_string(), HashSet::from([key])),
|
|
||||||
];
|
|
||||||
match ldap.modify(&dn, mods) {
|
match ldap.modify(&dn, mods) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
ldap.unbind()?;
|
ldap.unbind()?;
|
||||||
|
@ -70,15 +68,13 @@ pub async fn remove_ssh_key(mut req: Request<State>) -> tide::Result {
|
||||||
let LdapAuthResult {
|
let LdapAuthResult {
|
||||||
mut ldap,
|
mut ldap,
|
||||||
dn,
|
dn,
|
||||||
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) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mods = vec![
|
let mods = vec![Mod::Delete("sshPublicKey".to_string(), HashSet::from([key]))];
|
||||||
Mod::Delete("sshPublicKey".to_string(), HashSet::from([key])),
|
|
||||||
];
|
|
||||||
|
|
||||||
match ldap.modify(&dn, mods) {
|
match ldap.modify(&dn, mods) {
|
||||||
Ok(_) => {
|
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 {
|
pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
||||||
let LdapAuth {
|
let LdapAuth {
|
||||||
user,
|
user,
|
||||||
pass
|
pass,
|
||||||
} = req.body_json().await?;
|
} = req.body_json().await?;
|
||||||
let config = &req.state().config;
|
let config = &req.state().config;
|
||||||
|
|
||||||
|
@ -109,16 +105,25 @@ pub async fn get_ssh_keys(mut req: Request<State>) -> tide::Result {
|
||||||
mut ldap,
|
mut ldap,
|
||||||
dn,
|
dn,
|
||||||
is_skynet_user: _,
|
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()),
|
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
|
x
|
||||||
} else {
|
} else {
|
||||||
return Ok(json!({"result": "error", "error": "Not a skynet user"}).into());
|
return Ok(json!({"result": "error", "error": "Not a skynet user"}).into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let mut keys: Vec<String> = vec![];
|
let mut keys: Vec<String> = vec![];
|
||||||
let (rs, _res) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["sshPublicKey"])?.success()?;
|
let (rs, _res) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["sshPublicKey"])?.success()?;
|
||||||
for entry in rs {
|
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())
|
Ok(json!({"result": "success", "success": keys}).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod account_new;
|
pub mod account_new;
|
||||||
pub mod account_recover;
|
pub mod account_recover;
|
||||||
pub mod account_update;
|
|
||||||
pub mod account_ssh;
|
pub mod account_ssh;
|
||||||
|
pub mod account_update;
|
Loading…
Reference in a new issue