use crate::policy; #[derive(thiserror::Error, Debug)] pub enum Error { #[error(transparent)] PolicyError(#[from] policy::Error), #[error("ecsotre error: {0}")] EcstoreError(ecstore::error::Error), #[error("{0}")] StringError(String), #[error("crypto: {0}")] CryptoError(#[from] crypto::Error), #[error("user '{0}' does not exist")] NoSuchUser(String), #[error("account '{0}' does not exist")] NoSuchAccount(String), #[error("service account '{0}' does not exist")] NoSuchServiceAccount(String), #[error("temp account '{0}' does not exist")] NoSuchTempAccount(String), #[error("group '{0}' does not exist")] NoSuchGroup(String), #[error("policy does not exist")] NoSuchPolicy, #[error("policy in use")] PolicyInUse, #[error("group not empty")] GroupNotEmpty, #[error("invalid arguments specified")] InvalidArgument, #[error("not initialized")] IamSysNotInitialized, #[error("invalid service type: {0}")] InvalidServiceType(String), #[error("malformed credential")] ErrCredMalformed, #[error("CredNotInitialized")] CredNotInitialized, #[error("invalid access key length")] InvalidAccessKeyLength, #[error("invalid secret key length")] InvalidSecretKeyLength, #[error("access key contains reserved characters =,")] ContainsReservedChars, #[error("group name contains reserved characters =,")] GroupNameContainsReservedChars, #[error("jwt err {0}")] JWTError(jsonwebtoken::errors::Error), #[error("no access key")] NoAccessKey, #[error("invalid token")] InvalidToken, #[error("invalid access_key")] InvalidAccessKey, #[error("action not allowed")] IAMActionNotAllowed, #[error("no secret key with access key")] NoSecretKeyWithAccessKey, #[error("no access key with secret key")] NoAccessKeyWithSecretKey, #[error("policy too large")] PolicyTooLarge, } // pub fn is_err_no_such_user(e: &Error) -> bool { // matches!(e, Error::NoSuchUser(_)) // } pub fn is_err_no_such_policy(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchPolicy) } else { false } } pub fn is_err_no_such_user(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchUser(_)) } else { false } } pub fn is_err_no_such_account(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchAccount(_)) } else { false } } pub fn is_err_no_such_temp_account(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchTempAccount(_)) } else { false } } pub fn is_err_no_such_group(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchGroup(_)) } else { false } } pub fn is_err_no_such_service_account(err: &ecstore::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchServiceAccount(_)) } else { false } }