Files
muscl/src/core/protocol/commands/passwd_user.rs
h7x4 4c3677d6d3
All checks were successful
Build and test / docs (push) Successful in 7m1s
Build and test / check-license (push) Successful in 57s
Build and test / check (push) Successful in 2m46s
Build and test / build (push) Successful in 3m12s
Build and test / test (push) Successful in 3m25s
clippy pedantic fix + get rid of a few unwraps
2025-12-23 14:12:39 +09:00

63 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 '{username}' set successfully.");
}
Err(err) => {
eprintln!("{}", err.to_error_message(username));
eprintln!("Skipping...");
}
}
}
impl SetPasswordError {
#[must_use]
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 '{username}' does not exist.")
}
SetPasswordError::MySqlError(err) => {
format!("MySQL error: {err}")
}
}
}
#[allow(dead_code)]
#[must_use]
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(),
}
}
}