diff --git a/ecstore/src/tier/tier.rs b/ecstore/src/tier/tier.rs index 6a43d428c..d05374cd2 100644 --- a/ecstore/src/tier/tier.rs +++ b/ecstore/src/tier/tier.rs @@ -220,7 +220,7 @@ impl TierConfigMgr { if cfg.is_none() { return "internal".to_string(); } - cfg.expect("err").tier_type.to_string() + cfg.expect("err").tier_type.as_lowercase() } pub fn list_tiers(&self) -> Vec { diff --git a/ecstore/src/tier/tier_config.rs b/ecstore/src/tier/tier_config.rs index 6b1f225b8..32702d157 100644 --- a/ecstore/src/tier/tier_config.rs +++ b/ecstore/src/tier/tier_config.rs @@ -51,7 +51,7 @@ impl TierType { } } - pub fn to_string(&self) -> String { + pub fn as_lowercase(&self) -> String { match self { TierType::S3 => "s3".to_string(), TierType::RustFS => "rustfs".to_string(), @@ -199,11 +199,17 @@ pub struct TierS3 { impl TierS3 { #[allow(dead_code)] - fn new(name: &str, access_key: &str, secret_key: &str, bucket: &str, options: Vec) -> Result + fn create( + name: &str, + access_key: &str, + secret_key: &str, + bucket: &str, + options: Vec, + ) -> Result where F: Fn(TierS3) -> Box> + Send + Sync + 'static, { - if name == "" { + if name.is_empty() { return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY)); } let sc = TierS3 { @@ -264,7 +270,7 @@ pub struct TierMinIO { impl TierMinIO { #[allow(dead_code)] - fn new( + fn create( name: &str, endpoint: &str, access_key: &str, @@ -275,7 +281,7 @@ impl TierMinIO { where F: Fn(TierMinIO) -> Box> + Send + Sync + 'static, { - if name == "" { + if name.is_empty() { return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY)); } let m = TierMinIO { diff --git a/rustfs/src/admin/handlers/tier.rs b/rustfs/src/admin/handlers/tier.rs index 745780ee4..8a7a78d81 100644 --- a/rustfs/src/admin/handlers/tier.rs +++ b/rustfs/src/admin/handlers/tier.rs @@ -118,39 +118,36 @@ impl Operation for AddTier { let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; //tier_config_mgr.reload(api); - match tier_config_mgr.add(args, force).await { - Err(err) => { - if err.code == ERR_TIER_ALREADY_EXISTS.code { - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierNameAlreadyExist".into()), - "tier name already exists!", - )); - } else if err.code == ERR_TIER_NAME_NOT_UPPERCASE.code { - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierNameNotUppercase".into()), - "tier name not uppercase!", - )); - } else if err.code == ERR_TIER_BACKEND_IN_USE.code { - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierNameBackendInUse!".into()), - "tier name backend in use!", - )); - } else if err.code == ERR_TIER_CONNECT_ERR.code { - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierConnectError".into()), - "tier connect error!", - )); - } else if err.code == ERR_TIER_INVALID_CREDENTIALS.code { - return Err(S3Error::with_message(S3ErrorCode::Custom(err.code.clone().into()), err.message.clone())); - } else { - warn!("tier_config_mgr add failed, e: {:?}", err); - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierAddFailed".into()), - format!("tier add failed. {}", err.to_string()), - )); - } + if let Err(err) = tier_config_mgr.add(args, force).await { + if err.code == ERR_TIER_ALREADY_EXISTS.code { + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierNameAlreadyExist".into()), + "tier name already exists!", + )); + } else if err.code == ERR_TIER_NAME_NOT_UPPERCASE.code { + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierNameNotUppercase".into()), + "tier name not uppercase!", + )); + } else if err.code == ERR_TIER_BACKEND_IN_USE.code { + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierNameBackendInUse!".into()), + "tier name backend in use!", + )); + } else if err.code == ERR_TIER_CONNECT_ERR.code { + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierConnectError".into()), + "tier connect error!", + )); + } else if err.code == ERR_TIER_INVALID_CREDENTIALS.code { + return Err(S3Error::with_message(S3ErrorCode::Custom(err.code.clone().into()), err.message.clone())); + } else { + warn!("tier_config_mgr add failed, e: {:?}", err); + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierAddFailed".into()), + format!("tier add failed. {}", err), + )); } - Ok(_) => (), } if let Err(e) = tier_config_mgr.save().await { warn!("tier_config_mgr save failed, e: {:?}", e); @@ -203,24 +200,21 @@ impl Operation for EditTier { let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; //tier_config_mgr.reload(api); - match tier_config_mgr.edit(&tier_name, creds).await { - Err(err) => { - if err.code == ERR_TIER_NOT_FOUND.code { - return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found!")); - } else if err.code == ERR_TIER_MISSING_CREDENTIALS.code { - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierMissingCredentials".into()), - "tier missing credentials!", - )); - } else { - warn!("tier_config_mgr edit failed, e: {:?}", err); - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierEditFailed".into()), - format!("tier edit failed. {}", err.to_string()), - )); - } + if let Err(err) = tier_config_mgr.edit(&tier_name, creds).await { + if err.code == ERR_TIER_NOT_FOUND.code { + return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found!")); + } else if err.code == ERR_TIER_MISSING_CREDENTIALS.code { + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierMissingCredentials".into()), + "tier missing credentials!", + )); + } else { + warn!("tier_config_mgr edit failed, e: {:?}", err); + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierEditFailed".into()), + format!("tier edit failed. {}", err), + )); } - Ok(_) => (), } if let Err(e) = tier_config_mgr.save().await { warn!("tier_config_mgr save failed, e: {:?}", e); @@ -304,22 +298,20 @@ impl Operation for RemoveTier { let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; //tier_config_mgr.reload(api); - match tier_config_mgr.remove(&tier_name, force).await { - Err(err) => { - if err.code == ERR_TIER_NOT_FOUND.code { - return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found.")); - } else if err.code == ERR_TIER_BACKEND_NOT_EMPTY.code { - return Err(S3Error::with_message(S3ErrorCode::Custom("TierNameBackendInUse".into()), "tier is used.")); - } else { - warn!("tier_config_mgr remove failed, e: {:?}", err); - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierRemoveFailed".into()), - format!("tier remove failed. {}", err.to_string()), - )); - } + if let Err(err) = tier_config_mgr.remove(&tier_name, force).await { + if err.code == ERR_TIER_NOT_FOUND.code { + return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found.")); + } else if err.code == ERR_TIER_BACKEND_NOT_EMPTY.code { + return Err(S3Error::with_message(S3ErrorCode::Custom("TierNameBackendInUse".into()), "tier is used.")); + } else { + warn!("tier_config_mgr remove failed, e: {:?}", err); + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierRemoveFailed".into()), + format!("tier remove failed. {}", err), + )); } - Ok(_) => (), } + if let Err(e) = tier_config_mgr.save().await { warn!("tier_config_mgr save failed, e: {:?}", e); return Err(S3Error::with_message(S3ErrorCode::Custom("TierRemoveFailed".into()), "tier save failed")); @@ -422,7 +414,7 @@ impl Operation for ClearTier { let mut force: bool = false; let force_str = query.force; - if force_str != "" { + if !force_str.is_empty() { force = force_str.parse().unwrap(); } @@ -438,15 +430,12 @@ impl Operation for ClearTier { let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; //tier_config_mgr.reload(api); - match tier_config_mgr.clear_tier(force).await { - Err(err) => { - warn!("tier_config_mgr clear failed, e: {:?}", err); - return Err(S3Error::with_message( - S3ErrorCode::Custom("TierClearFailed".into()), - format!("tier clear failed. {}", err.to_string()), - )); - } - Ok(_) => (), + if let Err(err) = tier_config_mgr.clear_tier(force).await { + warn!("tier_config_mgr clear failed, e: {:?}", err); + return Err(S3Error::with_message( + S3ErrorCode::Custom("TierClearFailed".into()), + format!("tier clear failed. {}", err), + )); } if let Err(e) = tier_config_mgr.save().await { warn!("tier_config_mgr save failed, e: {:?}", e);