Fix protocol error struct name for List(All)PrivilegesError
Some checks failed
Some checks failed
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::{
|
|||||||
core::{
|
core::{
|
||||||
completion::mysql_database_completer,
|
completion::mysql_database_completer,
|
||||||
protocol::{
|
protocol::{
|
||||||
ClientToServerMessageStream, GetDatabasesPrivilegeDataError, Request, Response,
|
ClientToServerMessageStream, ListPrivilegesError, Request, Response,
|
||||||
print_list_privileges_output_status, print_list_privileges_output_status_json,
|
print_list_privileges_output_status, print_list_privileges_output_status_json,
|
||||||
request_validation::ValidationError,
|
request_validation::ValidationError,
|
||||||
},
|
},
|
||||||
@@ -77,7 +77,7 @@ pub async fn show_database_privileges(
|
|||||||
if privilege_data.iter().any(|(_, res)| {
|
if privilege_data.iter().any(|(_, res)| {
|
||||||
matches!(
|
matches!(
|
||||||
res,
|
res,
|
||||||
Err(GetDatabasesPrivilegeDataError::ValidationError(
|
Err(ListPrivilegesError::ValidationError(
|
||||||
ValidationError::AuthorizationError(_)
|
ValidationError::AuthorizationError(_)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::core::{
|
use crate::core::{
|
||||||
protocol::{
|
protocol::{
|
||||||
CreateDatabaseError, CreateUserError, DropDatabaseError, DropUserError,
|
CreateDatabaseError, CreateUserError, DropDatabaseError, DropUserError,
|
||||||
GetDatabasesPrivilegeDataError, ListUsersError, request_validation::ValidationError,
|
ListPrivilegesError, ListUsersError, request_validation::ValidationError,
|
||||||
},
|
},
|
||||||
types::DbOrUser,
|
types::DbOrUser,
|
||||||
};
|
};
|
||||||
@@ -161,28 +161,25 @@ pub fn handle_drop_database_error(error: DropDatabaseError, name: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_show_database_error_message(
|
pub fn format_show_database_error_message(error: ListPrivilegesError, name: &str) -> String {
|
||||||
error: GetDatabasesPrivilegeDataError,
|
|
||||||
name: &str,
|
|
||||||
) -> String {
|
|
||||||
let argv0 = std::env::args()
|
let argv0 = std::env::args()
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or_else(|| "mysql-dbadm".to_string());
|
.unwrap_or_else(|| "mysql-dbadm".to_string());
|
||||||
|
|
||||||
match error {
|
match error {
|
||||||
GetDatabasesPrivilegeDataError::ValidationError(ValidationError::NameValidationError(
|
ListPrivilegesError::ValidationError(ValidationError::NameValidationError(_)) => {
|
||||||
_,
|
name_validation_error_to_error_message(DbOrUser::Database(name.into()))
|
||||||
)) => name_validation_error_to_error_message(DbOrUser::Database(name.into())),
|
}
|
||||||
GetDatabasesPrivilegeDataError::ValidationError(ValidationError::AuthorizationError(_)) => {
|
ListPrivilegesError::ValidationError(ValidationError::AuthorizationError(_)) => {
|
||||||
authorization_error_message(DbOrUser::Database(name.into()))
|
authorization_error_message(DbOrUser::Database(name.into()))
|
||||||
}
|
}
|
||||||
GetDatabasesPrivilegeDataError::MySqlError(err) => {
|
ListPrivilegesError::MySqlError(err) => {
|
||||||
format!(
|
format!(
|
||||||
"{}: Failed to look up privileges for database '{}': {}",
|
"{}: Failed to look up privileges for database '{}': {}",
|
||||||
argv0, name, err
|
argv0, name, err
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
|
ListPrivilegesError::DatabaseDoesNotExist => {
|
||||||
format!("{}: Database '{}' doesn't exist.", argv0, name)
|
format!("{}: Database '{}' doesn't exist.", argv0, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use crate::{
|
|||||||
completion::mysql_database_completer,
|
completion::mysql_database_completer,
|
||||||
database_privileges::DatabasePrivilegeRow,
|
database_privileges::DatabasePrivilegeRow,
|
||||||
protocol::{
|
protocol::{
|
||||||
ClientToServerMessageStream, GetDatabasesPrivilegeDataError, Request, Response,
|
ClientToServerMessageStream, ListPrivilegesError, Request, Response,
|
||||||
create_client_to_server_message_stream,
|
create_client_to_server_message_stream,
|
||||||
},
|
},
|
||||||
types::MySQLDatabase,
|
types::MySQLDatabase,
|
||||||
@@ -314,7 +314,7 @@ async fn show_databases(
|
|||||||
.map(
|
.map(
|
||||||
|(name, rows)| match rows.map(|rows| (name.to_owned(), rows)) {
|
|(name, rows)| match rows.map(|rows| (name.to_owned(), rows)) {
|
||||||
Ok(rows) => Ok(rows),
|
Ok(rows) => Ok(rows),
|
||||||
Err(GetDatabasesPrivilegeDataError::DatabaseDoesNotExist) => Ok((name, vec![])),
|
Err(ListPrivilegesError::DatabaseDoesNotExist) => Ok((name, vec![])),
|
||||||
Err(err) => Err(format_show_database_error_message(err, &name)),
|
Err(err) => Err(format_show_database_error_message(err, &name)),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,26 +3,25 @@ use thiserror::Error;
|
|||||||
|
|
||||||
use crate::core::database_privileges::DatabasePrivilegeRow;
|
use crate::core::database_privileges::DatabasePrivilegeRow;
|
||||||
|
|
||||||
pub type ListAllPrivilegesResponse =
|
pub type ListAllPrivilegesResponse = Result<Vec<DatabasePrivilegeRow>, ListAllPrivilegesError>;
|
||||||
Result<Vec<DatabasePrivilegeRow>, GetAllDatabasesPrivilegeDataError>;
|
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum GetAllDatabasesPrivilegeDataError {
|
pub enum ListAllPrivilegesError {
|
||||||
#[error("MySQL error: {0}")]
|
#[error("MySQL error: {0}")]
|
||||||
MySqlError(String),
|
MySqlError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetAllDatabasesPrivilegeDataError {
|
impl ListAllPrivilegesError {
|
||||||
pub fn to_error_message(&self) -> String {
|
pub fn to_error_message(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
GetAllDatabasesPrivilegeDataError::MySqlError(err) => format!("MySQL error: {}", err),
|
ListAllPrivilegesError::MySqlError(err) => format!("MySQL error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn error_type(&self) -> String {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
GetAllDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
|
ListAllPrivilegesError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use crate::core::{
|
|||||||
pub type ListPrivilegesRequest = Option<Vec<MySQLDatabase>>;
|
pub type ListPrivilegesRequest = Option<Vec<MySQLDatabase>>;
|
||||||
|
|
||||||
pub type ListPrivilegesResponse =
|
pub type ListPrivilegesResponse =
|
||||||
BTreeMap<MySQLDatabase, Result<Vec<DatabasePrivilegeRow>, GetDatabasesPrivilegeDataError>>;
|
BTreeMap<MySQLDatabase, Result<Vec<DatabasePrivilegeRow>, ListPrivilegesError>>;
|
||||||
|
|
||||||
pub fn print_list_privileges_output_status(output: &ListPrivilegesResponse, long_names: bool) {
|
pub fn print_list_privileges_output_status(output: &ListPrivilegesResponse, long_names: bool) {
|
||||||
let mut final_privs_map: BTreeMap<MySQLDatabase, Vec<DatabasePrivilegeRow>> = BTreeMap::new();
|
let mut final_privs_map: BTreeMap<MySQLDatabase, Vec<DatabasePrivilegeRow>> = BTreeMap::new();
|
||||||
@@ -117,7 +117,7 @@ pub fn print_list_privileges_output_status_json(output: &ListPrivilegesResponse)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum GetDatabasesPrivilegeDataError {
|
pub enum ListPrivilegesError {
|
||||||
#[error("Validation error: {0}")]
|
#[error("Validation error: {0}")]
|
||||||
ValidationError(#[from] ValidationError),
|
ValidationError(#[from] ValidationError),
|
||||||
|
|
||||||
@@ -128,16 +128,16 @@ pub enum GetDatabasesPrivilegeDataError {
|
|||||||
MySqlError(String),
|
MySqlError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetDatabasesPrivilegeDataError {
|
impl ListPrivilegesError {
|
||||||
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
|
pub fn to_error_message(&self, database_name: &MySQLDatabase) -> String {
|
||||||
match self {
|
match self {
|
||||||
GetDatabasesPrivilegeDataError::ValidationError(err) => {
|
ListPrivilegesError::ValidationError(err) => {
|
||||||
err.to_error_message(DbOrUser::Database(database_name.clone()))
|
err.to_error_message(DbOrUser::Database(database_name.clone()))
|
||||||
}
|
}
|
||||||
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
|
ListPrivilegesError::DatabaseDoesNotExist => {
|
||||||
format!("Database '{}' does not exist.", database_name)
|
format!("Database '{}' does not exist.", database_name)
|
||||||
}
|
}
|
||||||
GetDatabasesPrivilegeDataError::MySqlError(err) => {
|
ListPrivilegesError::MySqlError(err) => {
|
||||||
format!("MySQL error: {}", err)
|
format!("MySQL error: {}", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,11 +145,9 @@ impl GetDatabasesPrivilegeDataError {
|
|||||||
|
|
||||||
pub fn error_type(&self) -> String {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
GetDatabasesPrivilegeDataError::ValidationError(err) => err.error_type(),
|
ListPrivilegesError::ValidationError(err) => err.error_type(),
|
||||||
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
|
ListPrivilegesError::DatabaseDoesNotExist => "database-does-not-exist".to_string(),
|
||||||
"database-does-not-exist".to_string()
|
ListPrivilegesError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
|
||||||
GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ use crate::{
|
|||||||
DatabasePrivilegesDiff,
|
DatabasePrivilegesDiff,
|
||||||
},
|
},
|
||||||
protocol::{
|
protocol::{
|
||||||
DiffDoesNotApplyError, GetAllDatabasesPrivilegeDataError,
|
DiffDoesNotApplyError, ListAllPrivilegesError, ListAllPrivilegesResponse,
|
||||||
GetDatabasesPrivilegeDataError, ListAllPrivilegesResponse, ListPrivilegesResponse,
|
ListPrivilegesError, ListPrivilegesResponse, ModifyDatabasePrivilegesError,
|
||||||
ModifyDatabasePrivilegesError, ModifyPrivilegesResponse,
|
ModifyPrivilegesResponse,
|
||||||
request_validation::{GroupDenylist, validate_db_or_user_request},
|
request_validation::{GroupDenylist, validate_db_or_user_request},
|
||||||
},
|
},
|
||||||
types::{DbOrUser, MySQLDatabase, MySQLUser},
|
types::{DbOrUser, MySQLDatabase, MySQLUser},
|
||||||
@@ -153,7 +153,7 @@ pub async fn get_databases_privilege_data(
|
|||||||
unix_user,
|
unix_user,
|
||||||
group_denylist,
|
group_denylist,
|
||||||
)
|
)
|
||||||
.map_err(GetDatabasesPrivilegeDataError::ValidationError)
|
.map_err(ListPrivilegesError::ValidationError)
|
||||||
{
|
{
|
||||||
results.insert(database_name.to_owned(), Err(err));
|
results.insert(database_name.to_owned(), Err(err));
|
||||||
continue;
|
continue;
|
||||||
@@ -165,14 +165,14 @@ pub async fn get_databases_privilege_data(
|
|||||||
{
|
{
|
||||||
results.insert(
|
results.insert(
|
||||||
database_name.to_owned(),
|
database_name.to_owned(),
|
||||||
Err(GetDatabasesPrivilegeDataError::DatabaseDoesNotExist),
|
Err(ListPrivilegesError::DatabaseDoesNotExist),
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = unsafe_get_database_privileges(database_name, connection)
|
let result = unsafe_get_database_privileges(database_name, connection)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| GetDatabasesPrivilegeDataError::MySqlError(e.to_string()));
|
.map_err(|e| ListPrivilegesError::MySqlError(e.to_string()));
|
||||||
|
|
||||||
results.insert(database_name.to_owned(), result);
|
results.insert(database_name.to_owned(), result);
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ pub async fn get_all_database_privileges(
|
|||||||
.bind(create_user_group_matching_regex(unix_user, group_denylist))
|
.bind(create_user_group_matching_regex(unix_user, group_denylist))
|
||||||
.fetch_all(connection)
|
.fetch_all(connection)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| GetAllDatabasesPrivilegeDataError::MySqlError(e.to_string()));
|
.map_err(|e| ListAllPrivilegesError::MySqlError(e.to_string()));
|
||||||
|
|
||||||
if let Err(e) = &result {
|
if let Err(e) = &result {
|
||||||
tracing::error!("Failed to get all database privileges: {:?}", e);
|
tracing::error!("Failed to get all database privileges: {:?}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user