client: add error subtypes for name and owner validation in json output
This commit is contained in:
@@ -79,11 +79,14 @@ impl CheckAuthorizationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CheckAuthorizationError::SanitizationError(_) => "sanitization-error",
|
CheckAuthorizationError::SanitizationError(err) => {
|
||||||
CheckAuthorizationError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
// CheckAuthorizationError::AuthorizationHandlerError(_) => "authorization-handler-error",
|
}
|
||||||
|
CheckAuthorizationError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
} // CheckAuthorizationError::AuthorizationHandlerError(_) => "authorization-handler-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,12 +75,16 @@ impl CreateDatabaseError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CreateDatabaseError::SanitizationError(_) => "sanitization-error",
|
CreateDatabaseError::SanitizationError(err) => {
|
||||||
CreateDatabaseError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
CreateDatabaseError::DatabaseAlreadyExists => "database-already-exists",
|
}
|
||||||
CreateDatabaseError::MySqlError(_) => "mysql-error",
|
CreateDatabaseError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
}
|
||||||
|
CreateDatabaseError::DatabaseAlreadyExists => "database-already-exists".to_string(),
|
||||||
|
CreateDatabaseError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,12 +75,14 @@ impl CreateUserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CreateUserError::SanitizationError(_) => "sanitization-error",
|
CreateUserError::SanitizationError(err) => {
|
||||||
CreateUserError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
CreateUserError::UserAlreadyExists => "user-already-exists",
|
}
|
||||||
CreateUserError::MySqlError(_) => "mysql-error",
|
CreateUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
|
||||||
|
CreateUserError::UserAlreadyExists => "user-already-exists".to_string(),
|
||||||
|
CreateUserError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,12 +78,16 @@ impl DropDatabaseError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
DropDatabaseError::SanitizationError(_) => "sanitization-error",
|
DropDatabaseError::SanitizationError(err) => {
|
||||||
DropDatabaseError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
DropDatabaseError::DatabaseDoesNotExist => "database-does-not-exist",
|
}
|
||||||
DropDatabaseError::MySqlError(_) => "mysql-error",
|
DropDatabaseError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
}
|
||||||
|
DropDatabaseError::DatabaseDoesNotExist => "database-does-not-exist".to_string(),
|
||||||
|
DropDatabaseError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,12 +75,14 @@ impl DropUserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
DropUserError::SanitizationError(_) => "sanitization-error",
|
DropUserError::SanitizationError(err) => {
|
||||||
DropUserError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
DropUserError::UserDoesNotExist => "user-does-not-exist",
|
}
|
||||||
DropUserError::MySqlError(_) => "mysql-error",
|
DropUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
|
||||||
|
DropUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
|
||||||
|
DropUserError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,11 @@ impl ListAllDatabasesError {
|
|||||||
ListAllDatabasesError::MySqlError(err) => format!("MySQL error: {}", err),
|
ListAllDatabasesError::MySqlError(err) => format!("MySQL error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn error_type(&self) -> String {
|
||||||
|
match self {
|
||||||
|
ListAllDatabasesError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,11 @@ impl GetAllDatabasesPrivilegeDataError {
|
|||||||
GetAllDatabasesPrivilegeDataError::MySqlError(err) => format!("MySQL error: {}", err),
|
GetAllDatabasesPrivilegeDataError::MySqlError(err) => format!("MySQL error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn error_type(&self) -> String {
|
||||||
|
match self {
|
||||||
|
GetAllDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,11 @@ impl ListAllUsersError {
|
|||||||
ListAllUsersError::MySqlError(err) => format!("MySQL error: {}", err),
|
ListAllUsersError::MySqlError(err) => format!("MySQL error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn error_type(&self) -> String {
|
||||||
|
match self {
|
||||||
|
ListAllUsersError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,12 +94,16 @@ impl ListDatabasesError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
ListDatabasesError::SanitizationError(_) => "sanitization-error",
|
ListDatabasesError::SanitizationError(err) => {
|
||||||
ListDatabasesError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
ListDatabasesError::DatabaseDoesNotExist => "database-does-not-exist",
|
}
|
||||||
ListDatabasesError::MySqlError(_) => "mysql-error",
|
ListDatabasesError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
}
|
||||||
|
ListDatabasesError::DatabaseDoesNotExist => "database-does-not-exist".to_string(),
|
||||||
|
ListDatabasesError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,12 +128,18 @@ impl GetDatabasesPrivilegeDataError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
GetDatabasesPrivilegeDataError::SanitizationError(_) => "sanitization-error",
|
GetDatabasesPrivilegeDataError::SanitizationError(err) => {
|
||||||
GetDatabasesPrivilegeDataError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => "database-does-not-exist",
|
}
|
||||||
GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error",
|
GetDatabasesPrivilegeDataError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
}
|
||||||
|
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
|
||||||
|
"database-does-not-exist".to_string()
|
||||||
|
}
|
||||||
|
GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,12 +109,14 @@ impl ListUsersError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
ListUsersError::SanitizationError(_) => "sanitization-error",
|
ListUsersError::SanitizationError(err) => {
|
||||||
ListUsersError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
ListUsersError::UserDoesNotExist => "user-does-not-exist",
|
}
|
||||||
ListUsersError::MySqlError(_) => "mysql-error",
|
ListUsersError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
|
||||||
|
ListUsersError::UserDoesNotExist => "user-does-not-exist".to_string(),
|
||||||
|
ListUsersError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ impl LockUserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
LockUserError::SanitizationError(_) => "sanitization-error",
|
LockUserError::SanitizationError(err) => {
|
||||||
LockUserError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
LockUserError::UserDoesNotExist => "user-does-not-exist",
|
}
|
||||||
LockUserError::UserIsAlreadyLocked => "user-is-already-locked",
|
LockUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
|
||||||
LockUserError::MySqlError(_) => "mysql-error",
|
LockUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
|
||||||
|
LockUserError::UserIsAlreadyLocked => "user-is-already-locked".to_string(),
|
||||||
|
LockUserError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,27 +81,27 @@ impl ModifyDatabasePrivilegesError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
ModifyDatabasePrivilegesError::DatabaseSanitizationError(_) => {
|
ModifyDatabasePrivilegesError::DatabaseSanitizationError(err) => {
|
||||||
"database-sanitization-error"
|
format!("database-sanitization-error/{}", err.error_type())
|
||||||
}
|
}
|
||||||
ModifyDatabasePrivilegesError::DatabaseOwnershipError(_) => "database-ownership-error",
|
ModifyDatabasePrivilegesError::DatabaseOwnershipError(err) => {
|
||||||
ModifyDatabasePrivilegesError::UserSanitizationError(_) => "user-sanitization-error",
|
format!("database-ownership-error/{}", err.error_type())
|
||||||
ModifyDatabasePrivilegesError::UserOwnershipError(_) => "user-ownership-error",
|
}
|
||||||
ModifyDatabasePrivilegesError::DatabaseDoesNotExist => "database-does-not-exist",
|
ModifyDatabasePrivilegesError::UserSanitizationError(err) => {
|
||||||
ModifyDatabasePrivilegesError::DiffDoesNotApply(err) => match err {
|
format!("user-sanitization-error/{}", err.error_type())
|
||||||
DiffDoesNotApplyError::RowAlreadyExists(_, _) => {
|
}
|
||||||
"diff-does-not-apply/row-already-exists"
|
ModifyDatabasePrivilegesError::UserOwnershipError(err) => {
|
||||||
}
|
format!("user-ownership-error/{}", err.error_type())
|
||||||
DiffDoesNotApplyError::RowDoesNotExist(_, _) => {
|
}
|
||||||
"diff-does-not-apply/row-does-not-exist"
|
ModifyDatabasePrivilegesError::DatabaseDoesNotExist => {
|
||||||
}
|
"database-does-not-exist".to_string()
|
||||||
DiffDoesNotApplyError::RowPrivilegeChangeDoesNotApply(_, _) => {
|
}
|
||||||
"diff-does-not-apply/row-privilege-change-does-not-apply"
|
ModifyDatabasePrivilegesError::DiffDoesNotApply(err) => {
|
||||||
}
|
format!("diff-does-not-apply/{}", err.error_type())
|
||||||
},
|
}
|
||||||
ModifyDatabasePrivilegesError::MySqlError(_) => "mysql-error",
|
ModifyDatabasePrivilegesError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,4 +129,14 @@ impl DiffDoesNotApplyError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn error_type(&self) -> String {
|
||||||
|
match self {
|
||||||
|
DiffDoesNotApplyError::RowAlreadyExists(_, _) => "row-already-exists".to_string(),
|
||||||
|
DiffDoesNotApplyError::RowDoesNotExist(_, _) => "row-does-not-exist".to_string(),
|
||||||
|
DiffDoesNotApplyError::RowPrivilegeChangeDoesNotApply(_, _) => {
|
||||||
|
"row-privilege-change-does-not-apply".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,12 +48,16 @@ impl SetPasswordError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
SetPasswordError::SanitizationError(_) => "sanitization-error",
|
SetPasswordError::SanitizationError(err) => {
|
||||||
SetPasswordError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
SetPasswordError::UserDoesNotExist => "user-does-not-exist",
|
}
|
||||||
SetPasswordError::MySqlError(_) => "mysql-error",
|
SetPasswordError::OwnershipError(err) => {
|
||||||
|
format!("ownership-error/{}", err.error_type())
|
||||||
|
}
|
||||||
|
SetPasswordError::UserDoesNotExist => "user-does-not-exist".to_string(),
|
||||||
|
SetPasswordError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ impl UnlockUserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_type(&self) -> &'static str {
|
pub fn error_type(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
UnlockUserError::SanitizationError(_) => "sanitization-error",
|
UnlockUserError::SanitizationError(err) => {
|
||||||
UnlockUserError::OwnershipError(_) => "ownership-error",
|
format!("sanitization-error/{}", err.error_type())
|
||||||
UnlockUserError::UserDoesNotExist => "user-does-not-exist",
|
}
|
||||||
UnlockUserError::UserIsAlreadyUnlocked => "user-is-already-unlocked",
|
UnlockUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
|
||||||
UnlockUserError::MySqlError(_) => "mysql-error",
|
UnlockUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
|
||||||
|
UnlockUserError::UserIsAlreadyUnlocked => "user-is-already-unlocked".to_string(),
|
||||||
|
UnlockUserError::MySqlError(_) => "mysql-error".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ impl NameValidationError {
|
|||||||
.to_owned(),
|
.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn error_type(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
NameValidationError::EmptyString => "empty-string",
|
||||||
|
NameValidationError::InvalidCharacters => "invalid-characters",
|
||||||
|
NameValidationError::TooLong => "too-long",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OwnerValidationError {
|
impl OwnerValidationError {
|
||||||
@@ -81,6 +89,13 @@ impl OwnerValidationError {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn error_type(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
OwnerValidationError::NoMatch => "no-match",
|
||||||
|
OwnerValidationError::StringEmpty => "string-empty",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user