pub mod profile {
use std::path::PathBuf;
use radicle::crypto::ssh::Keystore;
use radicle::crypto::PublicKey;
use radicle::git::UserInfo;
use radicle::profile::{Config, Home};
use radicle::Storage;
use snafu::{OptionExt, ResultExt};
#[derive(Clone, Debug)]
pub struct Profile {
pub home: Home,
pub storage: Storage,
pub keystore: Keystore,
pub public_key: PublicKey,
pub config: Config,
}
impl Profile {
pub fn load(home_path: PathBuf) -> Result<Self, snafu::Whatever> {
let home = Home::try_from(home_path).whatever_context("Unable to load home")?;
let keystore = Keystore::new(&home.keys());
let config = Config::load(&home.config()).whatever_context("Unable to load config")?;
let public_key = keystore
.public_key()
.whatever_context("Unable to load keystore")?
.whatever_context("Not able to find public key")?;
let storage = Storage::open(
home.storage(),
UserInfo {
alias: config.node.alias.clone(),
key: public_key,
},
)
.whatever_context("Unable to open storage")?;
Ok(Self {
home,
storage,
keystore,
public_key,
config,
})
}
}
impl From<radicle::Profile> for Profile {
fn from(profile: radicle::Profile) -> Self {
Self {
home: profile.home,
storage: profile.storage,
keystore: profile.keystore,
public_key: profile.public_key,
config: profile.config,
}
}
}
impl From<Profile> for radicle::Profile {
fn from(profile: Profile) -> Self {
Self {
home: profile.home,
storage: profile.storage,
keystore: profile.keystore,
public_key: profile.public_key,
config: profile.config,
}
}
}
}