Remove async references (#724)

This commit is contained in:
Firstyear 2022-04-29 13:23:46 +10:00 committed by GitHub
parent 8dc0199380
commit 53f3260285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1712 additions and 1728 deletions

2
Cargo.lock generated
View file

@ -638,6 +638,8 @@ dependencies = [
[[package]] [[package]]
name = "concread" name = "concread"
version = "0.3.1" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65099306f247b9a7bdd2919bba79355f646e477bc59ff4e8c13a1af976ed86fc"
dependencies = [ dependencies = [
"ahash", "ahash",
"crossbeam", "crossbeam",

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,12 +2,12 @@ use crate::session::read_tokens;
use crate::CommonOpt; use crate::CommonOpt;
use compact_jwt::{Jws, JwsUnverified}; use compact_jwt::{Jws, JwsUnverified};
use dialoguer::{theme::ColorfulTheme, Select}; use dialoguer::{theme::ColorfulTheme, Select};
use kanidm_client::{KanidmAsyncClient, KanidmClientBuilder}; use kanidm_client::{KanidmClient, KanidmClientBuilder};
use kanidm_proto::v1::UserAuthToken; use kanidm_proto::v1::UserAuthToken;
use std::str::FromStr; use std::str::FromStr;
impl CommonOpt { impl CommonOpt {
pub fn to_unauth_client(&self) -> KanidmAsyncClient { pub fn to_unauth_client(&self) -> KanidmClient {
let config_path: String = shellexpand::tilde("~/.config/kanidm").into_owned(); let config_path: String = shellexpand::tilde("~/.config/kanidm").into_owned();
let client_builder = KanidmClientBuilder::new() let client_builder = KanidmClientBuilder::new()
@ -46,13 +46,13 @@ impl CommonOpt {
client_builder client_builder
); );
client_builder.build_async().unwrap_or_else(|e| { client_builder.build().unwrap_or_else(|e| {
error!("Failed to build client instance -- {:?}", e); error!("Failed to build client instance -- {:?}", e);
std::process::exit(1); std::process::exit(1);
}) })
} }
pub async fn to_client(&self) -> KanidmAsyncClient { pub async fn to_client(&self) -> KanidmClient {
let client = self.to_unauth_client(); let client = self.to_unauth_client();
// Read the token file. // Read the token file.
let tokens = match read_tokens() { let tokens = match read_tokens() {

View file

@ -1,7 +1,7 @@
use crate::common::prompt_for_username_get_username; use crate::common::prompt_for_username_get_username;
use crate::{LoginOpt, LogoutOpt, SessionOpt}; use crate::{LoginOpt, LogoutOpt, SessionOpt};
use kanidm_client::{ClientError, KanidmAsyncClient}; use kanidm_client::{ClientError, KanidmClient};
use kanidm_proto::v1::{AuthAllowed, AuthResponse, AuthState, UserAuthToken}; use kanidm_proto::v1::{AuthAllowed, AuthResponse, AuthState, UserAuthToken};
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
use libc::umask; use libc::umask;
@ -142,10 +142,7 @@ impl LoginOpt {
self.copt.debug self.copt.debug
} }
async fn do_password( async fn do_password(&self, client: &mut KanidmClient) -> Result<AuthResponse, ClientError> {
&self,
client: &mut KanidmAsyncClient,
) -> Result<AuthResponse, ClientError> {
let password = rpassword::prompt_password("Enter password: ").unwrap_or_else(|e| { let password = rpassword::prompt_password("Enter password: ").unwrap_or_else(|e| {
error!("Failed to create password prompt -- {:?}", e); error!("Failed to create password prompt -- {:?}", e);
std::process::exit(1); std::process::exit(1);
@ -153,10 +150,7 @@ impl LoginOpt {
client.auth_step_password(password.as_str()).await client.auth_step_password(password.as_str()).await
} }
async fn do_backup_code( async fn do_backup_code(&self, client: &mut KanidmClient) -> Result<AuthResponse, ClientError> {
&self,
client: &mut KanidmAsyncClient,
) -> Result<AuthResponse, ClientError> {
print!("Enter Backup Code: "); print!("Enter Backup Code: ");
// We flush stdout so it'll write the buffer to screen, continuing operation. Without it, the application halts. // We flush stdout so it'll write the buffer to screen, continuing operation. Without it, the application halts.
#[allow(clippy::unwrap_used)] #[allow(clippy::unwrap_used)]
@ -174,7 +168,7 @@ impl LoginOpt {
client.auth_step_backup_code(backup_code.trim()).await client.auth_step_backup_code(backup_code.trim()).await
} }
async fn do_totp(&self, client: &mut KanidmAsyncClient) -> Result<AuthResponse, ClientError> { async fn do_totp(&self, client: &mut KanidmClient) -> Result<AuthResponse, ClientError> {
let totp = loop { let totp = loop {
print!("Enter TOTP: "); print!("Enter TOTP: ");
// We flush stdout so it'll write the buffer to screen, continuing operation. Without it, the application halts. // We flush stdout so it'll write the buffer to screen, continuing operation. Without it, the application halts.
@ -198,7 +192,7 @@ impl LoginOpt {
async fn do_webauthn( async fn do_webauthn(
&self, &self,
client: &mut KanidmAsyncClient, client: &mut KanidmClient,
pkr: RequestChallengeResponse, pkr: RequestChallengeResponse,
) -> Result<AuthResponse, ClientError> { ) -> Result<AuthResponse, ClientError> {
let mut wa = WebauthnAuthenticator::new(U2FHid::new()); let mut wa = WebauthnAuthenticator::new(U2FHid::new());

View file

@ -58,7 +58,7 @@ async fn main() {
None => client_builder, None => client_builder,
}; };
let client = client_builder.build_async().unwrap_or_else(|e| { let client = client_builder.build().unwrap_or_else(|e| {
error!("Failed to build client instance -- {:?}", e); error!("Failed to build client instance -- {:?}", e);
std::process::exit(1); std::process::exit(1);
}); });

View file

@ -1,8 +1,8 @@
use crate::db::Db; use crate::db::Db;
use crate::unix_config::{HomeAttr, UidAttr}; use crate::unix_config::{HomeAttr, UidAttr};
use crate::unix_proto::{HomeDirectoryInfo, NssGroup, NssUser}; use crate::unix_proto::{HomeDirectoryInfo, NssGroup, NssUser};
use kanidm_client::asynchronous::KanidmAsyncClient;
use kanidm_client::ClientError; use kanidm_client::ClientError;
use kanidm_client::KanidmClient;
use kanidm_proto::v1::{OperationError, UnixGroupToken, UnixUserToken}; use kanidm_proto::v1::{OperationError, UnixGroupToken, UnixUserToken};
use lru::LruCache; use lru::LruCache;
use reqwest::StatusCode; use reqwest::StatusCode;
@ -31,7 +31,7 @@ enum CacheState {
#[derive(Debug)] #[derive(Debug)]
pub struct CacheLayer { pub struct CacheLayer {
db: Db, db: Db,
client: RwLock<KanidmAsyncClient>, client: RwLock<KanidmClient>,
state: Mutex<CacheState>, state: Mutex<CacheState>,
pam_allow_groups: BTreeSet<String>, pam_allow_groups: BTreeSet<String>,
timeout_seconds: u64, timeout_seconds: u64,
@ -62,7 +62,7 @@ impl CacheLayer {
// cache timeout // cache timeout
timeout_seconds: u64, timeout_seconds: u64,
// //
client: KanidmAsyncClient, client: KanidmClient,
pam_allow_groups: Vec<String>, pam_allow_groups: Vec<String>,
default_shell: String, default_shell: String,
home_prefix: String, home_prefix: String,

View file

@ -480,7 +480,7 @@ async fn main() {
let cb = cb.connect_timeout(cfg.conn_timeout); let cb = cb.connect_timeout(cfg.conn_timeout);
let rsclient = match cb.build_async() { let rsclient = match cb.build() {
Ok(rsc) => rsc, Ok(rsc) => rsc,
Err(_e) => { Err(_e) => {
error!("Failed to build async client"); error!("Failed to build async client");

View file

@ -14,7 +14,7 @@ use kanidm_unix_common::constants::{
DEFAULT_SHELL, DEFAULT_UID_ATTR_MAP, DEFAULT_SHELL, DEFAULT_UID_ATTR_MAP,
}; };
use kanidm_client::{KanidmAsyncClient, KanidmClientBuilder}; use kanidm_client::{KanidmClient, KanidmClientBuilder};
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
@ -36,16 +36,16 @@ fn is_free_port(port: u16) -> bool {
} }
} }
type Fixture = Box<dyn FnOnce(KanidmAsyncClient) -> Pin<Box<dyn Future<Output = ()>>>>; type Fixture = Box<dyn FnOnce(KanidmClient) -> Pin<Box<dyn Future<Output = ()>>>>;
fn fixture<T>(f: fn(KanidmAsyncClient) -> T) -> Fixture fn fixture<T>(f: fn(KanidmClient) -> T) -> Fixture
where where
T: Future<Output = ()> + 'static, T: Future<Output = ()> + 'static,
{ {
Box::new(move |n| Box::pin(f(n))) Box::new(move |n| Box::pin(f(n)))
} }
async fn setup_test(fix_fn: Fixture) -> (CacheLayer, KanidmAsyncClient) { async fn setup_test(fix_fn: Fixture) -> (CacheLayer, KanidmClient) {
let _ = tracing_tree::test_init(); let _ = tracing_tree::test_init();
let mut counter = 0; let mut counter = 0;
@ -89,7 +89,7 @@ async fn setup_test(fix_fn: Fixture) -> (CacheLayer, KanidmAsyncClient) {
let adminclient = KanidmClientBuilder::new() let adminclient = KanidmClientBuilder::new()
.address(addr.clone()) .address(addr.clone())
.no_proxy() .no_proxy()
.build_async() .build()
.expect("Failed to build sync client"); .expect("Failed to build sync client");
fix_fn(adminclient).await; fix_fn(adminclient).await;
@ -97,13 +97,13 @@ async fn setup_test(fix_fn: Fixture) -> (CacheLayer, KanidmAsyncClient) {
let client = KanidmClientBuilder::new() let client = KanidmClientBuilder::new()
.address(addr.clone()) .address(addr.clone())
.no_proxy() .no_proxy()
.build_async() .build()
.expect("Failed to build async admin client"); .expect("Failed to build async admin client");
let rsclient = KanidmClientBuilder::new() let rsclient = KanidmClientBuilder::new()
.address(addr) .address(addr)
.no_proxy() .no_proxy()
.build_async() .build()
.expect("Failed to build client"); .expect("Failed to build client");
let cachelayer = CacheLayer::new( let cachelayer = CacheLayer::new(
@ -127,7 +127,7 @@ async fn setup_test(fix_fn: Fixture) -> (CacheLayer, KanidmAsyncClient) {
// let the tables hit the floor // let the tables hit the floor
} }
async fn test_fixture(rsclient: KanidmAsyncClient) { async fn test_fixture(rsclient: KanidmClient) {
let res = rsclient let res = rsclient
.auth_simple_password("admin", ADMIN_TEST_PASSWORD) .auth_simple_password("admin", ADMIN_TEST_PASSWORD)
.await; .await;

View file

@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicU16, Ordering};
use kanidm::audit::LogLevel; use kanidm::audit::LogLevel;
use kanidm::config::{Configuration, IntegrationTestConfig, ServerRole}; use kanidm::config::{Configuration, IntegrationTestConfig, ServerRole};
use kanidm::tracing_tree; use kanidm::tracing_tree;
use kanidm_client::{asynchronous::KanidmAsyncClient, KanidmClientBuilder}; use kanidm_client::{KanidmClient, KanidmClientBuilder};
use score::create_server_core; use score::create_server_core;
use tokio::task; use tokio::task;
@ -21,7 +21,7 @@ fn is_free_port(port: u16) -> bool {
} }
// Test external behaviours of the service. // Test external behaviours of the service.
pub async fn setup_async_test() -> KanidmAsyncClient { pub async fn setup_async_test() -> KanidmClient {
let _ = tracing_tree::test_init(); let _ = tracing_tree::test_init();
let mut counter = 0; let mut counter = 0;
@ -63,7 +63,7 @@ pub async fn setup_async_test() -> KanidmAsyncClient {
let rsclient = KanidmClientBuilder::new() let rsclient = KanidmClientBuilder::new()
.address(addr) .address(addr)
.no_proxy() .no_proxy()
.build_async() .build()
.expect("Failed to build client"); .expect("Failed to build client");
rsclient rsclient

View file

@ -1,7 +1,7 @@
#![deny(warnings)] #![deny(warnings)]
use std::collections::HashSet; use std::collections::HashSet;
use kanidm_client::asynchronous::KanidmAsyncClient; use kanidm_client::KanidmClient;
use kanidm_proto::v1::{Filter, Modify, ModifyList}; use kanidm_proto::v1::{Filter, Modify, ModifyList};
mod common; mod common;
@ -56,7 +56,7 @@ static DEFAULT_HP_GROUP_NAMES: [&str; 24] = [
static DEFAULT_NOT_HP_GROUP_NAMES: [&str; 2] = static DEFAULT_NOT_HP_GROUP_NAMES: [&str; 2] =
["idm_account_unix_extend_priv", "idm_group_unix_extend_priv"]; ["idm_account_unix_extend_priv", "idm_group_unix_extend_priv"];
async fn create_user(rsclient: &KanidmAsyncClient, id: &str, group_name: &str) -> () { async fn create_user(rsclient: &KanidmClient, id: &str, group_name: &str) -> () {
rsclient.idm_account_create(id, id).await.unwrap(); rsclient.idm_account_create(id, id).await.unwrap();
// Create group and add to user to test read attr: member_of // Create group and add to user to test read attr: member_of
@ -70,7 +70,7 @@ async fn create_user(rsclient: &KanidmAsyncClient, id: &str, group_name: &str) -
.unwrap(); .unwrap();
} }
async fn is_attr_writable(rsclient: &KanidmAsyncClient, id: &str, attr: &str) -> Option<bool> { async fn is_attr_writable(rsclient: &KanidmClient, id: &str, attr: &str) -> Option<bool> {
println!("writing to attribute: {}", attr); println!("writing to attribute: {}", attr);
match attr { match attr {
"radius_secret" => Some( "radius_secret" => Some(
@ -130,7 +130,7 @@ async fn is_attr_writable(rsclient: &KanidmAsyncClient, id: &str, attr: &str) ->
} }
} }
async fn add_all_attrs(rsclient: &KanidmAsyncClient, id: &str, group_name: &str) { async fn add_all_attrs(rsclient: &KanidmClient, id: &str, group_name: &str) {
// Extend with posix attrs to test read attr: gidnumber and loginshell // Extend with posix attrs to test read attr: gidnumber and loginshell
rsclient rsclient
.idm_group_add_members("idm_admins", &[ADMIN_TEST_USER]) .idm_group_add_members("idm_admins", &[ADMIN_TEST_USER])
@ -170,7 +170,7 @@ async fn add_all_attrs(rsclient: &KanidmAsyncClient, id: &str, group_name: &str)
} }
async fn create_user_with_all_attrs( async fn create_user_with_all_attrs(
rsclient: &KanidmAsyncClient, rsclient: &KanidmClient,
id: &str, id: &str,
optional_group: Option<&str>, optional_group: Option<&str>,
) -> () { ) -> () {
@ -181,7 +181,7 @@ async fn create_user_with_all_attrs(
add_all_attrs(&rsclient, id, group_name).await; add_all_attrs(&rsclient, id, group_name).await;
} }
async fn login_account(rsclient: &KanidmAsyncClient, id: &str) -> () { async fn login_account(rsclient: &KanidmClient, id: &str) -> () {
rsclient rsclient
.idm_group_add_members( .idm_group_add_members(
"idm_people_account_password_import_priv", "idm_people_account_password_import_priv",
@ -210,7 +210,7 @@ async fn login_account(rsclient: &KanidmAsyncClient, id: &str) -> () {
// Login to the given account, but first login with default admin credentials. // Login to the given account, but first login with default admin credentials.
// This is necessary when switching between unprivileged accounts, but adds extra calls which // This is necessary when switching between unprivileged accounts, but adds extra calls which
// create extra debugging noise, so should be avoided when unnecessary. // create extra debugging noise, so should be avoided when unnecessary.
async fn login_account_via_admin(rsclient: &KanidmAsyncClient, id: &str) -> () { async fn login_account_via_admin(rsclient: &KanidmClient, id: &str) -> () {
let _ = rsclient.logout(); let _ = rsclient.logout();
rsclient rsclient
.auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD) .auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
@ -220,7 +220,7 @@ async fn login_account_via_admin(rsclient: &KanidmAsyncClient, id: &str) -> () {
} }
async fn test_read_attrs( async fn test_read_attrs(
rsclient: &KanidmAsyncClient, rsclient: &KanidmClient,
id: &str, id: &str,
attrs: &[&str], attrs: &[&str],
is_readable: bool, is_readable: bool,
@ -247,7 +247,7 @@ async fn test_read_attrs(
} }
async fn test_write_attrs( async fn test_write_attrs(
rsclient: &KanidmAsyncClient, rsclient: &KanidmClient,
id: &str, id: &str,
attrs: &[&str], attrs: &[&str],
is_writeable: bool, is_writeable: bool,
@ -261,7 +261,7 @@ async fn test_write_attrs(
} }
async fn test_modify_group( async fn test_modify_group(
rsclient: &KanidmAsyncClient, rsclient: &KanidmClient,
group_names: &[&str], group_names: &[&str],
is_modificable: bool, is_modificable: bool,
) -> () { ) -> () {

View file

@ -2,9 +2,7 @@ use crate::data::*;
use crate::ldap::{LdapClient, LdapSchema}; use crate::ldap::{LdapClient, LdapSchema};
use crate::profile::{KaniHttpConfig, KaniLdapConfig}; use crate::profile::{KaniHttpConfig, KaniLdapConfig};
use crate::{TargetServer, TargetServerBuilder}; use crate::{TargetServer, TargetServerBuilder};
use kanidm_client::{ use kanidm_client::{ClientError, KanidmClient, KanidmClientBuilder, StatusCode};
asynchronous::KanidmAsyncClient, ClientError, KanidmClientBuilder, StatusCode,
};
use kanidm_proto::v1::*; use kanidm_proto::v1::*;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -14,7 +12,7 @@ use uuid::Uuid;
pub struct KaniHttpServer { pub struct KaniHttpServer {
uri: String, uri: String,
admin_pw: String, admin_pw: String,
client: KanidmAsyncClient, client: KanidmClient,
} }
#[derive(Debug)] #[derive(Debug)]
@ -29,7 +27,7 @@ impl KaniHttpServer {
.address(uri.clone()) .address(uri.clone())
.danger_accept_invalid_hostnames(true) .danger_accept_invalid_hostnames(true)
.danger_accept_invalid_certs(true) .danger_accept_invalid_certs(true)
.build_async() .build()
.map_err(|e| { .map_err(|e| {
error!("Unable to create kanidm client {:?}", e); error!("Unable to create kanidm client {:?}", e);
})?; })?;