node: Make node aliases required

This is a fairly substantial change, which adds a new configuration file
to the user's `$RAD_HOME` that includes node configuration, including
the alias, and also makes node aliases required.

When running `rad auth`, the user is now prompted for an alias, which
defaults to `$USER`.

When running `rad self`, the alias is now shown.

If the user runs radicle without a config file, the defaults are loaded,
and `$USER` is used as the alias.
This commit is contained in:
Alexis Sellier
2023-07-11 18:08:59 +02:00
parent 5103d9cedd
commit 2496a1d93d
2 changed files with 9 additions and 4 deletions
+4 -4
View File
@@ -14,7 +14,7 @@ use radicle::cob::thread;
use radicle::cob::thread::CommentId;
use radicle::cob::{ActorId, Author, Reaction, Timestamp};
use radicle::git::RefString;
use radicle::node::AliasStore;
use radicle::node::{Alias, AliasStore};
use radicle::prelude::NodeId;
use radicle::storage::{git, refs, ReadRepository};
use radicle_surf::blob::Blob;
@@ -146,7 +146,7 @@ pub(crate) fn patch(
}
/// Returns JSON for an `author` and fills in `alias` when present.
fn author(author: &Author, alias: Option<String>) -> Value {
fn author(author: &Author, alias: Option<Alias>) -> Value {
match alias {
Some(alias) => json!({
"id": author.id,
@@ -157,7 +157,7 @@ fn author(author: &Author, alias: Option<String>) -> Value {
}
/// Returns JSON for a patch `Merge` and fills in `alias` when present.
fn merge(merge: &Merge, nid: &NodeId, alias: Option<String>) -> Value {
fn merge(merge: &Merge, nid: &NodeId, alias: Option<Alias>) -> Value {
match alias {
Some(alias) => json!({
"author": {
@@ -180,7 +180,7 @@ fn merge(merge: &Merge, nid: &NodeId, alias: Option<String>) -> Value {
}
/// Returns JSON for a patch `Review` and fills in `alias` when present.
fn review(nid: &NodeId, alias: Option<String>, review: &Review) -> Value {
fn review(nid: &NodeId, alias: Option<Alias>, review: &Review) -> Value {
match alias {
Some(alias) => json!({
"author": {
+5
View File
@@ -16,9 +16,11 @@ use radicle::crypto::ssh::keystore::MemorySigner;
use radicle::crypto::ssh::Keystore;
use radicle::crypto::{KeyPair, Seed, Signer};
use radicle::git::{raw as git2, RefString};
use radicle::node;
use radicle::node::address as AddressStore;
use radicle::node::routing as RoutingStore;
use radicle::node::tracking::store as TrackingStore;
use radicle::profile;
use radicle::profile::Home;
use radicle::storage::ReadStorage;
use radicle::Storage;
@@ -63,6 +65,9 @@ pub fn profile(home: &Path, seed: [u8; 32]) -> radicle::Profile {
storage,
keystore,
public_key: keypair.pk.into(),
config: profile::Config {
node: node::Config::new(node::Alias::new("seed")),
},
}
}