1 |
use anyhow::Error;
|
2 |
|
3 |
use giterated_models::instance::Instance;
|
4 |
|
5 |
use std::collections::HashMap;
|
6 |
|
7 |
#[derive(Default)]
|
8 |
pub struct PublicKeyCache {
|
9 |
pub keys: HashMap<Instance, String>,
|
10 |
}
|
11 |
|
12 |
impl PublicKeyCache {
|
13 |
pub async fn get(&mut self, instance: &Instance) -> Result<String, Error> {
|
14 |
if let Some(key) = self.keys.get(instance) {
|
15 |
return Ok(key.clone());
|
16 |
} else {
|
17 |
let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance.url))
|
18 |
.await?
|
19 |
.text()
|
20 |
.await?;
|
21 |
|
22 |
self.keys.insert(instance.clone(), key);
|
23 |
|
24 |
Ok(self.keys.get(instance).unwrap().clone())
|
25 |
}
|
26 |
}
|
27 |
}
|
28 |
|