cargo fmt + clippy
This commit is contained in:
parent
fb7391a29c
commit
21c2fc2e8b
|
@ -1,3 +1,3 @@
|
||||||
pub mod database_command;
|
pub mod database_command;
|
||||||
pub mod user_command;
|
|
||||||
pub mod mysql_admutils_compatibility;
|
pub mod mysql_admutils_compatibility;
|
||||||
|
pub mod user_command;
|
||||||
|
|
|
@ -11,7 +11,8 @@ use crate::core::{
|
||||||
database_operations::{
|
database_operations::{
|
||||||
apply_permission_diffs, db_priv_field_human_readable_name, diff_permissions, yn,
|
apply_permission_diffs, db_priv_field_human_readable_name, diff_permissions, yn,
|
||||||
DatabasePrivileges, DATABASE_PRIVILEGE_FIELDS,
|
DatabasePrivileges, DATABASE_PRIVILEGE_FIELDS,
|
||||||
}, user_operations::user_exists,
|
},
|
||||||
|
user_operations::user_exists,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Support batch creation/dropping,showing of databases,
|
// TODO: Support batch creation/dropping,showing of databases,
|
||||||
|
@ -520,10 +521,10 @@ pub async fn edit_permissions(
|
||||||
};
|
};
|
||||||
|
|
||||||
for row in permissions_to_change.iter() {
|
for row in permissions_to_change.iter() {
|
||||||
if !user_exists(&row.user, conn).await? {
|
if !user_exists(&row.user, conn).await? {
|
||||||
// TODO: allow user to return and correct their mistake
|
// TODO: allow user to return and correct their mistake
|
||||||
anyhow::bail!("User {} does not exist", row.user);
|
anyhow::bail!("User {} does not exist", row.user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let diffs = diff_permissions(permission_data, &permissions_to_change).await;
|
let diffs = diff_permissions(permission_data, &permissions_to_change).await;
|
||||||
|
|
|
@ -54,12 +54,7 @@ pub struct Args {
|
||||||
/// This is a compatibility layer for the mysql-dbadm command.
|
/// This is a compatibility layer for the mysql-dbadm command.
|
||||||
/// Please consider using the newer mysqladm command instead.
|
/// Please consider using the newer mysqladm command instead.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(
|
#[command(version, about, disable_help_subcommand = true, verbatim_doc_comment)]
|
||||||
version,
|
|
||||||
about,
|
|
||||||
disable_help_subcommand = true,
|
|
||||||
verbatim_doc_comment,
|
|
||||||
)]
|
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// create the DATABASE(s).
|
/// create the DATABASE(s).
|
||||||
Create(CreateArgs),
|
Create(CreateArgs),
|
||||||
|
@ -73,7 +68,6 @@ pub enum Command {
|
||||||
|
|
||||||
// TODO: make this output more verbatim_doc_comment-like,
|
// TODO: make this output more verbatim_doc_comment-like,
|
||||||
// without messing up the indentation.
|
// without messing up the indentation.
|
||||||
|
|
||||||
/// change permissions for the DATABASE(s). Your
|
/// change permissions for the DATABASE(s). Your
|
||||||
/// favorite editor will be started, allowing you
|
/// favorite editor will be started, allowing you
|
||||||
/// to make changes to the permission table.
|
/// to make changes to the permission table.
|
||||||
|
|
|
@ -71,7 +71,10 @@ pub fn validate_name_token(name: &str) -> anyhow::Result<()> {
|
||||||
anyhow::bail!("Database name is too long. Maximum length is 64 characters.");
|
anyhow::bail!("Database name is too long. Maximum length is 64 characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-') {
|
if !name
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
|
||||||
|
{
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
indoc! {r#"
|
indoc! {r#"
|
||||||
Invalid characters in name: '{}'
|
Invalid characters in name: '{}'
|
||||||
|
@ -85,7 +88,10 @@ pub fn validate_name_token(name: &str) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate_ownership_by_user_prefix<'a>(name: &'a str, user: &User) -> anyhow::Result<&'a str> {
|
pub fn validate_ownership_by_user_prefix<'a>(
|
||||||
|
name: &'a str,
|
||||||
|
user: &User,
|
||||||
|
) -> anyhow::Result<&'a str> {
|
||||||
let user_groups = get_unix_groups(user)?;
|
let user_groups = get_unix_groups(user)?;
|
||||||
|
|
||||||
let mut split_name = name.split('_');
|
let mut split_name = name.split('_');
|
||||||
|
|
|
@ -8,7 +8,8 @@ use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{mysql::MySqlRow, prelude::*, MySqlConnection};
|
use sqlx::{mysql::MySqlRow, prelude::*, MySqlConnection};
|
||||||
|
|
||||||
use super::common::{
|
use super::common::{
|
||||||
create_user_group_matching_regex, get_current_unix_user, quote_identifier, validate_name_token, validate_ownership_by_user_prefix
|
create_user_group_matching_regex, get_current_unix_user, quote_identifier, validate_name_token,
|
||||||
|
validate_ownership_by_user_prefix,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn create_database(name: &str, conn: &mut MySqlConnection) -> anyhow::Result<()> {
|
pub async fn create_database(name: &str, conn: &mut MySqlConnection) -> anyhow::Result<()> {
|
||||||
|
|
|
@ -5,7 +5,10 @@ use sqlx::{prelude::*, MySqlConnection};
|
||||||
|
|
||||||
use crate::core::common::quote_literal;
|
use crate::core::common::quote_literal;
|
||||||
|
|
||||||
use super::common::{create_user_group_matching_regex, get_current_unix_user, validate_name_token, validate_ownership_by_user_prefix};
|
use super::common::{
|
||||||
|
create_user_group_matching_regex, get_current_unix_user, validate_name_token,
|
||||||
|
validate_ownership_by_user_prefix,
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn user_exists(db_user: &str, conn: &mut MySqlConnection) -> anyhow::Result<bool> {
|
pub async fn user_exists(db_user: &str, conn: &mut MySqlConnection) -> anyhow::Result<bool> {
|
||||||
let unix_user = get_current_unix_user()?;
|
let unix_user = get_current_unix_user()?;
|
||||||
|
@ -102,11 +105,11 @@ pub async fn password_is_set_for_database_user(
|
||||||
validate_user_name(db_user, &unix_user)?;
|
validate_user_name(db_user, &unix_user)?;
|
||||||
|
|
||||||
let user_has_password = sqlx::query_as::<_, PasswordIsSet>(
|
let user_has_password = sqlx::query_as::<_, PasswordIsSet>(
|
||||||
"SELECT authentication_string != '' FROM mysql.user WHERE User = ?"
|
"SELECT authentication_string != '' FROM mysql.user WHERE User = ?",
|
||||||
)
|
)
|
||||||
.bind(db_user)
|
.bind(db_user)
|
||||||
.fetch_optional(conn)
|
.fetch_optional(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(user_has_password.map(|PasswordIsSet(is_set)| is_set))
|
Ok(user_has_password.map(|PasswordIsSet(is_set)| is_set))
|
||||||
}
|
}
|
||||||
|
@ -167,7 +170,8 @@ pub async fn get_database_user_for_user(
|
||||||
/// to validate the database name ourselves to prevent SQL injection.
|
/// to validate the database name ourselves to prevent SQL injection.
|
||||||
pub fn validate_user_name(name: &str, user: &User) -> anyhow::Result<()> {
|
pub fn validate_user_name(name: &str, user: &User) -> anyhow::Result<()> {
|
||||||
validate_name_token(name).context(format!("Invalid username: '{}'", name))?;
|
validate_name_token(name).context(format!("Invalid username: '{}'", name))?;
|
||||||
validate_ownership_by_user_prefix(name, user).context(format!("Invalid username: '{}'", name))?;
|
validate_ownership_by_user_prefix(name, user)
|
||||||
|
.context(format!("Invalid username: '{}'", name))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue