diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-09-05 18:01:03 +0200 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-09-05 18:04:29 +0200 |
commit | 14e0b7d4ef1bbae9290e86f14c58a08b746270f2 (patch) | |
tree | daa9fd486441b869969df92880117659b3b2730b /src/auth.rs | |
parent | Merge pull request 'don't accept cannot-be-a-base urls in parsing' (#123) fro... (diff) | |
download | forgejo-cli-14e0b7d4ef1bbae9290e86f14c58a08b746270f2.tar.xz forgejo-cli-14e0b7d4ef1bbae9290e86f14c58a08b746270f2.zip |
fix: consistency among host names
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/auth.rs b/src/auth.rs index c0bd467..40dedd5 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -13,8 +13,6 @@ pub enum AuthCommand { /// /// Use this if `fj auth login` doesn't work AddKey { - /// The domain name of the forgejo instance. - host: String, /// The user that the key is associated with user: String, /// The key to add. If not present, the key will be read in from stdin. @@ -53,21 +51,24 @@ impl AuthCommand { eprintln!("already not signed in to {host}"); } } - AuthCommand::AddKey { host, user, key } => { + AuthCommand::AddKey { user, key } => { + let repo_info = crate::repo::RepoInfo::get_current(host_name, None, None)?; + let host_url = repo_info.host_url(); let key = match key { Some(key) => key, None => crate::readline("new key: ").await?.trim().to_string(), }; - if !keys.hosts.contains_key(&user) { + let host = crate::host_with_port(&host_url); + if !keys.hosts.contains_key(host) { keys.hosts.insert( - host, + host.to_owned(), crate::keys::LoginInfo::Application { name: user, token: key, }, ); } else { - println!("key for {} already exists", host); + println!("key for {host} already exists"); } } AuthCommand::List => { @@ -84,7 +85,7 @@ impl AuthCommand { } pub fn get_client_info_for(url: &url::Url) -> Option<(&'static str, &'static str)> { - let client_info = match (url.host_str()?, url.path()) { + let client_info = match (crate::host_with_port(url), url.path()) { ("codeberg.org", "/") => option_env!("CLIENT_INFO_CODEBERG"), _ => None, }; @@ -173,8 +174,8 @@ async fn oauth_login( refresh_token: response.refresh_token, expires_at, }; - keys.hosts - .insert(host.host_str().unwrap().to_string(), login_info); + let domain = crate::host_with_port(&host); + keys.hosts.insert(domain.to_owned(), login_info); Ok(()) } |