cli: Correctly update inventory with seed commands
Make sure our inventory is up to date with the policy changes, as well as when publishing private repositories.
This commit is contained in:
parent
fc55d67929
commit
f0e2018ac5
|
|
@ -0,0 +1,29 @@
|
||||||
|
If we initialize a public repository without seeding it, it won't be advertized:
|
||||||
|
```
|
||||||
|
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed
|
||||||
|
|
||||||
|
Initializing public radicle 👾 repository in [..]
|
||||||
|
|
||||||
|
✓ Repository heartwood created.
|
||||||
|
|
||||||
|
Your Repository ID (RID) is rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK.
|
||||||
|
You can show it any time by running `rad .` from this directory.
|
||||||
|
|
||||||
|
Your repository will be announced to the network when you start your node.
|
||||||
|
You can start your node with `rad node start`.
|
||||||
|
To push changes, run `git push`.
|
||||||
|
```
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
```
|
||||||
|
|
||||||
|
If we then seed it, it becomes advertized in our inventory:
|
||||||
|
```
|
||||||
|
$ rad seed rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
|
||||||
|
✓ Inventory updated with rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
|
||||||
|
✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'all'
|
||||||
|
```
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
Let's say we initialize a private repository and specify that we don't want it
|
||||||
|
to be seeded.
|
||||||
|
```
|
||||||
|
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed
|
||||||
|
|
||||||
|
Initializing private radicle 👾 repository in [..]
|
||||||
|
|
||||||
|
✓ Repository heartwood created.
|
||||||
|
|
||||||
|
Your Repository ID (RID) is rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu.
|
||||||
|
You can show it any time by running `rad .` from this directory.
|
||||||
|
|
||||||
|
You have created a private repository.
|
||||||
|
This repository will only be visible to you, and to peers you explicitly allow.
|
||||||
|
|
||||||
|
To make it public, run `rad publish`.
|
||||||
|
To push changes, run `git push`.
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rad seed
|
||||||
|
No seeding policies to show.
|
||||||
|
```
|
||||||
|
|
||||||
|
We can decide to seed it later:
|
||||||
|
```
|
||||||
|
$ rad seed rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu
|
||||||
|
✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'all'
|
||||||
|
```
|
||||||
|
|
||||||
|
But it still won't show up in our inventory, since it's private:
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
```
|
||||||
|
|
@ -16,3 +16,15 @@ This repository will only be visible to you, and to peers you explicitly allow.
|
||||||
To make it public, run `rad publish`.
|
To make it public, run `rad publish`.
|
||||||
To push changes, run `git push`.
|
To push changes, run `git push`.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The repository does not show up in our inventory, since it is not advertized,
|
||||||
|
despite being seeded:
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
$ rad seed
|
||||||
|
╭────────────────────────────────────────────────────────────────╮
|
||||||
|
│ Repository Name Policy Scope │
|
||||||
|
├────────────────────────────────────────────────────────────────┤
|
||||||
|
│ rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu heartwood allow all │
|
||||||
|
╰────────────────────────────────────────────────────────────────╯
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ $ rad init
|
||||||
✗ Error: repository is already initialized with remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
✗ Error: repository is already initialized with remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
```
|
```
|
||||||
|
|
||||||
Projects can be listed with the `ls` command:
|
Repositories can be listed with the `ls` command:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad ls
|
$ rad ls
|
||||||
|
|
@ -39,3 +39,10 @@ $ rad ls
|
||||||
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
|
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
|
||||||
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Public repositories are added to our inventory:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ Note that if we unseed a repository, it is no longer part of our inventory:
|
||||||
```
|
```
|
||||||
$ rad unseed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
$ rad unseed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed
|
✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed
|
||||||
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
$ rad node inventory
|
||||||
```
|
```
|
||||||
|
|
||||||
Likewise, if we seed a repository we don't have locally, it won't show up as
|
Likewise, if we seed a repository we don't have locally, it won't show up as
|
||||||
|
|
@ -100,20 +100,17 @@ part of our inventory:
|
||||||
```
|
```
|
||||||
$ rad seed rad:z3trNYnLWS11cJWC6BbxDs5niGo82
|
$ rad seed rad:z3trNYnLWS11cJWC6BbxDs5niGo82
|
||||||
[...]
|
[...]
|
||||||
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
$ rad node inventory
|
||||||
```
|
```
|
||||||
|
|
||||||
But if we start seeding the repository we have locally again, it'll show
|
But if we start seeding the repository we have locally again, it'll show
|
||||||
up in our inventory:
|
up in our inventory:
|
||||||
```
|
```
|
||||||
$ rad seed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
$ rad seed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
[...]
|
✓ Inventory updated with rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
|
||||||
╭─────────────────────────────────────────────────────╮
|
$ rad node inventory
|
||||||
│ RID NID │
|
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||||
├─────────────────────────────────────────────────────┤
|
|
||||||
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji z6MknSL…StBU8Vi │
|
|
||||||
╰─────────────────────────────────────────────────────╯
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Some commands also give us a hint if the node isn't running:
|
Some commands also give us a hint if the node isn't running:
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,21 @@ Let's say we have a private repo. To make it public, we use the `publish` comman
|
||||||
```
|
```
|
||||||
$ rad inspect --visibility
|
$ rad inspect --visibility
|
||||||
private
|
private
|
||||||
|
$ rad node inventory
|
||||||
$ rad publish
|
$ rad publish
|
||||||
|
✓ Updating inventory..
|
||||||
✓ Repository is now public
|
✓ Repository is now public
|
||||||
! Warning: Your node is not running. Start your node with `rad node start` to announce your repository to the network
|
! Warning: Your node is not running. Start your node with `rad node start` to announce your repository to the network
|
||||||
$ rad inspect --visibility
|
$ rad inspect --visibility
|
||||||
public
|
public
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The repository is now in our inventory:
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu
|
||||||
|
```
|
||||||
|
|
||||||
If we try to publish again, we get an error:
|
If we try to publish again, we get an error:
|
||||||
|
|
||||||
``` (fail)
|
``` (fail)
|
||||||
|
|
|
||||||
|
|
@ -35,3 +35,11 @@ $ rad ls --all
|
||||||
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji local f2de534 Radicle Heartwood Protocol & Stack │
|
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji local f2de534 Radicle Heartwood Protocol & Stack │
|
||||||
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Hence, we also see that it isn't in our inventory and isn't seeded:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rad node inventory
|
||||||
|
$ rad seed
|
||||||
|
No seeding policies to show.
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -114,18 +114,19 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
anyhow::bail!("fatal: repository storage is corrupt");
|
anyhow::bail!("fatal: repository storage is corrupt");
|
||||||
}
|
}
|
||||||
|
let mut node = radicle::Node::new(profile.socket());
|
||||||
|
let spinner = term::spinner("Updating inventory..");
|
||||||
|
|
||||||
|
// The repository is now part of our inventory.
|
||||||
|
profile.add_inventory(rid, &mut node)?;
|
||||||
|
spinner.finish();
|
||||||
|
|
||||||
term::success!(
|
term::success!(
|
||||||
"Repository is now {}",
|
"Repository is now {}",
|
||||||
term::format::visibility(&doc.visibility)
|
term::format::visibility(&doc.visibility)
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut node = radicle::Node::new(profile.socket());
|
if !node.is_running() {
|
||||||
if node.is_running() {
|
|
||||||
let spinner = term::spinner("Announcing to network..");
|
|
||||||
node.announce_inventory()?;
|
|
||||||
spinner.finish();
|
|
||||||
} else {
|
|
||||||
term::warning(format!(
|
term::warning(format!(
|
||||||
"Your node is not running. Start your node with {} to announce your repository \
|
"Your node is not running. Start your node with {} to announce your repository \
|
||||||
to the network",
|
to the network",
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,13 @@ pub fn update(
|
||||||
let updated = profile.seed(rid, scope, node)?;
|
let updated = profile.seed(rid, scope, node)?;
|
||||||
let outcome = if updated { "updated" } else { "exists" };
|
let outcome = if updated { "updated" } else { "exists" };
|
||||||
|
|
||||||
|
if let Ok(repo) = profile.storage.repository(rid) {
|
||||||
|
if repo.identity_doc()?.visibility.is_public() {
|
||||||
|
profile.add_inventory(rid, node)?;
|
||||||
|
term::success!("Inventory updated with {}", term::format::tertiary(rid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
term::success!(
|
term::success!(
|
||||||
"Seeding policy {outcome} for {} with scope '{scope}'",
|
"Seeding policy {outcome} for {} with scope '{scope}'",
|
||||||
term::format::tertiary(rid),
|
term::format::tertiary(rid),
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,23 @@ fn rad_init() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rad_init_no_seed() {
|
||||||
|
let mut environment = Environment::new();
|
||||||
|
let alice = environment.node(Config::test(Alias::new("alice")));
|
||||||
|
let working = environment.tmp().join("working");
|
||||||
|
|
||||||
|
fixtures::repository(working.join("alice"));
|
||||||
|
|
||||||
|
test(
|
||||||
|
"examples/rad-init-no-seed.md",
|
||||||
|
working.join("alice"),
|
||||||
|
Some(&alice.home),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_init_with_existing_remote() {
|
fn rad_init_with_existing_remote() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
|
|
@ -2168,6 +2185,23 @@ fn rad_init_private() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rad_init_private_no_seed() {
|
||||||
|
let mut environment = Environment::new();
|
||||||
|
let alice = environment.node(Config::test(Alias::new("alice")));
|
||||||
|
let working = environment.tmp().join("working");
|
||||||
|
|
||||||
|
fixtures::repository(working.join("alice"));
|
||||||
|
|
||||||
|
test(
|
||||||
|
"examples/rad-init-private-no-seed.md",
|
||||||
|
working.join("alice"),
|
||||||
|
Some(&alice.home),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_init_private_seed() {
|
fn rad_init_private_seed() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ use crate::node::{
|
||||||
use crate::prelude::{Did, NodeId, RepoId};
|
use crate::prelude::{Did, NodeId, RepoId};
|
||||||
use crate::storage::git::transport;
|
use crate::storage::git::transport;
|
||||||
use crate::storage::git::Storage;
|
use crate::storage::git::Storage;
|
||||||
use crate::storage::{ReadRepository, ReadStorage};
|
use crate::storage::ReadRepository;
|
||||||
use crate::{cli, cob, git, node, storage, web};
|
use crate::{cli, cob, git, node, storage, web};
|
||||||
|
|
||||||
/// Environment variables used by radicle.
|
/// Environment variables used by radicle.
|
||||||
|
|
@ -453,15 +453,9 @@ impl Profile {
|
||||||
Ok(updated) => Ok(updated),
|
Ok(updated) => Ok(updated),
|
||||||
Err(e) if e.is_connection_err() => {
|
Err(e) if e.is_connection_err() => {
|
||||||
let mut config = self.policies_mut()?;
|
let mut config = self.policies_mut()?;
|
||||||
let result = config.seed(&rid, scope)?;
|
let updated = config.seed(&rid, scope)?;
|
||||||
|
|
||||||
if result && self.storage.contains(&rid)? {
|
Ok(updated)
|
||||||
let now = LocalTime::now();
|
|
||||||
let mut db = self.database_mut()?;
|
|
||||||
|
|
||||||
node::routing::Store::add_inventory(&mut db, [&rid], *self.id(), now.into())?;
|
|
||||||
}
|
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
Err(e) => Err(e.into()),
|
Err(e) => Err(e.into()),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue