Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `profile::env` module
Alexis Sellier committed 3 years ago
commit 092ccfdcbc895a73fd5c0efce378fbd5165b4386
parent 577b6320562f361fe4c93029f79613a2bb02a3c5
2 files changed +18 -4
modified radicle-node/src/main.rs
@@ -2,6 +2,7 @@ use std::{env, net, process, thread};

use anyhow::Context as _;

+
use radicle::profile;
use radicle_node::crypto::ssh::keystore::MemorySigner;
use radicle_node::logger;
use radicle_node::prelude::Address;
@@ -18,6 +19,7 @@ struct Options {
impl Options {
    fn from_env() -> Result<Self, lexopt::Error> {
        use lexopt::prelude::*;
+

        let mut parser = lexopt::Parser::from_env();
        let mut connect = Vec::new();
        let mut listen = Vec::new();
@@ -53,7 +55,7 @@ fn main() -> anyhow::Result<()> {
    let signer = match profile.signer() {
        Ok(signer) => signer.boxed(),
        Err(err) => {
-
            let passphrase = env::var("RAD_PASSPHRASE")
+
            let passphrase = env::var(profile::env::RAD_PASSPHRASE)
                .context("Either ssh-agent must be initialized, or `RAD_PASSPHRASE` must be set")
                .context(err)?;
            MemorySigner::load(&profile.keystore, &passphrase)?.boxed()
modified radicle/src/profile.rs
@@ -10,8 +10,8 @@
//!     node/
//!       radicle.sock                           # Node control socket
//!
+
use std::io;
use std::path::PathBuf;
-
use std::{env, io};

use thiserror::Error;

@@ -22,6 +22,18 @@ use crate::node;
use crate::storage::git::transport;
use crate::storage::git::Storage;

+
/// Environment variables used by radicle.
+
pub mod env {
+
    pub use std::env::*;
+

+
    /// Path to the radicle home folder.
+
    pub const RAD_HOME: &str = "RAD_HOME";
+
    /// Path to the radicle node socket file.
+
    pub const RAD_SOCKET: &str = "RAD_SOCKET";
+
    /// Passphrase for the encrypted radicle secret key.
+
    pub const RAD_PASSPHRASE: &str = "RAD_PASSPHRASE";
+
}
+

#[derive(Debug, Error)]
pub enum Error {
    #[error(transparent)]
@@ -107,7 +119,7 @@ impl Profile {

    /// Get the path to the radicle node socket.
    pub fn node(&self) -> PathBuf {
-
        env::var_os("RAD_SOCKET")
+
        env::var_os(env::RAD_SOCKET)
            .map(PathBuf::from)
            .unwrap_or_else(|| self.home.join("node").join(node::DEFAULT_SOCKET_NAME))
    }
@@ -115,7 +127,7 @@ impl Profile {

/// Get the path to the radicle home folder.
pub fn home() -> Result<PathBuf, io::Error> {
-
    if let Some(home) = env::var_os("RAD_HOME") {
+
    if let Some(home) = env::var_os(env::RAD_HOME) {
        Ok(PathBuf::from(home))
    } else if let Some(home) = env::var_os("HOME") {
        Ok(PathBuf::from(home).join(".radicle"))