Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Make `Profile::init` more flexible
Alexis Sellier committed 3 years ago
commit fd936becf18e8245f1acc6e98ec3507838650746
parent 66d1f99a1eada49d1b043aab7b9535af193a34a3
3 files changed +7 -6
modified radicle-cli/src/commands/auth.rs
@@ -4,6 +4,7 @@ use std::ffi::OsString;
use anyhow::anyhow;

use radicle::crypto::ssh;
+
use radicle::profile;
use radicle::Profile;

use crate::git;
@@ -76,9 +77,10 @@ pub fn init(options: Options) -> anyhow::Result<()> {
        term::blank();
    }

+
    let home = profile::home()?;
    let passphrase = term::read_passphrase(options.stdin, true)?;
    let spinner = term::spinner("Creating your 🌱 Ed25519 keypair...");
-
    let profile = Profile::init(passphrase.as_str())?;
+
    let profile = Profile::init(home, passphrase.as_str())?;
    spinner.finish();

    term::success!(
modified radicle-tools/src/rad-auth.rs
@@ -1,9 +1,10 @@
+
use radicle::profile;
use radicle::profile::{Error, Profile};

fn main() -> anyhow::Result<()> {
    let profile = match Profile::load() {
        Ok(profile) => profile,
-
        Err(Error::NotFound(_)) => Profile::init("radicle")?,
+
        Err(Error::NotFound(_)) => Profile::init(profile::home()?, "radicle")?,
        Err(err) => anyhow::bail!(err),
    };

modified radicle/src/profile.rs
@@ -57,11 +57,9 @@ pub struct Profile {
}

impl Profile {
-
    pub fn init(passphrase: &str) -> Result<Self, Error> {
-
        let home = self::home()?;
+
    pub fn init(home: impl AsRef<Path>, passphrase: &str) -> Result<Self, Error> {
+
        let home = home.as_ref().to_path_buf();
        let storage = Storage::open(&home.join("storage"))?;
-
        // TODO: This should generate a keypair at the given location.
-
        // For now, we use ssh-keygen?
        let keystore = Keystore::new(&home.join("keys"));
        let public_key = keystore.init("radicle", passphrase)?;