Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: Start to disentangle user and node
Merged lorenz opened 8 months ago

Basically, the Node ID moves from rad self to rad node.

If we ever want to disentangle the users’ identity from the node, then the rad node commands must learn to print the information related to the node, and the rad self command should not display information related to the node so prominently.

Users might have to re-learn a tiny bit here, but I wager it is worth the pain.

This is just a first tiny step in this direction, and I extracted these changes from (still unpushed) work on patch/ed450c9 that got out of hand.

The time is now.

4 files changed +64 -39 9b7529ba f00d1d67
modified crates/radicle-cli/examples/rad-node.md
@@ -15,7 +15,7 @@ node status` command (or just `rad node` for short):

```
$ rad node status
-
✓ Node is running and listening on [..].
+
✓ Node is running with Node ID z6MknSL[..]Vi and listening for inbound connections on [..].
```

```
modified crates/radicle-cli/examples/rad-self.md
@@ -3,17 +3,17 @@ device and node.

```
$ rad self
-
Alias           alice
-
DID             did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
-
└╴Node ID (NID) z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
-
SSH             not running
-
├╴Key (hash)    SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
-
└╴Key (full)    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
-
Home            [..]/home/alice/.radicle
-
├╴Config        [..]/home/alice/.radicle/config.json
-
├╴Storage       [..]/home/alice/.radicle/storage
-
├╴Keys          [..]/home/alice/.radicle/keys
-
└╴Node          [..]/home/alice/.radicle/node
+
Alias        alice
+
DID          did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
+
Node         not running
+
SSH          not running
+
├╴Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
+
└╴Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
+
Home         [..]/home/alice/.radicle
+
├╴Config     [..]/home/alice/.radicle/config.json
+
├╴Storage    [..]/home/alice/.radicle/storage
+
├╴Keys       [..]/home/alice/.radicle/keys
+
└╴Node       [..]/home/alice/.radicle/node
```

If you need to display only your DID, Node ID, or SSH Public Key, you can use
@@ -26,6 +26,7 @@ did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi

```
$ rad self --nid
+
! Warning: The option `--nid` is deprecated, please use `rad node status` instead.
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
```

modified crates/radicle-cli/src/commands/node/control.rs
@@ -260,23 +260,7 @@ pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
        term::warning(warning);
    }

-
    if node.is_running() {
-
        let listen = node
-
            .listen_addrs()?
-
            .into_iter()
-
            .map(|addr| addr.to_string())
-
            .collect::<Vec<_>>();
-

-
        if listen.is_empty() {
-
            term::success!("Node is {}.", term::format::positive("running"));
-
        } else {
-
            term::success!(
-
                "Node is {} and listening on {}.",
-
                term::format::positive("running"),
-
                listen.join(", ")
-
            );
-
        }
-
    } else {
+
    if !node.is_running() {
        term::info!("Node is {}.", term::format::negative("stopped"));
        term::info!(
            "To start it, run {}.",
@@ -285,6 +269,35 @@ pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
        return Ok(());
    }

+
    let listen = node
+
        .listen_addrs()?
+
        .into_iter()
+
        .map(|addr| addr.to_string())
+
        .collect::<Vec<_>>();
+

+
    let nid = node.nid()?;
+
    let nid = if &nid == profile.id() {
+
        term::format::tertiary(term::format::node_id_human(&nid))
+
    } else {
+
        term::format::yellow(term::format::node_id_human(&nid)).bold()
+
    };
+

+
    if listen.is_empty() {
+
        term::success!(
+
            "Node is {} with Node ID {} and {} listening for inbound connections.",
+
            term::format::positive("running"),
+
            nid,
+
            term::Paint::new("not").italic()
+
        );
+
    } else {
+
        term::success!(
+
            "Node is {} with Node ID {} and listening for inbound connections on {}.",
+
            term::format::positive("running"),
+
            nid,
+
            listen.join(", ")
+
        );
+
    }
+

    let sessions = sessions(node)?;
    if let Some(table) = sessions {
        term::blank();
modified crates/radicle-cli/src/commands/self.rs
@@ -1,7 +1,8 @@
use std::ffi::OsString;

use radicle::crypto::ssh;
-
use radicle::Profile;
+
use radicle::node::Handle as _;
+
use radicle::{Node, Profile};

use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
@@ -20,7 +21,6 @@ Options

    --did                Show your DID
    --alias              Show your Node alias
-
    --nid                Show your Node ID (NID)
    --home               Show your Radicle home
    --config             Show the location of your configuration file
    --ssh-key            Show your public key in OpenSSH format
@@ -100,7 +100,15 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            term::print(profile.config.alias());
        }
        Show::NodeId => {
-
            term::print(profile.id());
+
            term::warning(
+
                "The option `--nid` is deprecated, please use `rad node status` instead.",
+
            );
+
            term::print(
+
                Node::new(profile.socket())
+
                    .nid()
+
                    .ok()
+
                    .unwrap_or_else(|| *profile.id()),
+
            );
        }
        Show::Did => {
            term::print(profile.did());
@@ -137,11 +145,13 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
        term::format::tertiary(did).into(),
    ]);

-
    let node_id = profile.id();
-
    table.push([
-
        term::format::style("└╴Node ID (NID)").into(),
-
        term::format::tertiary(node_id).into(),
-
    ]);
+
    let socket = profile.socket();
+
    let node = if Node::new(&socket).is_running() {
+
        term::format::positive(format!("running ({})", socket.display()))
+
    } else {
+
        term::format::negative("not running".to_string())
+
    };
+
    table.push([term::format::style("Node").into(), node.to_string().into()]);

    let ssh_agent = match ssh::agent::Agent::connect() {
        Ok(c) => term::format::positive(format!(
@@ -158,13 +168,14 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
        ssh_agent.to_string().into(),
    ]);

-
    let ssh_short = ssh::fmt::fingerprint(node_id);
+
    let id = profile.id();
+
    let ssh_short = ssh::fmt::fingerprint(id);
    table.push([
        term::format::style("├╴Key (hash)").into(),
        term::format::tertiary(ssh_short).into(),
    ]);

-
    let ssh_long = ssh::fmt::key(node_id);
+
    let ssh_long = ssh::fmt::key(id);
    table.push([
        term::format::style("└╴Key (full)").into(),
        term::format::tertiary(ssh_long).into(),