Rename `profile::Paths` to `profile::Home`
This makes the intent clearer. Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
d31968509d
commit
be9def8b11
|
|
@ -50,7 +50,7 @@ impl Args for Options {
|
|||
pub fn run(_options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
|
||||
let home = profile::home()?;
|
||||
|
||||
println!("{}", home.display());
|
||||
println!("{}", home.path().display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
use radicle::profile::Profile;
|
||||
use radicle::profile::{Home, Profile};
|
||||
use radicle::test::fixtures;
|
||||
|
||||
mod framework;
|
||||
|
|
@ -45,7 +45,7 @@ fn profile(home: &Path) -> Profile {
|
|||
// Set debug mode, to make test output more predictable.
|
||||
env::set_var("RAD_DEBUG", "1");
|
||||
// Setup a new user.
|
||||
Profile::init(home, "radicle".to_owned()).unwrap()
|
||||
Profile::init(Home::new(home.to_path_buf()), "radicle".to_owned()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub fn seed(dir: &Path) -> Context {
|
|||
.unwrap();
|
||||
|
||||
// eq. rad auth
|
||||
let profile = radicle::Profile::init(rad_home, PASSWORD.to_owned()).unwrap();
|
||||
let profile = radicle::Profile::init(rad_home.into(), PASSWORD.to_owned()).unwrap();
|
||||
|
||||
// rad init
|
||||
rad_init::init(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::{io, net, thread, time};
|
|||
|
||||
use cyphernet::{Cert, EcSign};
|
||||
use netservices::resource::NetAccept;
|
||||
use radicle::profile::Paths;
|
||||
use radicle::profile::Home;
|
||||
use radicle::Storage;
|
||||
use reactor::poller::popol;
|
||||
use reactor::Reactor;
|
||||
|
|
@ -67,19 +67,19 @@ impl<G: crypto::Signer + EcSign<Pk = NodeId, Sig = Signature> + Clone + 'static>
|
|||
///
|
||||
/// This function spawns threads.
|
||||
pub fn with(
|
||||
paths: Paths,
|
||||
home: Home,
|
||||
config: service::Config,
|
||||
listen: Vec<net::SocketAddr>,
|
||||
proxy: net::SocketAddr,
|
||||
signer: G,
|
||||
) -> Result<Runtime<G>, Error> {
|
||||
let id = *signer.public_key();
|
||||
let node_sock = paths.socket();
|
||||
let node_dir = paths.node();
|
||||
let node_sock = home.socket();
|
||||
let node_dir = home.node();
|
||||
let network = config.network;
|
||||
let rng = fastrand::Rng::new();
|
||||
let clock = LocalTime::now();
|
||||
let storage = Storage::open(paths.storage())?;
|
||||
let storage = Storage::open(home.storage())?;
|
||||
let address_db = node_dir.join(ADDRESS_DB_FILE);
|
||||
let routing_db = node_dir.join(ROUTING_DB_FILE);
|
||||
let tracking_db = node_dir.join(TRACKING_DB_FILE);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use radicle::profile;
|
|||
use radicle_node::client::Runtime;
|
||||
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
||||
use radicle_node::prelude::{Address, NodeId};
|
||||
use radicle_node::profile::Paths;
|
||||
use radicle_node::{logger, service};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -79,11 +78,10 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
let options = Options::from_env()?;
|
||||
let home = profile::home()?;
|
||||
let paths = Paths::new(home);
|
||||
let passphrase = env::var(profile::env::RAD_PASSPHRASE)
|
||||
.context("`RAD_PASSPHRASE` is required to be set for the node to establish connections")?
|
||||
.into();
|
||||
let keystore = Keystore::new(&paths.keys());
|
||||
let keystore = Keystore::new(&home.keys());
|
||||
let signer = MemorySigner::load(&keystore, passphrase)?;
|
||||
let config = service::Config {
|
||||
connect: options.connect.into_iter().collect(),
|
||||
|
|
@ -92,7 +90,7 @@ fn main() -> anyhow::Result<()> {
|
|||
..service::Config::default()
|
||||
};
|
||||
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
||||
let runtime = Runtime::with(paths, config, options.listen, proxy, signer)?;
|
||||
let runtime = Runtime::with(home, config, options.listen, proxy, signer)?;
|
||||
|
||||
runtime.run()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use radicle::crypto::test::signer::MockSigner;
|
|||
use radicle::git::refname;
|
||||
use radicle::identity::Id;
|
||||
use radicle::node::Handle;
|
||||
use radicle::profile::Paths;
|
||||
use radicle::profile::Home;
|
||||
use radicle::storage::WriteStorage;
|
||||
use radicle::test::fixtures;
|
||||
use radicle::Storage;
|
||||
|
|
@ -42,7 +42,7 @@ impl Node {
|
|||
.take(8)
|
||||
.collect::<String>(),
|
||||
);
|
||||
let paths = Paths::init(home).unwrap();
|
||||
let paths = Home::init(home).unwrap();
|
||||
let signer = MockSigner::default();
|
||||
let listen = vec![([0, 0, 0, 0], 0).into()];
|
||||
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
||||
|
|
|
|||
|
|
@ -59,24 +59,22 @@ pub enum Error {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Profile {
|
||||
pub paths: Paths,
|
||||
pub home: Home,
|
||||
pub storage: Storage,
|
||||
pub keystore: Keystore,
|
||||
pub public_key: PublicKey,
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn init(home: impl AsRef<Path>, passphrase: impl Into<Passphrase>) -> Result<Self, Error> {
|
||||
let home = home.as_ref().to_path_buf();
|
||||
let paths = Paths::init(home.as_path())?;
|
||||
let storage = Storage::open(paths.storage())?;
|
||||
let keystore = Keystore::new(&paths.keys());
|
||||
pub fn init(home: Home, passphrase: impl Into<Passphrase>) -> Result<Self, Error> {
|
||||
let storage = Storage::open(home.storage())?;
|
||||
let keystore = Keystore::new(&home.keys());
|
||||
let public_key = keystore.init("radicle", passphrase)?;
|
||||
|
||||
transport::local::register(storage.clone());
|
||||
|
||||
Ok(Profile {
|
||||
paths,
|
||||
home,
|
||||
storage,
|
||||
keystore,
|
||||
public_key,
|
||||
|
|
@ -85,17 +83,16 @@ impl Profile {
|
|||
|
||||
pub fn load() -> Result<Self, Error> {
|
||||
let home = self::home()?;
|
||||
let paths = Paths::new(home);
|
||||
let storage = Storage::open(paths.storage())?;
|
||||
let keystore = Keystore::new(&paths.keys());
|
||||
let storage = Storage::open(home.storage())?;
|
||||
let keystore = Keystore::new(&home.keys());
|
||||
let public_key = keystore
|
||||
.public_key()?
|
||||
.ok_or_else(|| Error::NotFound(paths.home.clone()))?;
|
||||
.ok_or_else(|| Error::NotFound(home.path().to_path_buf()))?;
|
||||
|
||||
transport::local::register(storage.clone());
|
||||
|
||||
Ok(Profile {
|
||||
paths,
|
||||
home,
|
||||
storage,
|
||||
keystore,
|
||||
public_key,
|
||||
|
|
@ -127,31 +124,31 @@ impl Profile {
|
|||
|
||||
/// Return the path to the keys folder.
|
||||
pub fn keys(&self) -> PathBuf {
|
||||
self.paths.keys()
|
||||
self.home.keys()
|
||||
}
|
||||
|
||||
/// Get the profile home directory.
|
||||
pub fn home(&self) -> &Path {
|
||||
self.paths.home()
|
||||
self.home.path()
|
||||
}
|
||||
|
||||
/// Get the path to the radicle node socket.
|
||||
pub fn socket(&self) -> PathBuf {
|
||||
self.paths.socket()
|
||||
self.home.socket()
|
||||
}
|
||||
|
||||
/// Get `Paths` of profile
|
||||
pub fn paths(&self) -> &Paths {
|
||||
&self.paths
|
||||
pub fn paths(&self) -> &Home {
|
||||
&self.home
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the path to the radicle home folder.
|
||||
pub fn home() -> Result<PathBuf, io::Error> {
|
||||
pub fn home() -> Result<Home, io::Error> {
|
||||
if let Some(home) = env::var_os(env::RAD_HOME) {
|
||||
Ok(PathBuf::from(home))
|
||||
Ok(Home::new(PathBuf::from(home)))
|
||||
} else if let Some(home) = env::var_os("HOME") {
|
||||
Ok(PathBuf::from(home).join(".radicle"))
|
||||
Ok(Home::new(PathBuf::from(home).join(".radicle")))
|
||||
} else {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
|
|
@ -160,12 +157,19 @@ pub fn home() -> Result<PathBuf, io::Error> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Radicle home.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Paths {
|
||||
home: PathBuf,
|
||||
pub struct Home {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
impl Paths {
|
||||
impl From<PathBuf> for Home {
|
||||
fn from(path: PathBuf) -> Self {
|
||||
Self { path }
|
||||
}
|
||||
}
|
||||
|
||||
impl Home {
|
||||
pub fn init(home: impl Into<PathBuf>) -> Result<Self, io::Error> {
|
||||
let paths = Self::new(home);
|
||||
fs::create_dir_all(paths.node()).ok();
|
||||
|
|
@ -174,23 +178,23 @@ impl Paths {
|
|||
}
|
||||
|
||||
pub fn new(home: impl Into<PathBuf>) -> Self {
|
||||
Self { home: home.into() }
|
||||
Self { path: home.into() }
|
||||
}
|
||||
|
||||
pub fn home(&self) -> &Path {
|
||||
self.home.as_path()
|
||||
pub fn path(&self) -> &Path {
|
||||
self.path.as_path()
|
||||
}
|
||||
|
||||
pub fn storage(&self) -> PathBuf {
|
||||
self.home.join("storage")
|
||||
self.path.join("storage")
|
||||
}
|
||||
|
||||
pub fn keys(&self) -> PathBuf {
|
||||
self.home.join("keys")
|
||||
self.path.join("keys")
|
||||
}
|
||||
|
||||
pub fn node(&self) -> PathBuf {
|
||||
self.home.join("node")
|
||||
self.path.join("node")
|
||||
}
|
||||
|
||||
pub fn socket(&self) -> PathBuf {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub mod setup {
|
|||
use crate::crypto::test::signer::MockSigner;
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
profile::Paths,
|
||||
profile::Home,
|
||||
test::{fixtures, storage::git::Repository},
|
||||
Storage,
|
||||
};
|
||||
|
|
@ -19,7 +19,7 @@ pub mod setup {
|
|||
let mut rng = fastrand::Rng::new();
|
||||
let signer = MockSigner::new(&mut rng);
|
||||
let home = tmp.path().join("home");
|
||||
let paths = Paths::new(home.as_path());
|
||||
let paths = Home::new(home.as_path());
|
||||
let storage = Storage::open(paths.storage()).unwrap();
|
||||
let (id, _, _, _) = fixtures::project(tmp.path().join("copy"), &storage, &signer).unwrap();
|
||||
let project = storage.repository(id).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in New Issue