radicle-cli: Warn when using old names of nodes
This commit is contained in:
parent
727e4e72c7
commit
af35e6f4d0
|
|
@ -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`.
|
||||||
|
```
|
||||||
|
|
@ -86,6 +86,7 @@ fn debug(profile: Option<&Profile>) -> anyhow::Result<()> {
|
||||||
operating_system: std::env::consts::OS,
|
operating_system: std::env::consts::OS,
|
||||||
arch: std::env::consts::ARCH,
|
arch: std::env::consts::ARCH,
|
||||||
env,
|
env,
|
||||||
|
warnings: collect_warnings(profile),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", serde_json::to_string_pretty(&debug).unwrap());
|
println!("{}", serde_json::to_string_pretty(&debug).unwrap());
|
||||||
|
|
@ -109,6 +110,9 @@ struct DebugInfo {
|
||||||
operating_system: &'static str,
|
operating_system: &'static str,
|
||||||
arch: &'static str,
|
arch: &'static str,
|
||||||
env: BTreeMap<String, String>,
|
env: BTreeMap<String, String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
|
warnings: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
@ -153,3 +157,10 @@ fn stderr_of(bin: &str, args: &[&str]) -> anyhow::Result<String> {
|
||||||
let (_, stderr) = output_of(bin, args)?;
|
let (_, stderr) = output_of(bin, args)?;
|
||||||
Ok(stderr)
|
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()],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,10 @@ pub fn connect(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
|
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() {
|
if node.is_running() {
|
||||||
let listen = node
|
let listen = node
|
||||||
.listen_addrs()?
|
.listen_addrs()?
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,5 @@ pub mod node;
|
||||||
pub mod pager;
|
pub mod pager;
|
||||||
pub mod project;
|
pub mod project;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
|
|
||||||
|
mod warning;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -428,6 +428,21 @@ fn rad_config() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn rad_checkout() {
|
fn rad_checkout() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue