Skip to content
Snippets Groups Projects
Commit 8ebb6428 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon: Committed by Yaroslav Dynnikov
Browse files

fix: picodata expel add --user --password-file & --auth-method parameters

parent dca4eaa0
No related branches found
No related tags found
1 merge request!895fix: wrong pico_service password + picodata expel --user
Pipeline #35246 failed
......@@ -315,12 +315,34 @@ pub struct Expel {
pub instance_id: InstanceId,
#[clap(
long = "peer",
value_name = "[HOST][:PORT]",
default_value = "localhost:3301"
short = 'u',
long = "user",
value_name = "USER",
default_value = DEFAULT_USERNAME,
env = "PICODATA_USER"
)]
/// The username to connect with. Ignored if provided in `ADDRESS`.
pub user: String,
#[clap(
short = 'a',
long = "auth-type",
value_name = "METHOD",
default_value = AuthMethod::ChapSha1.as_str(),
)]
/// Address of any instance from the cluster.
/// The preferred authentication method.
pub auth_method: AuthMethod,
#[clap(long = "peer", value_name = "[USER@][HOST][:PORT]")]
/// Address of any picodata instance of the given cluster. It will be used
/// to redirect the request to the current raft-leader to execute the actual
/// request.
pub peer_address: Address,
#[clap(long, env = "PICODATA_PASSWORD_FILE")]
/// Path to a plain-text file with a password.
/// If this option isn't provided, the password is prompted from the terminal.
pub password_file: Option<String>,
}
impl Expel {
......
use crate::{rpc, tarantool_main, tlog};
use crate::cli::args;
use crate::cli::connect::determine_credentials_and_connect;
use crate::rpc::expel::Request as ExpelRequest;
use crate::rpc::RequestArgs;
use crate::tarantool_main;
use crate::tlog;
use crate::traft::error::Error;
use tarantool::fiber;
use tarantool::network::client::AsClient;
use super::args;
pub async fn tt_expel(args: args::Expel) -> Result<(), Error> {
let (client, _) = determine_credentials_and_connect(
&args.peer_address,
Some(&args.user),
args.password_file.as_deref(),
args.auth_method,
)?;
pub async fn tt_expel(args: args::Expel) {
let req = rpc::expel::Request {
let req = ExpelRequest {
cluster_id: args.cluster_id,
instance_id: args.instance_id,
instance_id: args.instance_id.clone(),
};
let res = rpc::network_call(
&format!("{}:{}", args.peer_address.host, args.peer_address.port),
&rpc::expel::redirect::Request(req),
)
.await;
match res {
Ok(_) => {
tlog!(Info, "Success expel call");
std::process::exit(0);
}
Err(e) => {
tlog!(Error, "Failed to expel instance: {e}");
std::process::exit(-1);
}
}
fiber::block_on(client.call(ExpelRequest::PROC_NAME, &req))
.map_err(|e| Error::other(format!("Failed to expel instance: {e}")))?;
tlog!(Info, "Instance {} successfully expelled", args.instance_id);
Ok(())
}
pub fn main(args: args::Expel) -> ! {
......@@ -30,7 +34,11 @@ pub fn main(args: args::Expel) -> ! {
callback_data: (args,),
callback_data_type: (args::Expel,),
callback_body: {
::tarantool::fiber::block_on(tt_expel(args))
if let Err(e) = ::tarantool::fiber::block_on(tt_expel(args)) {
tlog!(Critical, "{e}");
std::process::exit(1);
}
std::process::exit(0);
}
);
std::process::exit(rc);
......
......@@ -1382,6 +1382,7 @@ class Cluster:
def expel(self, target: Instance, peer: Instance | None = None):
peer = peer if peer else target
assert self.service_password_file, "cannot expel without pico_service password"
# fmt: off
command = [
......@@ -1389,6 +1390,8 @@ class Cluster:
"--peer", peer.listen,
"--cluster-id", target.cluster_id,
"--instance-id", target.instance_id,
"--user", "pico_service",
"--password-file", self.service_password_file,
]
# fmt: on
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment