From 173ab188b326fbe78cfba4ab455a74619f4556bb Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 24 Jun 2024 09:39:18 +0100 Subject: feat(login): store in git config and use cache replace ngit yaml file config with: * nsec / ncryptsec / npub in git config in nostr.* namespace * sql database cache for metadata and relay events allow different logins to be used for different git repositories by storing login in local git config --- src/sub_commands/init.rs | 9 ++++++++- src/sub_commands/login.rs | 9 +++++---- src/sub_commands/push.rs | 9 ++++++++- src/sub_commands/send.rs | 9 ++++++++- 4 files changed, 29 insertions(+), 7 deletions(-) (limited to 'src/sub_commands') diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index edaca15..4d1bdfb 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -59,7 +59,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { #[cfg(test)] let mut client = ::default(); - let (keys, user_ref) = login::launch(&cli_args.nsec, &cli_args.password, Some(&client)).await?; + let (keys, user_ref) = login::launch( + &git_repo, + &cli_args.nsec, + &cli_args.password, + Some(&client), + false, + ) + .await?; client.set_keys(&keys).await; diff --git a/src/sub_commands/login.rs b/src/sub_commands/login.rs index 43ce480..e71d431 100644 --- a/src/sub_commands/login.rs +++ b/src/sub_commands/login.rs @@ -1,11 +1,11 @@ -use anyhow::Result; +use anyhow::{Context, Result}; use clap; #[cfg(not(test))] use crate::client::Client; #[cfg(test)] use crate::client::MockConnect; -use crate::{client::Connect, login, Cli}; +use crate::{client::Connect, git::Repo, login, Cli}; #[derive(clap::Args)] pub struct SubCommandArgs { @@ -15,8 +15,9 @@ pub struct SubCommandArgs { } pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { + let git_repo = Repo::discover().context("cannot find a git repository")?; if command_args.offline { - login::launch(&args.nsec, &args.password, None).await?; + login::launch(&git_repo, &args.nsec, &args.password, None, true).await?; Ok(()) } else { #[cfg(not(test))] @@ -24,7 +25,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { #[cfg(test)] let client = ::default(); - login::launch(&args.nsec, &args.password, Some(&client)).await?; + login::launch(&git_repo, &args.nsec, &args.password, Some(&client), true).await?; client.disconnect().await?; Ok(()) } diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index fefe102..ade2ff8 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs @@ -148,7 +148,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { ahead.len() ); - let (keys, user_ref) = login::launch(&cli_args.nsec, &cli_args.password, Some(&client)).await?; + let (keys, user_ref) = login::launch( + &git_repo, + &cli_args.nsec, + &cli_args.password, + Some(&client), + false, + ) + .await?; client.set_keys(&keys).await; diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index c8d900c..8971d8b 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -178,7 +178,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { } else { None }; - let (keys, user_ref) = login::launch(&cli_args.nsec, &cli_args.password, Some(&client)).await?; + let (keys, user_ref) = login::launch( + &git_repo, + &cli_args.nsec, + &cli_args.password, + Some(&client), + false, + ) + .await?; client.set_keys(&keys).await; -- cgit v1.2.3