Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle-cli: Warn when using old names of nodes
Merged lorenz opened 10 months ago
6 files changed +137 -3 1df8cf10 af35e6f4
added crates/radicle-cli/examples/rad-warn-old-nodes.md
@@ -0,0 +1,55 @@
+
```
+
$ rad config push preferredSeeds z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@seed.radicle.garden:8776
+
z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@seed.radicle.garden:8776
+
$ rad config push node.connect z6Mkmqogy2qEM2ummccUthFEaaHvyYmYBYh3dbe9W4ebScxo@ash.radicle.garden:8776
+
z6Mkmqogy2qEM2ummccUthFEaaHvyYmYBYh3dbe9W4ebScxo@ash.radicle.garden:8776
+
```
+

+
Note the warnings that the above configuration causes:
+

+
```
+
$ rad debug
+
{
+
  "radExe": "[..]",
+
  "radVersion": "[..]",
+
  "radicleNodeVersion": "radicle-node [..]",
+
  "gitRemoteRadVersion": "git-remote-rad [..]",
+
  "gitVersion": "git version [..]",
+
  "sshVersion": "[..]",
+
  "gitHead": "[..]",
+
  "log": {
+
    "filename": "[..]",
+
    "exists": false,
+
    "len": null
+
  },
+
  "oldLog": {
+
    "filename": "[..]",
+
    "exists": false,
+
    "len": null
+
  },
+
  "operatingSystem": "[..]",
+
  "arch": "[..]",
+
  "env": {
+
    "PATH": "[..]",
+
    "RAD_HOME": "[..]",
+
    "RAD_KEYGEN_SEED": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+
    "RAD_LOCAL_TIME": "[..]",
+
    "RAD_PASSPHRASE": "<REDACTED>",
+
    "RAD_RNG_SEED": "0"
+
  },
+
  "warnings": [
+
    "Value of configuration option `node.connect` at index 0 mentions node with address 'ash.radicle.garden:8776', which has been renamed to 'rosa.radicle.xyz:8776'. Please update your configuration.",
+
    "Value of configuration option `preferred_seeds` at index 0 mentions node with address 'seed.radicle.garden:8776', which has been renamed to 'iris.radicle.xyz:8776'. Please update your configuration."
+
  ]
+
}
+
```
+

+
Also, `rad node status` will warn us:
+

+
```
+
$ rad node status
+
! Warning: Value of configuration option `node.connect` at index 0 mentions node with address 'ash.radicle.garden:8776', which has been renamed to 'rosa.radicle.xyz:8776'. Please update your configuration.
+
! Warning: Value of configuration option `preferred_seeds` at index 0 mentions node with address 'seed.radicle.garden:8776', which has been renamed to 'iris.radicle.xyz:8776'. Please update your configuration.
+
Node is stopped.
+
To start it, run `rad node start`.
+
```

\ No newline at end of file
modified crates/radicle-cli/src/commands/debug.rs
@@ -1,5 +1,5 @@
#![allow(clippy::or_fun_call)]
-
use std::collections::HashMap;
+
use std::collections::BTreeMap;
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
@@ -57,7 +57,7 @@ pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
// Collect information about the local Radicle installation and write
// it out.
fn debug(profile: Option<&Profile>) -> anyhow::Result<()> {
-
    let env = HashMap::from_iter(env::vars().filter_map(|(k, v)| {
+
    let env = BTreeMap::from_iter(env::vars().filter_map(|(k, v)| {
        if k == "RAD_PASSPHRASE" {
            Some((k, "<REDACTED>".into()))
        } else if k.starts_with("RAD_") || k.starts_with("SSH_") || k == "PATH" || k == "SHELL" {
@@ -86,6 +86,7 @@ fn debug(profile: Option<&Profile>) -> anyhow::Result<()> {
        operating_system: std::env::consts::OS,
        arch: std::env::consts::ARCH,
        env,
+
        warnings: collect_warnings(profile),
    };

    println!("{}", serde_json::to_string_pretty(&debug).unwrap());
@@ -108,7 +109,10 @@ struct DebugInfo {
    old_log: Option<LogFile>,
    operating_system: &'static str,
    arch: &'static str,
-
    env: HashMap<String, String>,
+
    env: BTreeMap<String, String>,
+

+
    #[serde(skip_serializing_if = "Vec::is_empty")]
+
    warnings: Vec<String>,
}

#[derive(Debug, Serialize)]
@@ -153,3 +157,10 @@ fn stderr_of(bin: &str, args: &[&str]) -> anyhow::Result<String> {
    let (_, stderr) = output_of(bin, args)?;
    Ok(stderr)
}
+

+
fn collect_warnings(profile: Option<&Profile>) -> Vec<String> {
+
    match profile {
+
        Some(profile) => crate::warning::nodes_renamed(&profile.config),
+
        None => vec!["No Radicle profile found.".to_string()],
+
    }
+
}
modified crates/radicle-cli/src/commands/node/control.rs
@@ -206,6 +206,10 @@ pub fn connect(
}

pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
+
    for warning in crate::warning::nodes_renamed(&profile.config) {
+
        term::warning(warning);
+
    }
+

    if node.is_running() {
        let listen = node
            .listen_addrs()?
modified crates/radicle-cli/src/lib.rs
@@ -7,3 +7,5 @@ pub mod node;
pub mod pager;
pub mod project;
pub mod terminal;
+

+
mod warning;
added crates/radicle-cli/src/warning.rs
@@ -0,0 +1,47 @@
+
use std::collections::HashMap;
+
use std::sync::LazyLock;
+

+
use radicle::node::config::ConnectAddress;
+
use radicle::node::Address;
+
use radicle::profile::Config;
+

+
static NODES_RENAMED: LazyLock<HashMap<Address, Address>> = LazyLock::new(|| {
+
    HashMap::from([
+
        (
+
            "seed.radicle.garden:8776".parse().unwrap(),
+
            "iris.radicle.xyz:8776".parse().unwrap(),
+
        ),
+
        (
+
            "ash.radicle.garden:8776".parse().unwrap(),
+
            "rosa.radicle.xyz:8776".parse().unwrap(),
+
        ),
+
    ])
+
});
+

+
fn nodes_renamed_for_option(
+
    option: &'static str,
+
    iter: impl IntoIterator<Item = ConnectAddress>,
+
) -> Vec<String> {
+
    let mut warnings: Vec<String> = vec![];
+

+
    for (i, value) in iter.into_iter().enumerate() {
+
        let old: Address = value.into();
+
        if let Some(new) = NODES_RENAMED.get(&old) {
+
            warnings.push(format!(
+
                "Value of configuration option `{option}` at index {i} mentions node with address '{}', which has been renamed to '{}'. Please update your configuration.",
+
                old, new
+
            ));
+
        }
+
    }
+

+
    warnings
+
}
+

+
pub(crate) fn nodes_renamed(config: &Config) -> Vec<String> {
+
    let mut warnings = nodes_renamed_for_option("node.connect", config.node.connect.clone());
+
    warnings.extend(nodes_renamed_for_option(
+
        "preferred_seeds",
+
        config.preferred_seeds.clone(),
+
    ));
+
    warnings
+
}
modified crates/radicle-cli/tests/commands.rs
@@ -429,6 +429,21 @@ fn rad_config() {
}

#[test]
+
fn rad_warn_old_nodes() {
+
    let mut environment = Environment::new();
+
    let profile = environment.profile(config::profile("alice"));
+
    let working = tempfile::tempdir().unwrap();
+

+
    test(
+
        "examples/rad-warn-old-nodes.md",
+
        working.path(),
+
        Some(&profile.home),
+
        [],
+
    )
+
    .unwrap();
+
}
+

+
#[test]
fn rad_checkout() {
    let mut environment = Environment::new();
    let profile = environment.profile(config::profile("alice"));