diff options
Diffstat (limited to 'src/lib/login/existing.rs')
| -rw-r--r-- | src/lib/login/existing.rs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs index e60621d..2e45ca4 100644 --- a/src/lib/login/existing.rs +++ b/src/lib/login/existing.rs | |||
| @@ -18,7 +18,7 @@ use crate::client::MockConnect; | |||
| 18 | use crate::{ | 18 | use crate::{ |
| 19 | cli_interactor::{Interactor, InteractorPrompt, PromptPasswordParms}, | 19 | cli_interactor::{Interactor, InteractorPrompt, PromptPasswordParms}, |
| 20 | client::fetch_public_key, | 20 | client::fetch_public_key, |
| 21 | git::{Repo, RepoActions, get_git_config_item}, | 21 | git::{Repo, RepoActions, get_git_config_item, get_git_config_item_system}, |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | /// load signer from git config and UserProfile from cache or relays | 24 | /// load signer from git config and UserProfile from cache or relays |
| @@ -62,7 +62,8 @@ pub async fn load_existing_login( | |||
| 62 | Ok((signer, user_ref, source)) | 62 | Ok((signer, user_ref, source)) |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// priority order: cli arguments, local git config, global git config | 65 | /// priority order: cli arguments, local git config, global git config, system |
| 66 | /// git config | ||
| 66 | pub fn get_signer_info( | 67 | pub fn get_signer_info( |
| 67 | git_repo: &Option<&Repo>, | 68 | git_repo: &Option<&Repo>, |
| 68 | signer_info: &Option<SignerInfo>, | 69 | signer_info: &Option<SignerInfo>, |
| @@ -82,6 +83,7 @@ pub fn get_signer_info( | |||
| 82 | SignerInfoSource::CommandLineArguments, | 83 | SignerInfoSource::CommandLineArguments, |
| 83 | SignerInfoSource::GitLocal, | 84 | SignerInfoSource::GitLocal, |
| 84 | SignerInfoSource::GitGlobal, | 85 | SignerInfoSource::GitGlobal, |
| 86 | SignerInfoSource::GitSystem, | ||
| 85 | ] | 87 | ] |
| 86 | } { | 88 | } { |
| 87 | if let Ok(res) = | 89 | if let Ok(res) = |
| @@ -91,7 +93,7 @@ pub fn get_signer_info( | |||
| 91 | break; | 93 | break; |
| 92 | } | 94 | } |
| 93 | } | 95 | } |
| 94 | result.context("failed to get or find signer info in cli arguments, local git config or global git config")? | 96 | result.context("failed to get or find signer info in cli arguments, local git config, global git config or system git config")? |
| 95 | } | 97 | } |
| 96 | Some(SignerInfoSource::CommandLineArguments) => { | 98 | Some(SignerInfoSource::CommandLineArguments) => { |
| 97 | if let Some(signer_info) = signer_info { | 99 | if let Some(signer_info) = signer_info { |
| @@ -158,6 +160,33 @@ pub fn get_signer_info( | |||
| 158 | bail!("no signer info in global git config") | 160 | bail!("no signer info in global git config") |
| 159 | } | 161 | } |
| 160 | } | 162 | } |
| 163 | Some(SignerInfoSource::GitSystem) => { | ||
| 164 | if let Some(nsec) = get_git_config_item_system("nostr.nsec") | ||
| 165 | .context("failed to get system git config")? | ||
| 166 | { | ||
| 167 | ( | ||
| 168 | SignerInfo::Nsec { | ||
| 169 | nsec: nsec.to_string(), | ||
| 170 | password: password.clone(), | ||
| 171 | npub: get_git_config_item_system("nostr.npub") | ||
| 172 | .context("failed to get system git config")?, | ||
| 173 | }, | ||
| 174 | SignerInfoSource::GitSystem, | ||
| 175 | ) | ||
| 176 | } else if let Some(bunker_uri) = get_git_config_item_system("nostr.bunker-uri") | ||
| 177 | .context("failed to get system git config")? | ||
| 178 | { | ||
| 179 | (SignerInfo::Bunker { | ||
| 180 | bunker_uri, bunker_app_key: get_git_config_item_system("nostr.bunker-app-key") | ||
| 181 | .context("failed to get system git config")? | ||
| 182 | .context("system git config item nostr.bunker-uri exists but nostr.bunker-app-key doesn't")?, | ||
| 183 | npub: get_git_config_item_system("nostr.npub") | ||
| 184 | .context("failed to get system git config")?, | ||
| 185 | }, SignerInfoSource::GitSystem) | ||
| 186 | } else { | ||
| 187 | bail!("no signer info in system git config") | ||
| 188 | } | ||
| 189 | } | ||
| 161 | }) | 190 | }) |
| 162 | } | 191 | } |
| 163 | 192 | ||