Feature/unregister command (#460)
* Unregister command for mixnode * Unregister command for gateway * cargo fmt
This commit is contained in:
committed by
GitHub
parent
a69123ebc1
commit
1d851c390c
@@ -17,6 +17,7 @@ use clap::ArgMatches;
|
||||
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod run;
|
||||
pub(crate) mod unregister;
|
||||
pub(crate) mod upgrade;
|
||||
|
||||
pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Config {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2020 Nym Technologies SA
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::config::{persistence::pathfinder::GatewayPathfinder, Config};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use config::NymConfig;
|
||||
use crypto::asymmetric::identity;
|
||||
use log::*;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
App::new("unregister").about("Unregister the gateway").arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-gateway we want to explicitly unregister")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
}
|
||||
|
||||
fn load_identity_keys(pathfinder: &GatewayPathfinder) -> identity::KeyPair {
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
pathfinder.public_identity_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored identity key files")
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
// TODO: this should probably be made implicit by slapping `#[tokio::main]` on our main method
|
||||
// and then removing runtime from gateway itself in `run`
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
println!("Attempting to unregister gateway {}...", id);
|
||||
|
||||
let config = match Config::load_from_file(id) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
error!("Failed to load config for {}. Are you sure you have run provided correct id? (Error was: {})", id, err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// we need to load identity keys to be able to grab node's public key
|
||||
let pathfinder = GatewayPathfinder::new_from_config(&config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
|
||||
// now attempt to unregister
|
||||
let validator_client_config = validator_client::Config::new(config.get_validator_rest_endpoint());
|
||||
let validator_client = validator_client::Client::new(validator_client_config);
|
||||
|
||||
match validator_client.unregister_node(&*identity_keypair.public_key().to_base58_string()).await {
|
||||
Err(err) => error!("failed to unregister node '{}'. Error: {:?}", id, err),
|
||||
Ok(_) => info!("managed to successfully unregister node '{}'!", id)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -30,6 +30,7 @@ fn main() {
|
||||
.subcommand(commands::init::command_args())
|
||||
.subcommand(commands::run::command_args())
|
||||
.subcommand(commands::upgrade::command_args())
|
||||
.subcommand(commands::unregister::command_args())
|
||||
.get_matches();
|
||||
|
||||
execute(arg_matches);
|
||||
@@ -40,6 +41,7 @@ fn execute(matches: ArgMatches) {
|
||||
("init", Some(m)) => commands::init::execute(m),
|
||||
("run", Some(m)) => commands::run::execute(m),
|
||||
("upgrade", Some(m)) => commands::upgrade::execute(m),
|
||||
("unregister", Some(m)) => commands::unregister::execute(m),
|
||||
_ => println!("{}", usage()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use nymsphinx::params::DEFAULT_NUM_MIX_HOPS;
|
||||
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod run;
|
||||
pub(crate) mod unregister;
|
||||
pub(crate) mod upgrade;
|
||||
|
||||
pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Config {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2020 Nym Technologies SA
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::config::{persistence::pathfinder::MixNodePathfinder, Config};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use config::NymConfig;
|
||||
use crypto::asymmetric::identity;
|
||||
use log::*;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
App::new("unregister").about("Unregister the mixnode").arg(
|
||||
Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-mixnode we want to explicitly unregister")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
}
|
||||
|
||||
fn load_identity_keys(pathfinder: &MixNodePathfinder) -> identity::KeyPair {
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
pathfinder.public_identity_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored identity key files")
|
||||
}
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
// TODO: this should probably be made implicit by slapping `#[tokio::main]` on our main method
|
||||
// and then removing runtime from mixnode itself in `run`
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let id = matches.value_of("id").unwrap();
|
||||
|
||||
println!("Attempting to unregister mixnode {}...", id);
|
||||
|
||||
let config = match Config::load_from_file(id) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
error!("Failed to load config for {}. Are you sure you have run provided correct id? (Error was: {})", id, err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// we need to load identity keys to be able to grab node's public key
|
||||
let pathfinder = MixNodePathfinder::new_from_config(&config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
|
||||
// now attempt to unregister
|
||||
let validator_client_config = validator_client::Config::new(config.get_validator_rest_endpoint());
|
||||
let validator_client = validator_client::Client::new(validator_client_config);
|
||||
|
||||
match validator_client.unregister_node(&*identity_keypair.public_key().to_base58_string()).await {
|
||||
Err(err) => error!("failed to unregister node '{}'. Error: {:?}", id, err),
|
||||
Ok(_) => info!("managed to successfully unregister node '{}'!", id)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -30,6 +30,7 @@ fn main() {
|
||||
.subcommand(commands::init::command_args())
|
||||
.subcommand(commands::run::command_args())
|
||||
.subcommand(commands::upgrade::command_args())
|
||||
.subcommand(commands::unregister::command_args())
|
||||
.get_matches();
|
||||
|
||||
execute(arg_matches);
|
||||
@@ -40,6 +41,7 @@ fn execute(matches: ArgMatches) {
|
||||
("init", Some(m)) => commands::init::execute(m),
|
||||
("run", Some(m)) => commands::run::execute(m),
|
||||
("upgrade", Some(m)) => commands::upgrade::execute(m),
|
||||
("unregister", Some(m)) => commands::unregister::execute(m),
|
||||
_ => println!("{}", usage()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user