cli: Move node addresses command

To make things a little more consistent, move the `rad self --address`
command to `rad node config --addresses`, since it's more about
externally-facing configuration of the node, rather than your local user
or profile.
This commit is contained in:
cloudhead 2024-02-26 14:23:13 +01:00
parent 091f7b7e98
commit a48081f271
No known key found for this signature in database
5 changed files with 36 additions and 24 deletions

View File

@ -18,6 +18,12 @@ $ rad node status
✓ Node is running and listening on [..]. ✓ Node is running and listening on [..].
``` ```
```
$ rad node config --addresses
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@41.12.98.112:8776
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.cloudhead.io:8776
```
The node also allows us to query data that it has access to such as The node also allows us to query data that it has access to such as
the follow policies and the routing table. Before we explore the follow policies and the routing table. Before we explore
those commands we'll first follow a peer so that we have something to those commands we'll first follow a peer so that we have something to

View File

@ -38,8 +38,3 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
$ rad self --home $ rad self --home
[..]/home/alice/.radicle [..]/home/alice/.radicle
``` ```
```
$ rad self --address
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.alice.acme:8776
```

View File

@ -4,6 +4,8 @@ use std::time;
use anyhow::anyhow; use anyhow::anyhow;
use radicle::node::config::ConnectAddress;
use radicle::node::Handle as _;
use radicle::node::{Address, Node, NodeId, PeerAddr}; use radicle::node::{Address, Node, NodeId, PeerAddr};
use radicle::prelude::RepoId; use radicle::prelude::RepoId;
@ -32,7 +34,7 @@ Usage
rad node connect <nid>@<addr> [<option>...] rad node connect <nid>@<addr> [<option>...]
rad node routing [--rid <rid>] [--nid <nid>] [--json] [<option>...] rad node routing [--rid <rid>] [--nid <nid>] [--json] [<option>...]
rad node events [--timeout <secs>] [-n <count>] [<option>...] rad node events [--timeout <secs>] [-n <count>] [<option>...]
rad node config rad node config [--addresses]
For `<node-option>` see `radicle-node --help`. For `<node-option>` see `radicle-node --help`.
@ -68,7 +70,9 @@ pub enum Operation {
addr: PeerAddr<NodeId, Address>, addr: PeerAddr<NodeId, Address>,
timeout: time::Duration, timeout: time::Duration,
}, },
Config, Config {
addresses: bool,
},
Events { Events {
timeout: time::Duration, timeout: time::Duration,
count: usize, count: usize,
@ -121,6 +125,7 @@ impl Args for Options {
let mut lines: usize = 60; let mut lines: usize = 60;
let mut count: usize = usize::MAX; let mut count: usize = usize::MAX;
let mut timeout = time::Duration::MAX; let mut timeout = time::Duration::MAX;
let mut addresses = false;
let mut path = None; let mut path = None;
let mut verbose = false; let mut verbose = false;
@ -167,6 +172,9 @@ impl Args for Options {
Long("foreground") if matches!(op, Some(OperationName::Start)) => { Long("foreground") if matches!(op, Some(OperationName::Start)) => {
foreground = true; foreground = true;
} }
Long("addresses") if matches!(op, Some(OperationName::Config)) => {
addresses = true;
}
Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => { Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => {
verbose = true; verbose = true;
} }
@ -191,7 +199,7 @@ impl Args for Options {
})?, })?,
timeout, timeout,
}, },
OperationName::Config => Operation::Config, OperationName::Config => Operation::Config { addresses },
OperationName::Events => Operation::Events { timeout, count }, OperationName::Events => Operation::Events { timeout, count },
OperationName::Routing => Operation::Routing { rid, nid, json }, OperationName::Routing => Operation::Routing { rid, nid, json },
OperationName::Logs => Operation::Logs { lines }, OperationName::Logs => Operation::Logs { lines },
@ -217,7 +225,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Operation::Connect { addr, timeout } => { Operation::Connect { addr, timeout } => {
control::connect(&mut node, addr.id, addr.addr, timeout)? control::connect(&mut node, addr.id, addr.addr, timeout)?
} }
Operation::Config => control::config(&node)?, Operation::Config { addresses } => {
if addresses {
let cfg = node.config()?;
for addr in cfg.external_addresses {
term::print(ConnectAddress::from((*profile.id(), addr)).to_string());
}
} else {
control::config(&node)?;
}
}
Operation::Sessions => { Operation::Sessions => {
let sessions = control::sessions(&node)?; let sessions = control::sessions(&node)?;
if let Some(table) = sessions { if let Some(table) = sessions {

View File

@ -1,7 +1,6 @@
use std::ffi::OsString; use std::ffi::OsString;
use radicle::crypto::ssh; use radicle::crypto::ssh;
use radicle::node::config::ConnectAddress;
use radicle::Profile; use radicle::Profile;
use crate::terminal as term; use crate::terminal as term;
@ -22,7 +21,6 @@ Options
--did Show your DID --did Show your DID
--alias Show your Node alias --alias Show your Node alias
--nid Show your Node ID (NID) --nid Show your Node ID (NID)
--address Show your Node address(es)
--home Show your Radicle home --home Show your Radicle home
--config Show the location of your configuration file --config Show the location of your configuration file
--ssh-key Show your public key in OpenSSH format --ssh-key Show your public key in OpenSSH format
@ -34,7 +32,6 @@ Options
#[derive(Debug)] #[derive(Debug)]
enum Show { enum Show {
Alias, Alias,
Address,
NodeId, NodeId,
Did, Did,
Home, Home,
@ -61,9 +58,6 @@ impl Args for Options {
Long("alias") if show.is_none() => { Long("alias") if show.is_none() => {
show = Some(Show::Alias); show = Some(Show::Alias);
} }
Long("address") if show.is_none() => {
show = Some(Show::Address);
}
Long("nid") if show.is_none() => { Long("nid") if show.is_none() => {
show = Some(Show::NodeId); show = Some(Show::NodeId);
} }
@ -105,12 +99,6 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Show::Alias => { Show::Alias => {
term::print(profile.config.alias()); term::print(profile.config.alias());
} }
Show::Address => {
let nid = profile.public_key;
for addr in profile.config.node.external_addresses {
term::print(ConnectAddress::from((nid, addr)).to_string());
}
}
Show::NodeId => { Show::NodeId => {
term::print(profile.id()); term::print(profile.id());
} }

View File

@ -1,6 +1,6 @@
use std::path::Path; use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use std::{env, thread, time}; use std::{env, net, thread, time};
use radicle::git; use radicle::git;
use radicle::node; use radicle::node;
@ -8,7 +8,7 @@ use radicle::node::address::Store as _;
use radicle::node::config::seeds::{RADICLE_COMMUNITY_NODE, RADICLE_TEAM_NODE}; use radicle::node::config::seeds::{RADICLE_COMMUNITY_NODE, RADICLE_TEAM_NODE};
use radicle::node::routing::Store as _; use radicle::node::routing::Store as _;
use radicle::node::Handle as _; use radicle::node::Handle as _;
use radicle::node::{Alias, DEFAULT_TIMEOUT}; use radicle::node::{Address, Alias, DEFAULT_TIMEOUT};
use radicle::prelude::RepoId; use radicle::prelude::RepoId;
use radicle::profile; use radicle::profile;
use radicle::profile::Home; use radicle::profile::Home;
@ -582,7 +582,13 @@ fn rad_node_connect() {
#[test] #[test]
fn rad_node() { fn rad_node() {
let mut environment = Environment::new(); let mut environment = Environment::new();
let alice = environment.node(Config::test(Alias::new("alice"))); let alice = environment.node(Config {
external_addresses: vec![
Address::from(net::SocketAddr::from(([41, 12, 98, 112], 8776))),
Address::from_str("seed.cloudhead.io:8776").unwrap(),
],
..Config::test(Alias::new("alice"))
});
let working = tempfile::tempdir().unwrap(); let working = tempfile::tempdir().unwrap();
let alice = alice.spawn(); let alice = alice.spawn();