Create api keys

This commit is contained in:
ManyTheFish 2023-08-02 16:52:45 +02:00
parent 49f976c8d8
commit 3eb6f4b56f
3 changed files with 51 additions and 33 deletions

View file

@ -137,7 +137,7 @@ enum OnFailure {
KeepDb,
}
pub fn setup_meilisearch(
pub async fn setup_meilisearch(
opt: &Opt,
zk: Option<zk::Client>,
) -> anyhow::Result<(Arc<IndexScheduler>, Arc<AuthController>)> {
@ -147,7 +147,7 @@ pub fn setup_meilisearch(
// the db is empty and the snapshot exists, import it
if empty_db && snapshot_path_exists {
match compression::from_tar_gz(snapshot_path, &opt.db_path) {
Ok(()) => open_or_create_database_unchecked(opt, OnFailure::RemoveDb, zk)?,
Ok(()) => open_or_create_database_unchecked(opt, OnFailure::RemoveDb, zk).await?,
Err(e) => {
std::fs::remove_dir_all(&opt.db_path)?;
return Err(e);
@ -164,14 +164,14 @@ pub fn setup_meilisearch(
bail!("snapshot doesn't exist at {}", snapshot_path.display())
// the snapshot and the db exist, and we can ignore the snapshot because of the ignore_snapshot_if_db_exists flag
} else {
open_or_create_database(opt, empty_db, zk)?
open_or_create_database(opt, empty_db, zk).await?
}
} else if let Some(ref path) = opt.import_dump {
let src_path_exists = path.exists();
// the db is empty and the dump exists, import it
if empty_db && src_path_exists {
let (mut index_scheduler, mut auth_controller) =
open_or_create_database_unchecked(opt, OnFailure::RemoveDb, zk)?;
open_or_create_database_unchecked(opt, OnFailure::RemoveDb, zk).await?;
match import_dump(&opt.db_path, path, &mut index_scheduler, &mut auth_controller) {
Ok(()) => (index_scheduler, auth_controller),
Err(e) => {
@ -191,10 +191,10 @@ pub fn setup_meilisearch(
// the dump and the db exist and we can ignore the dump because of the ignore_dump_if_db_exists flag
// or, the dump is missing but we can ignore that because of the ignore_missing_dump flag
} else {
open_or_create_database(opt, empty_db, zk)?
open_or_create_database(opt, empty_db, zk).await?
}
} else {
open_or_create_database(opt, empty_db, zk)?
open_or_create_database(opt, empty_db, zk).await?
};
// We create a loop in a thread that registers snapshotCreation tasks
@ -218,7 +218,7 @@ pub fn setup_meilisearch(
}
/// Try to start the IndexScheduler and AuthController without checking the VERSION file or anything.
fn open_or_create_database_unchecked(
async fn open_or_create_database_unchecked(
opt: &Opt,
on_failure: OnFailure,
zk: Option<zk::Client>,
@ -250,7 +250,7 @@ fn open_or_create_database_unchecked(
match (
index_scheduler_builder(),
auth_controller.map_err(anyhow::Error::from),
auth_controller.await.map_err(anyhow::Error::from),
create_version_file(&opt.db_path).map_err(anyhow::Error::from),
) {
(Ok(i), Ok(a), Ok(())) => Ok((i, a)),
@ -264,7 +264,7 @@ fn open_or_create_database_unchecked(
}
/// Ensure you're in a valid state and open the IndexScheduler + AuthController for you.
fn open_or_create_database(
async fn open_or_create_database(
opt: &Opt,
empty_db: bool,
zk: Option<zk::Client>,
@ -273,7 +273,7 @@ fn open_or_create_database(
check_version_file(&opt.db_path)?;
}
open_or_create_database_unchecked(opt, OnFailure::KeepDb, zk)
open_or_create_database_unchecked(opt, OnFailure::KeepDb, zk).await
}
fn import_dump(

View file

@ -68,7 +68,7 @@ async fn main() -> anyhow::Result<()> {
Some(ref url) => Some(zk::Client::connect(url).await.unwrap()),
None => None,
};
let (index_scheduler, auth_controller) = setup_meilisearch(&opt, zk)?;
let (index_scheduler, auth_controller) = setup_meilisearch(&opt, zk).await?;
#[cfg(all(not(debug_assertions), feature = "analytics"))]
let analytics = if !opt.no_analytics {