cli: Improve `rad-auth` first authentication

This commit is contained in:
Alexis Sellier 2023-02-28 09:30:53 +01:00
parent e4b44370d3
commit 892f02bc43
No known key found for this signature in database
8 changed files with 20 additions and 16 deletions

View File

@ -4,9 +4,9 @@ The example below is run with `RAD_PASSPHRASE` set.
```
$ rad auth
Initializing your 🌱 profile and identity
Initializing your radicle 🌱 identity
✓ Creating your 🌱 Ed25519 keypair...
✓ Creating your Ed25519 keypair...
! Adding your radicle key to ssh-agent...
✓ Your Radicle ID is did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi. This identifies your device.

View File

@ -66,7 +66,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
}
pub fn init(options: Options) -> anyhow::Result<()> {
term::headline("Initializing your 🌱 profile and identity");
term::headline(format!(
"Initializing your {} 🌱 identity",
term::format::highlight("radicle")
));
if let Ok(version) = radicle::git::version() {
if version < radicle::git::VERSION_REQUIRED {
@ -84,9 +87,9 @@ pub fn init(options: Options) -> anyhow::Result<()> {
let passphrase = if options.stdin {
term::passphrase_stdin()
} else {
term::passphrase_confirm()
term::passphrase_confirm("Enter a passphrase:")
}?;
let spinner = term::spinner("Creating your 🌱 Ed25519 keypair...");
let spinner = term::spinner("Creating your Ed25519 keypair...");
let profile = Profile::init(home, passphrase.clone())?;
spinner.finish();
@ -115,7 +118,7 @@ pub fn authenticate(profile: &Profile, options: Options) -> anyhow::Result<()> {
let agent = ssh::agent::Agent::connect()?;
// TODO: Only show this if we're not authenticated.
term::headline(&format!(
term::headline(format!(
"🌱 Authenticating as {}",
term::format::Identity::new(profile).styled()
));

View File

@ -80,7 +80,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let profile = ctx.profile()?;
let path = execute(options, &profile)?;
term::headline(&format!(
term::headline(format!(
"🌱 Project checkout successful under ./{}",
term::format::highlight(path.file_name().unwrap_or_default().to_string_lossy())
));
@ -105,7 +105,7 @@ pub fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
anyhow::bail!("the local path {:?} already exists", path.as_path());
}
term::headline(&format!(
term::headline(format!(
"Initializing local checkout for 🌱 {} ({})",
term::format::highlight(options.id),
payload.name(),

View File

@ -128,7 +128,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
&delegates,
)?;
term::headline(&format!(
term::headline(format!(
"🌱 Project successfully cloned under {}",
term::format::highlight(Path::new(".").join(path).display())
));

View File

@ -159,7 +159,7 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
let path = path.as_path().canonicalize()?;
let interactive = options.interactive;
term::headline(&format!(
term::headline(format!(
"Initializing local 🌱 project in {}",
if path == cwd {
term::format::highlight(".").to_string()
@ -286,7 +286,7 @@ pub fn setup_signing(
.ok_or(anyhow!("cannot setup signing in bare repository"))?;
let key = ssh::fmt::fingerprint(node_id);
let yes = if !git::is_signing_configured(repo)? {
term::headline(&format!(
term::headline(format!(
"Configuring 🌱 signing key {}...",
term::format::tertiary(key)
));

View File

@ -101,7 +101,7 @@ pub fn run(
))?;
let head_branch = try_branch(workdir.head()?)?;
term::headline(&format!(
term::headline(format!(
"🌱 Creating patch for {}",
term::format::highlight(project.name())
));

View File

@ -95,7 +95,7 @@ pub fn run(
// `HEAD`; This is what we are proposing as a patch.
let head_branch = try_branch(workdir.head()?)?;
term::headline(&format!(
term::headline(format!(
"🌱 Updating patch for {}",
term::format::highlight(project.name())
));

View File

@ -72,7 +72,7 @@ pub fn columns() -> Option<usize> {
termion::terminal_size().map(|(cols, _)| cols as usize).ok()
}
pub fn headline(headline: &str) {
pub fn headline(headline: impl fmt::Display) {
println!();
println!("{}", style(headline).bold());
println!();
@ -214,16 +214,17 @@ pub fn passphrase() -> Result<Passphrase, anyhow::Error> {
}
}
pub fn passphrase_confirm() -> Result<Passphrase, anyhow::Error> {
pub fn passphrase_confirm(prompt: &str) -> Result<Passphrase, anyhow::Error> {
if let Some(p) = profile::env::passphrase() {
Ok(p)
} else {
Ok(Passphrase::from(
Password::new("Passphrase:")
Password::new(prompt)
.with_render_config(*CONFIG)
.with_display_mode(inquire::PasswordDisplayMode::Masked)
.with_custom_confirmation_message("Repeat passphrase:")
.with_custom_confirmation_error_message("The passphrases don't match.")
.with_help_message("This passphrase protects your radicle identity")
.prompt()?,
))
}