Files
muscl/src/core/protocol/commands/passwd_user.rs
h7x4 3f014f073e
All checks were successful
Build and test / build (push) Successful in 2m55s
Build and test / check (push) Successful in 3m4s
Build and test / test (push) Successful in 4m33s
Build and test / check-license (push) Successful in 5m35s
Build and test / docs (push) Successful in 8m23s
Rename AuthorizationError to ValidationError, rename suberrors
2025-12-15 14:56:53 +09:00

61 lines
1.8 KiB
Rust

use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::core::{
protocol::request_validation::ValidationError,
types::{DbOrUser, MySQLUser},
};
pub type SetUserPasswordRequest = (MySQLUser, String);
pub type SetUserPasswordResponse = Result<(), SetPasswordError>;
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SetPasswordError {
#[error("Validation error: {0}")]
ValidationError(#[from] ValidationError),
#[error("User does not exist")]
UserDoesNotExist,
#[error("MySQL error: {0}")]
MySqlError(String),
}
pub fn print_set_password_output_status(output: &SetUserPasswordResponse, username: &MySQLUser) {
match output {
Ok(()) => {
println!("Password for user '{}' set successfully.", username);
}
Err(err) => {
println!("{}", err.to_error_message(username));
println!("Skipping...");
}
}
}
impl SetPasswordError {
pub fn to_error_message(&self, username: &MySQLUser) -> String {
match self {
SetPasswordError::ValidationError(err) => {
err.to_error_message(DbOrUser::User(username.clone()))
}
SetPasswordError::UserDoesNotExist => {
format!("User '{}' does not exist.", username)
}
SetPasswordError::MySqlError(err) => {
format!("MySQL error: {}", err)
}
}
}
#[allow(dead_code)]
pub fn error_type(&self) -> String {
match self {
SetPasswordError::ValidationError(err) => err.error_type(),
SetPasswordError::UserDoesNotExist => "user-does-not-exist".to_string(),
SetPasswordError::MySqlError(_) => "mysql-error".to_string(),
}
}
}