core: move DbOrUser to types, wrap item name in struct

This commit is contained in:
2025-11-29 18:59:11 +09:00
parent 877f45c103
commit 03ddf0ac8a
14 changed files with 140 additions and 106 deletions

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLDatabase,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLDatabase},
};
pub type CreateDatabasesRequest = Vec<MySQLDatabase>;
@@ -60,10 +60,10 @@ impl CreateDatabaseError {
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
match self {
CreateDatabaseError::SanitizationError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
CreateDatabaseError::OwnershipError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
CreateDatabaseError::DatabaseAlreadyExists => {
format!("Database {} already exists.", database_name)

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
};
pub type CreateUsersRequest = Vec<MySQLUser>;
@@ -60,9 +60,11 @@ impl CreateUserError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
CreateUserError::SanitizationError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
CreateUserError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
CreateUserError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
CreateUserError::UserAlreadyExists => {
format!("User '{}' already exists.", username)
}

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLDatabase,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLDatabase},
};
pub type DropDatabasesRequest = Vec<MySQLDatabase>;
@@ -63,10 +63,10 @@ impl DropDatabaseError {
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
match self {
DropDatabaseError::SanitizationError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
DropDatabaseError::OwnershipError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
DropDatabaseError::DatabaseDoesNotExist => {
format!("Database {} does not exist.", database_name)

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
};
pub type DropUsersRequest = Vec<MySQLUser>;
@@ -59,8 +59,12 @@ pub fn print_drop_users_output_status_json(output: &DropUsersResponse) {
impl DropUserError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
DropUserError::SanitizationError(err) => err.to_error_message(username, DbOrUser::User),
DropUserError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
DropUserError::SanitizationError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
DropUserError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
DropUserError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use crate::{
core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLDatabase,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLDatabase},
},
server::sql::database_operations::DatabaseRow,
};
@@ -26,10 +26,10 @@ impl ListDatabasesError {
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
match self {
ListDatabasesError::SanitizationError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
ListDatabasesError::OwnershipError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
ListDatabasesError::DatabaseDoesNotExist => {
format!("Database '{}' does not exist.", database_name)

View File

@@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
use crate::core::{
database_privileges::DatabasePrivilegeRow,
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLDatabase,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLDatabase},
};
pub type ListPrivilegesRequest = Option<Vec<MySQLDatabase>>;
@@ -29,10 +29,10 @@ impl GetDatabasesPrivilegeDataError {
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
match self {
GetDatabasesPrivilegeDataError::SanitizationError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
GetDatabasesPrivilegeDataError::OwnershipError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
format!("Database '{}' does not exist.", database_name)

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use crate::{
core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
},
server::sql::user_operations::DatabaseUser,
};
@@ -26,9 +26,11 @@ impl ListUsersError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
ListUsersError::SanitizationError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
ListUsersError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
ListUsersError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
ListUsersError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
};
pub type LockUsersRequest = Vec<MySQLUser>;
@@ -60,8 +60,12 @@ pub fn print_lock_users_output_status_json(output: &LockUsersResponse) {
impl LockUserError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
LockUserError::SanitizationError(err) => err.to_error_message(username, DbOrUser::User),
LockUserError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
LockUserError::SanitizationError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
LockUserError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
LockUserError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use crate::core::{
database_privileges::{DatabasePrivilegeRow, DatabasePrivilegeRowDiff, DatabasePrivilegesDiff},
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::{MySQLDatabase, MySQLUser},
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLDatabase, MySQLUser},
};
pub type ModifyPrivilegesRequest = BTreeSet<DatabasePrivilegesDiff>;
@@ -54,16 +54,16 @@ impl ModifyDatabasePrivilegesError {
pub fn to_error_message(&self, database_name: &MySQLDatabase, username: &MySQLUser) -> String {
match self {
ModifyDatabasePrivilegesError::DatabaseSanitizationError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
ModifyDatabasePrivilegesError::DatabaseOwnershipError(err) => {
err.to_error_message(database_name, DbOrUser::Database)
err.to_error_message(DbOrUser::Database(database_name.clone()))
}
ModifyDatabasePrivilegesError::UserSanitizationError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
ModifyDatabasePrivilegesError::UserOwnershipError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
ModifyDatabasePrivilegesError::DatabaseDoesNotExist => {
format!("Database '{}' does not exist.", database_name)

View File

@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
};
pub type SetUserPasswordRequest = (MySQLUser, String);
@@ -33,9 +33,11 @@ impl SetPasswordError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
SetPasswordError::SanitizationError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
SetPasswordError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
SetPasswordError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
SetPasswordError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}

View File

@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use crate::core::{
protocol::request_validation::{DbOrUser, NameValidationError, OwnerValidationError},
types::MySQLUser,
protocol::request_validation::{NameValidationError, OwnerValidationError},
types::{DbOrUser, MySQLUser},
};
pub type UnlockUsersRequest = Vec<MySQLUser>;
@@ -61,9 +61,11 @@ impl UnlockUserError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
UnlockUserError::SanitizationError(err) => {
err.to_error_message(username, DbOrUser::User)
err.to_error_message(DbOrUser::User(username.clone()))
}
UnlockUserError::OwnershipError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
UnlockUserError::OwnershipError(err) => err.to_error_message(username, DbOrUser::User),
UnlockUserError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}