This commit is contained in:
Tamo 2023-08-03 13:59:05 +02:00
parent d5523cc6ac
commit 5ce01bcb53

View File

@ -46,6 +46,8 @@ impl AuthController {
Ok(_) => generate_default_keys(&controller).await?, Ok(_) => generate_default_keys(&controller).await?,
// If the node exist we should clear our DB and download all the existing api-keys // If the node exist we should clear our DB and download all the existing api-keys
Err(zk::Error::NodeExists) => { Err(zk::Error::NodeExists) => {
log::warn!("Auth directory already exists, we need to clear our keys + import the one in zookeeper");
let store = controller.store.clone(); let store = controller.store.clone();
tokio::task::spawn_blocking(move || store.delete_all_keys()).await??; tokio::task::spawn_blocking(move || store.delete_all_keys()).await??;
let children = zk let children = zk
@ -99,12 +101,14 @@ impl AuthController {
// TODO: ugly unwraps // TODO: ugly unwraps
let uuid = path.strip_prefix("/auth/").unwrap(); let uuid = path.strip_prefix("/auth/").unwrap();
let uuid = Uuid::parse_str(&uuid).unwrap(); let uuid = Uuid::parse_str(&uuid).unwrap();
log::info!("The key {} has been deleted", uuid);
dbg!(controller_clone.store.delete_api_key(uuid).unwrap()); dbg!(controller_clone.store.delete_api_key(uuid).unwrap());
} }
zk::EventType::NodeCreated | zk::EventType::NodeDataChanged => { zk::EventType::NodeCreated | zk::EventType::NodeDataChanged => {
let (key, stat) = zk.get_data(&path).await.unwrap(); let (key, stat) = zk.get_data(&path).await.unwrap();
dbg!(stat); let key: Key = serde_json::from_slice(&key).unwrap();
let key = serde_json::from_slice(&key).unwrap(); log::info!("The key {} has been deleted", key.uid);
dbg!(controller_clone.store.put_api_key(key).unwrap()); dbg!(controller_clone.store.put_api_key(key).unwrap());
} }
zk::EventType::NodeChildrenChanged => panic!("Got the unexpected NodeChildrenChanged event, what is it used for?"), zk::EventType::NodeChildrenChanged => panic!("Got the unexpected NodeChildrenChanged event, what is it used for?"),