Make `Profile::init` more flexible
Allow passing a custom home. Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
66d1f99a1e
commit
fd936becf1
|
|
@ -4,6 +4,7 @@ use std::ffi::OsString;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
||||||
use radicle::crypto::ssh;
|
use radicle::crypto::ssh;
|
||||||
|
use radicle::profile;
|
||||||
use radicle::Profile;
|
use radicle::Profile;
|
||||||
|
|
||||||
use crate::git;
|
use crate::git;
|
||||||
|
|
@ -76,9 +77,10 @@ pub fn init(options: Options) -> anyhow::Result<()> {
|
||||||
term::blank();
|
term::blank();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let home = profile::home()?;
|
||||||
let passphrase = term::read_passphrase(options.stdin, true)?;
|
let passphrase = term::read_passphrase(options.stdin, true)?;
|
||||||
let spinner = term::spinner("Creating your 🌱 Ed25519 keypair...");
|
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();
|
spinner.finish();
|
||||||
|
|
||||||
term::success!(
|
term::success!(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
use radicle::profile;
|
||||||
use radicle::profile::{Error, Profile};
|
use radicle::profile::{Error, Profile};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let profile = match Profile::load() {
|
let profile = match Profile::load() {
|
||||||
Ok(profile) => profile,
|
Ok(profile) => profile,
|
||||||
Err(Error::NotFound(_)) => Profile::init("radicle")?,
|
Err(Error::NotFound(_)) => Profile::init(profile::home()?, "radicle")?,
|
||||||
Err(err) => anyhow::bail!(err),
|
Err(err) => anyhow::bail!(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,9 @@ pub struct Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Profile {
|
impl Profile {
|
||||||
pub fn init(passphrase: &str) -> Result<Self, Error> {
|
pub fn init(home: impl AsRef<Path>, passphrase: &str) -> Result<Self, Error> {
|
||||||
let home = self::home()?;
|
let home = home.as_ref().to_path_buf();
|
||||||
let storage = Storage::open(&home.join("storage"))?;
|
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 keystore = Keystore::new(&home.join("keys"));
|
||||||
let public_key = keystore.init("radicle", passphrase)?;
|
let public_key = keystore.init("radicle", passphrase)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue