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