cargo fmt + clippy
This commit is contained in:
parent
3556eb37ea
commit
d1d06514a9
|
@ -56,11 +56,11 @@ The Y/N-values corresponds to the following mysql privileges:
|
||||||
/// Please consider using the newer mysqladm command instead.
|
/// Please consider using the newer mysqladm command instead.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(
|
#[command(
|
||||||
bin_name = "mysql-dbadm",
|
bin_name = "mysql-dbadm",
|
||||||
version,
|
version,
|
||||||
about,
|
about,
|
||||||
disable_help_subcommand = true,
|
disable_help_subcommand = true,
|
||||||
verbatim_doc_comment,
|
verbatim_doc_comment
|
||||||
)]
|
)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
|
|
|
@ -32,11 +32,11 @@ use crate::{
|
||||||
/// Please consider using the newer mysqladm command instead.
|
/// Please consider using the newer mysqladm command instead.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(
|
#[command(
|
||||||
bin_name = "mysql-useradm",
|
bin_name = "mysql-useradm",
|
||||||
version,
|
version,
|
||||||
about,
|
about,
|
||||||
disable_help_subcommand = true,
|
disable_help_subcommand = true,
|
||||||
verbatim_doc_comment,
|
verbatim_doc_comment
|
||||||
)]
|
)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
|
|
|
@ -32,15 +32,18 @@ pub fn drop_privs() -> anyhow::Result<()> {
|
||||||
|
|
||||||
/// This function is used to bootstrap the connection to the server.
|
/// This function is used to bootstrap the connection to the server.
|
||||||
/// This can happen in two ways:
|
/// This can happen in two ways:
|
||||||
|
///
|
||||||
/// 1. If a socket path is provided, or exists in the default location,
|
/// 1. If a socket path is provided, or exists in the default location,
|
||||||
/// the function will connect to the socket and authenticate with the
|
/// the function will connect to the socket and authenticate with the
|
||||||
/// server to ensure that the server knows the uid of the client.
|
/// server to ensure that the server knows the uid of the client.
|
||||||
|
///
|
||||||
/// 2. If a config path is provided, or exists in the default location,
|
/// 2. If a config path is provided, or exists in the default location,
|
||||||
/// and the config is readable, the function will assume it is either
|
/// and the config is readable, the function will assume it is either
|
||||||
/// setuid or setgid, and will fork a child process to run the server
|
/// setuid or setgid, and will fork a child process to run the server
|
||||||
/// with the provided config. The server will exit silently by itself
|
/// with the provided config. The server will exit silently by itself
|
||||||
/// when it is done, and this function will only return for the client
|
/// when it is done, and this function will only return for the client
|
||||||
/// with the socket for the server.
|
/// with the socket for the server.
|
||||||
|
///
|
||||||
/// If neither of these options are available, the function will fail.
|
/// If neither of these options are available, the function will fail.
|
||||||
pub fn bootstrap_server_connection_and_drop_privileges(
|
pub fn bootstrap_server_connection_and_drop_privileges(
|
||||||
server_socket_path: Option<PathBuf>,
|
server_socket_path: Option<PathBuf>,
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -109,17 +109,17 @@ fn main() -> anyhow::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
#[cfg(feature = "mysql-admutils-compatibility")]
|
#[cfg(feature = "mysql-admutils-compatibility")]
|
||||||
if let Some(_) = handle_mysql_admutils_command()? {
|
if handle_mysql_admutils_command()?.is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let args: Args = Args::parse();
|
let args: Args = Args::parse();
|
||||||
|
|
||||||
if let Some(_) = handle_server_command(&args)? {
|
if handle_server_command(&args)?.is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = handle_generate_completions_command(&args)? {
|
if handle_generate_completions_command(&args)?.is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,8 @@ fn handle_mysql_admutils_command() -> anyhow::Result<Option<()>> {
|
||||||
});
|
});
|
||||||
|
|
||||||
match argv0.as_deref() {
|
match argv0.as_deref() {
|
||||||
Some("mysql-dbadm") => mysql_dbadm::main().map(|result| Some(result)),
|
Some("mysql-dbadm") => mysql_dbadm::main().map(Some),
|
||||||
Some("mysql-useradm") => mysql_useradm::main().map(|result| Some(result)),
|
Some("mysql-useradm") => mysql_useradm::main().map(Some),
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,4 @@ pub fn try_get_with_binary_fallback(
|
||||||
row.try_get::<Vec<u8>, _>(column)
|
row.try_get::<Vec<u8>, _>(column)
|
||||||
.map(|v| String::from_utf8_lossy(&v).to_string())
|
.map(|v| String::from_utf8_lossy(&v).to_string())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,7 @@ pub async fn create_mysql_connection_from_config(
|
||||||
) -> anyhow::Result<MySqlConnection> {
|
) -> anyhow::Result<MySqlConnection> {
|
||||||
log_config(config);
|
log_config(config);
|
||||||
|
|
||||||
let mut mysql_options = MySqlConnectOptions::new()
|
let mut mysql_options = MySqlConnectOptions::new().database("mysql");
|
||||||
.database("mysql");
|
|
||||||
|
|
||||||
if let Some(username) = &config.username {
|
if let Some(username) = &config.username {
|
||||||
mysql_options = mysql_options.username(username);
|
mysql_options = mysql_options.username(username);
|
||||||
|
@ -168,6 +167,8 @@ pub async fn create_mysql_connection_from_config(
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(connection) => connection.context("Failed to connect to the database"),
|
Ok(connection) => connection.context("Failed to connect to the database"),
|
||||||
Err(_) => Err(anyhow!("Timed out after 2 seconds")).context("Failed to connect to the database"),
|
Err(_) => {
|
||||||
|
Err(anyhow!("Timed out after 2 seconds")).context("Failed to connect to the database")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue