move ecsotre/error to common

This commit is contained in:
weisd
2025-03-25 17:14:40 +08:00
parent c3b47adf39
commit 545ae79e44
81 changed files with 444 additions and 359 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use regex::Regex;
const ARN_PREFIX_ARN: &str = "arn";
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::policy::Policy;
use crate::sys::{iam_policy_claim_name_sa, Validator, INHERITED_POLICY_TYPE};
use crate::utils;
use crate::utils::extract_claims;
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
+25 -7
View File
@@ -1,3 +1,6 @@
use ecstore::disk::error::clone_disk_err;
use ecstore::disk::error::DiskError;
use crate::policy;
#[derive(thiserror::Error, Debug)]
@@ -6,7 +9,7 @@ pub enum Error {
PolicyError(#[from] policy::Error),
#[error("ecsotre error: {0}")]
EcstoreError(ecstore::error::Error),
EcstoreError(common::error::Error),
#[error("{0}")]
StringError(String),
@@ -96,7 +99,7 @@ pub enum Error {
// matches!(e, Error::NoSuchUser(_))
// }
pub fn is_err_no_such_policy(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_policy(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchPolicy)
} else {
@@ -104,7 +107,7 @@ pub fn is_err_no_such_policy(err: &ecstore::error::Error) -> bool {
}
}
pub fn is_err_no_such_user(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_user(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchUser(_))
} else {
@@ -112,7 +115,7 @@ pub fn is_err_no_such_user(err: &ecstore::error::Error) -> bool {
}
}
pub fn is_err_no_such_account(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_account(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchAccount(_))
} else {
@@ -120,7 +123,7 @@ pub fn is_err_no_such_account(err: &ecstore::error::Error) -> bool {
}
}
pub fn is_err_no_such_temp_account(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_temp_account(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchTempAccount(_))
} else {
@@ -128,7 +131,7 @@ pub fn is_err_no_such_temp_account(err: &ecstore::error::Error) -> bool {
}
}
pub fn is_err_no_such_group(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_group(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchGroup(_))
} else {
@@ -136,10 +139,25 @@ pub fn is_err_no_such_group(err: &ecstore::error::Error) -> bool {
}
}
pub fn is_err_no_such_service_account(err: &ecstore::error::Error) -> bool {
pub fn is_err_no_such_service_account(err: &common::error::Error) -> bool {
if let Some(e) = err.downcast_ref::<Error>() {
matches!(e, Error::NoSuchServiceAccount(_))
} else {
false
}
}
pub fn clone_err(e: &common::error::Error) -> common::error::Error {
if let Some(e) = e.downcast_ref::<DiskError>() {
clone_disk_err(e)
} else if let Some(e) = e.downcast_ref::<std::io::Error>() {
if let Some(code) = e.raw_os_error() {
common::error::Error::new(std::io::Error::from_raw_os_error(code))
} else {
common::error::Error::new(std::io::Error::new(e.kind(), e.to_string()))
}
} else {
//TODO: 优化其他类型
common::error::Error::msg(e.to_string())
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
use auth::Credentials;
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use ecstore::store::ECStore;
use error::Error as IamError;
use log::debug;
+2 -4
View File
@@ -12,11 +12,9 @@ use crate::{
MAX_SVCSESSION_POLICY_SIZE, SESSION_POLICY_NAME, SESSION_POLICY_NAME_EXTRACTED, STATUS_DISABLED, STATUS_ENABLED,
},
};
use common::error::{Error, Result};
use ecstore::config::error::is_err_config_not_found;
use ecstore::utils::{crypto::base64_encode, path::path_join_buf};
use ecstore::{
config::error::is_err_config_not_found,
error::{Error, Result},
};
use log::{debug, warn};
use madmin::{AccountStatus, AddOrUpdateUserReq, GroupDesc};
use serde::{Deserialize, Serialize};
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, ops::Deref};
use strum::{EnumString, IntoStaticStr};
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
use strum::{EnumString, IntoStaticStr};
+1 -1
View File
@@ -1,6 +1,6 @@
use super::key_name::KeyName;
use crate::{policy::Error as PolicyError, sys::Validator};
use ecstore::error::Error;
use common::error::Error;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
use std::ops::Deref;
+2 -2
View File
@@ -1,6 +1,6 @@
use super::{Effect, Error as IamError, Statement, ID};
use crate::sys::{Args, Validator, DEFAULT_VERSION};
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
@@ -323,7 +323,7 @@ pub mod default {
#[cfg(test)]
mod test {
use super::*;
use ecstore::error::Result;
use common::error::{Error, Result};
#[tokio::test]
async fn test_parse_policy() -> Result<()> {
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
use std::{
collections::{HashMap, HashSet},
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::sys::{Args, Validator};
use super::{action::Action, ActionSet, Effect, Error as IamError, Functions, ResourceSet, ID};
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
+1 -1
View File
@@ -1,7 +1,7 @@
pub mod object;
use crate::{auth::UserIdentity, cache::Cache, policy::PolicyDoc};
use ecstore::error::Result;
use common::error::Result;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use time::OffsetDateTime;
+2 -2
View File
@@ -7,13 +7,13 @@ use crate::{
manager::{extract_jwt_claims, get_default_policyes},
policy::PolicyDoc,
};
use common::error::{Error, Result};
use ecstore::{
config::{
common::{delete_config, read_config, read_config_with_metadata, save_config},
com::{delete_config, read_config, read_config_with_metadata, save_config},
error::is_err_config_not_found,
RUSTFS_CONFIG_PREFIX,
},
error::{Error, Result},
store::ECStore,
store_api::{ObjectInfo, ObjectOptions},
store_list_objects::{ObjectInfoOrErr, WalkOptions},
+1 -1
View File
@@ -24,7 +24,7 @@ use crate::policy::PolicyDoc;
use crate::store::MappedPolicy;
use crate::store::Store;
use crate::store::UserType;
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use ecstore::utils::crypto::base64_decode;
use ecstore::utils::crypto::base64_encode;
use madmin::AddOrUpdateUserReq;
+1 -1
View File
@@ -1,4 +1,4 @@
use ecstore::error::{Error, Result};
use common::error::{Error, Result};
use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header};
use rand::{Rng, RngCore};
use serde::{de::DeserializeOwned, Serialize};