summaryrefslogtreecommitdiffstats
path: root/src/keys.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/keys.rs')
-rw-r--r--src/keys.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/keys.rs b/src/keys.rs
index 58fc57d..e5fd6c5 100644
--- a/src/keys.rs
+++ b/src/keys.rs
@@ -6,6 +6,8 @@ use url::Url;
#[derive(serde::Serialize, serde::Deserialize, Clone, Default)]
pub struct KeyInfo {
pub hosts: BTreeMap<String, LoginInfo>,
+ #[serde(default)]
+ pub aliases: BTreeMap<String, String>,
}
impl KeyInfo {
@@ -54,6 +56,21 @@ impl KeyInfo {
pub async fn get_api(&mut self, url: &Url) -> eyre::Result<forgejo_api::Forgejo> {
self.get_login(url)?.api_for(url).await.map_err(Into::into)
}
+
+ pub fn deref_alias(&self, url: url::Url) -> url::Url {
+ match self.aliases.get(crate::host_with_port(&url)) {
+ Some(replacement) => {
+ let s = format!(
+ "{}{}{}",
+ &url[..url::Position::BeforeHost],
+ replacement,
+ &url[url::Position::AfterPort..]
+ );
+ url::Url::parse(&s).unwrap()
+ }
+ None => url,
+ }
+ }
}
#[derive(serde::Serialize, serde::Deserialize, Clone)]