JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Unified stack `GetValue` implementation

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨325f5af

⁨giterated-daemon/src/keys.rs⁩ - ⁨687⁩ bytes
Raw
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))
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