mirror of
https://github.com/rustfs/rustfs.git
synced 2026-03-17 14:24:08 +00:00
refactor: remove compatibility naming from admin helpers
This commit is contained in:
@@ -679,7 +679,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minio_admin_paths_are_not_console_paths() {
|
||||
fn external_admin_paths_are_not_console_paths() {
|
||||
assert!(is_console_path("/rustfs/console/"));
|
||||
assert!(!is_console_path("/minio/admin/v3/info"));
|
||||
assert!(!is_console_path("/rustfs/admin/v3/info"));
|
||||
|
||||
@@ -893,7 +893,7 @@ mod tests {
|
||||
use rustfs_madmin::UserInfo;
|
||||
|
||||
#[test]
|
||||
fn set_policy_query_supports_minio_parameter_names() {
|
||||
fn set_policy_query_supports_external_parameter_names() {
|
||||
let query: SetPolicyForUserOrGroupQuery =
|
||||
serde_urlencoded::from_str("policy=readwrite&user-or-group=test-user&is-group=true").expect("query should parse");
|
||||
|
||||
@@ -947,7 +947,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn policy_entities_query_supports_repeated_minio_parameters() {
|
||||
fn policy_entities_query_supports_repeated_external_parameters() {
|
||||
let query = parse_policy_entities_query(Some("user=alice&user=bob&group=ops&policy=readonly&policy=writeonly"));
|
||||
|
||||
assert_eq!(query.users, vec!["alice".to_string(), "bob".to_string()]);
|
||||
|
||||
@@ -51,7 +51,7 @@ struct CompatibleBucketQuotaRequest {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct MinioBucketQuotaResponse {
|
||||
struct CompatibleBucketQuotaResponse {
|
||||
quota: u64,
|
||||
size: u64,
|
||||
rate: u64,
|
||||
@@ -64,11 +64,11 @@ fn default_quota_type() -> String {
|
||||
rustfs_config::QUOTA_TYPE_HARD.to_string()
|
||||
}
|
||||
|
||||
fn is_minio_set_bucket_quota_path(path: &str) -> bool {
|
||||
fn is_compat_set_bucket_quota_path(path: &str) -> bool {
|
||||
path.ends_with("/v3/set-bucket-quota")
|
||||
}
|
||||
|
||||
fn is_minio_get_bucket_quota_path(path: &str) -> bool {
|
||||
fn is_compat_get_bucket_quota_path(path: &str) -> bool {
|
||||
path.ends_with("/v3/get-bucket-quota")
|
||||
}
|
||||
|
||||
@@ -108,10 +108,10 @@ fn parse_set_bucket_quota_request(body: &[u8]) -> Result<SetBucketQuotaRequest,
|
||||
})
|
||||
}
|
||||
|
||||
fn minio_bucket_quota_response(quota: &BucketQuota) -> MinioBucketQuotaResponse {
|
||||
fn compat_bucket_quota_response(quota: &BucketQuota) -> CompatibleBucketQuotaResponse {
|
||||
let size = quota.quota.unwrap_or(0);
|
||||
|
||||
MinioBucketQuotaResponse {
|
||||
CompatibleBucketQuotaResponse {
|
||||
quota: size,
|
||||
size,
|
||||
rate: 0,
|
||||
@@ -281,7 +281,7 @@ impl Operation for SetBucketQuotaHandler {
|
||||
// Get real-time usage from data usage system
|
||||
let current_usage = current_usage_from_context(&bucket).await;
|
||||
|
||||
let json = if is_minio_set_bucket_quota_path(req.uri.path()) {
|
||||
let json = if is_compat_set_bucket_quota_path(req.uri.path()) {
|
||||
String::new()
|
||||
} else {
|
||||
let response = BucketQuotaResponse {
|
||||
@@ -339,8 +339,8 @@ impl Operation for GetBucketQuotaHandler {
|
||||
_ => s3_error!(InternalError, "Failed to get quota: {}", e),
|
||||
})?;
|
||||
|
||||
let json = if is_minio_get_bucket_quota_path(req.uri.path()) {
|
||||
serde_json::to_string(&minio_bucket_quota_response("a))
|
||||
let json = if is_compat_get_bucket_quota_path(req.uri.path()) {
|
||||
serde_json::to_string(&compat_bucket_quota_response("a))
|
||||
.map_err(|e| s3_error!(InternalError, "Failed to serialize response: {}", e))?
|
||||
} else {
|
||||
let response = BucketQuotaResponse {
|
||||
@@ -576,7 +576,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_set_bucket_quota_request_accepts_minio_shape() {
|
||||
fn parse_set_bucket_quota_request_accepts_compat_shape() {
|
||||
let request = parse_set_bucket_quota_request(br#"{"quota":1073741824,"size":1073741824,"quotatype":"hard"}"#)
|
||||
.expect("parse quota request");
|
||||
|
||||
@@ -594,9 +594,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minio_bucket_quota_response_uses_minio_field_names() {
|
||||
fn compat_bucket_quota_response_uses_external_field_names() {
|
||||
let quota = BucketQuota::new(Some(1024));
|
||||
let json = serde_json::to_string(&minio_bucket_quota_response("a)).expect("serialize");
|
||||
let json = serde_json::to_string(&compat_bucket_quota_response("a)).expect("serialize");
|
||||
|
||||
assert!(json.contains("\"quota\":1024"));
|
||||
assert!(json.contains("\"size\":1024"));
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::admin::utils::{encode_compatible_admin_payload, has_space_be, is_minio_admin_request, read_compatible_admin_body};
|
||||
use crate::admin::utils::{encode_compatible_admin_payload, has_space_be, is_compat_admin_request, read_compatible_admin_body};
|
||||
use crate::auth::{constant_time_eq, get_condition_values, get_session_token};
|
||||
use crate::server::{ADMIN_PREFIX, RemoteAddr};
|
||||
use crate::{
|
||||
@@ -44,16 +44,16 @@ use time::OffsetDateTime;
|
||||
use tracing::{debug, warn};
|
||||
use url::form_urlencoded;
|
||||
|
||||
fn minio_time_sentinel() -> OffsetDateTime {
|
||||
fn compat_time_sentinel() -> OffsetDateTime {
|
||||
OffsetDateTime::UNIX_EPOCH
|
||||
}
|
||||
|
||||
fn list_expiration_or_sentinel(expiration: Option<OffsetDateTime>) -> Option<OffsetDateTime> {
|
||||
Some(expiration.unwrap_or_else(minio_time_sentinel))
|
||||
Some(expiration.unwrap_or_else(compat_time_sentinel))
|
||||
}
|
||||
|
||||
fn expiration_for_admin_path(path: &str, expiration: Option<OffsetDateTime>) -> Option<OffsetDateTime> {
|
||||
if is_minio_admin_request(path) {
|
||||
if is_compat_admin_request(path) {
|
||||
list_expiration_or_sentinel(expiration)
|
||||
} else {
|
||||
expiration
|
||||
@@ -61,7 +61,7 @@ fn expiration_for_admin_path(path: &str, expiration: Option<OffsetDateTime>) ->
|
||||
}
|
||||
|
||||
fn delete_service_account_success_status(path: &str) -> StatusCode {
|
||||
if is_minio_admin_request(path) {
|
||||
if is_compat_admin_request(path) {
|
||||
StatusCode::NO_CONTENT
|
||||
} else {
|
||||
StatusCode::OK
|
||||
@@ -1223,7 +1223,7 @@ mod tests {
|
||||
use serde_urlencoded::from_bytes;
|
||||
|
||||
#[test]
|
||||
fn access_key_query_supports_minio_alias() {
|
||||
fn access_key_query_supports_external_alias() {
|
||||
let query: AccessKeyQuery = from_bytes(b"access-key=test-access-key").expect("parse query");
|
||||
assert_eq!(query.access_key, "test-access-key");
|
||||
}
|
||||
@@ -1288,7 +1288,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_access_keys_query_parses_minio_parameters() {
|
||||
fn list_access_keys_query_parses_external_parameters() {
|
||||
let query = parse_list_access_keys_query(Some("users=alice&users=bob&all=true&listType=svcacc-only"));
|
||||
|
||||
assert_eq!(query.users, vec!["alice".to_string(), "bob".to_string()]);
|
||||
@@ -1303,7 +1303,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_service_account_uses_minio_success_status() {
|
||||
fn delete_service_account_uses_external_success_status() {
|
||||
assert_eq!(
|
||||
delete_service_account_success_status("/minio/admin/v3/delete-service-account"),
|
||||
StatusCode::NO_CONTENT
|
||||
@@ -1319,7 +1319,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expiration_for_minio_admin_path_uses_sentinel() {
|
||||
fn expiration_for_external_admin_path_uses_sentinel() {
|
||||
assert_eq!(
|
||||
expiration_for_admin_path("/minio/admin/v3/list-service-accounts", None),
|
||||
Some(OffsetDateTime::UNIX_EPOCH)
|
||||
|
||||
@@ -24,7 +24,7 @@ fn admin_path(path: &str) -> String {
|
||||
format!("{}{}", ADMIN_PREFIX, path)
|
||||
}
|
||||
|
||||
fn minio_admin_path(path: &str) -> String {
|
||||
fn compat_admin_alias_path(path: &str) -> String {
|
||||
format!("{}{}", MINIO_ADMIN_PREFIX, path)
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ fn test_register_routes_cover_representative_admin_paths() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minio_admin_alias_paths_match_existing_admin_routes() {
|
||||
fn test_admin_alias_paths_match_existing_admin_routes() {
|
||||
let mut router: S3Router<AdminOperation> = S3Router::new(false);
|
||||
|
||||
health::register_health_route(&mut router).expect("register health route");
|
||||
@@ -134,21 +134,21 @@ fn test_minio_admin_alias_paths_match_existing_admin_routes() {
|
||||
quota::register_quota_route(&mut router).expect("register quota route");
|
||||
|
||||
for (method, path) in [
|
||||
(Method::GET, minio_admin_path("/v3/is-admin")),
|
||||
(Method::GET, minio_admin_path("/v3/info")),
|
||||
(Method::GET, minio_admin_path("/v3/storageinfo")),
|
||||
(Method::GET, minio_admin_path("/v3/pools/list")),
|
||||
(Method::PUT, minio_admin_path("/v3/add-service-account")),
|
||||
(Method::GET, minio_admin_path("/v3/temporary-account-info")),
|
||||
(Method::GET, minio_admin_path("/v3/info-access-key")),
|
||||
(Method::GET, minio_admin_path("/v3/list-access-keys-bulk")),
|
||||
(Method::PUT, minio_admin_path("/v3/set-policy")),
|
||||
(Method::PUT, minio_admin_path("/v3/set-bucket-quota")),
|
||||
(Method::GET, minio_admin_path("/v3/get-bucket-quota")),
|
||||
(Method::POST, minio_admin_path("/v3/idp/builtin/policy/attach")),
|
||||
(Method::POST, minio_admin_path("/v3/idp/builtin/policy/detach")),
|
||||
(Method::GET, minio_admin_path("/v3/idp/builtin/policy-entities")),
|
||||
(Method::POST, minio_admin_path("/v3/rebalance/start")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/is-admin")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/info")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/storageinfo")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/pools/list")),
|
||||
(Method::PUT, compat_admin_alias_path("/v3/add-service-account")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/temporary-account-info")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/info-access-key")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/list-access-keys-bulk")),
|
||||
(Method::PUT, compat_admin_alias_path("/v3/set-policy")),
|
||||
(Method::PUT, compat_admin_alias_path("/v3/set-bucket-quota")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/get-bucket-quota")),
|
||||
(Method::POST, compat_admin_alias_path("/v3/idp/builtin/policy/attach")),
|
||||
(Method::POST, compat_admin_alias_path("/v3/idp/builtin/policy/detach")),
|
||||
(Method::GET, compat_admin_alias_path("/v3/idp/builtin/policy-entities")),
|
||||
(Method::POST, compat_admin_alias_path("/v3/rebalance/start")),
|
||||
] {
|
||||
assert!(
|
||||
router.contains_compatible_route(method.clone(), &path),
|
||||
|
||||
@@ -264,13 +264,13 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn canonicalize_admin_path_maps_minio_prefix_to_rustfs_prefix() {
|
||||
fn canonicalize_admin_path_maps_compat_prefix_to_rustfs_prefix() {
|
||||
assert_eq!(canonicalize_admin_path("/minio/admin/v3/info").as_ref(), "/rustfs/admin/v3/info");
|
||||
assert_eq!(canonicalize_admin_path("/rustfs/admin/v3/info").as_ref(), "/rustfs/admin/v3/info");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_admin_path_accepts_rustfs_and_minio_prefixes() {
|
||||
fn is_admin_path_accepts_rustfs_and_compat_prefixes() {
|
||||
assert!(is_admin_path("/rustfs/admin/v3/info"));
|
||||
assert!(is_admin_path("/minio/admin/v3/info"));
|
||||
assert!(!is_admin_path("/bucket/object"));
|
||||
|
||||
@@ -20,7 +20,7 @@ pub(crate) fn has_space_be(s: &str) -> bool {
|
||||
s.trim().len() != s.len()
|
||||
}
|
||||
|
||||
pub(crate) fn is_minio_admin_request(path: &str) -> bool {
|
||||
pub(crate) fn is_compat_admin_request(path: &str) -> bool {
|
||||
path.starts_with(MINIO_ADMIN_PREFIX)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ pub(crate) async fn read_compatible_admin_body(
|
||||
.await
|
||||
.map_err(|e| s3_error!(InvalidRequest, "failed to read request body: {}", e))?;
|
||||
|
||||
if is_minio_admin_request(path) {
|
||||
if is_compat_admin_request(path) {
|
||||
decrypt_stream_io(secret_key.as_bytes(), body.as_ref())
|
||||
.or_else(|_| decrypt_data(secret_key.as_bytes(), body.as_ref()))
|
||||
.map_err(|e| s3_error!(InvalidRequest, "failed to decrypt MinIO admin payload: {}", e))
|
||||
@@ -45,7 +45,7 @@ pub(crate) async fn read_compatible_admin_body(
|
||||
}
|
||||
|
||||
pub(crate) fn encode_compatible_admin_payload(path: &str, secret_key: &str, data: Vec<u8>) -> S3Result<(Vec<u8>, &'static str)> {
|
||||
if is_minio_admin_request(path) {
|
||||
if is_compat_admin_request(path) {
|
||||
let encrypted = encrypt_stream_io(secret_key.as_bytes(), &data)
|
||||
.map_err(|e| s3_error!(InternalError, "failed to encrypt MinIO admin payload: {}", e))?;
|
||||
Ok((encrypted, "application/octet-stream"))
|
||||
@@ -61,9 +61,9 @@ mod tests {
|
||||
use s3s::Body;
|
||||
|
||||
#[test]
|
||||
fn detects_minio_admin_paths_only_for_minio_prefix() {
|
||||
assert!(is_minio_admin_request("/minio/admin/v3/list-users"));
|
||||
assert!(!is_minio_admin_request("/rustfs/admin/v3/list-users"));
|
||||
fn detects_compat_admin_paths_only_for_external_prefix() {
|
||||
assert!(is_compat_admin_request("/minio/admin/v3/list-users"));
|
||||
assert!(!is_compat_admin_request("/rustfs/admin/v3/list-users"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -77,7 +77,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encodes_minio_payload_with_compatible_encryption() {
|
||||
fn encodes_compat_payload_with_compatible_encryption() {
|
||||
let payload = b"{\"ok\":true}".to_vec();
|
||||
let (encoded, content_type) =
|
||||
encode_compatible_admin_payload("/minio/admin/v3/list-users", "secret", payload.clone()).expect("encode payload");
|
||||
@@ -88,7 +88,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reads_legacy_minio_payload_as_fallback() {
|
||||
async fn reads_legacy_compat_payload_as_fallback() {
|
||||
let payload = b"{\"ok\":true}".to_vec();
|
||||
let encrypted = encrypt_data(b"secret", &payload).expect("encrypt payload");
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_minio_prefixed_envs_are_accepted_by_parser() {
|
||||
fn test_external_prefixed_envs_are_accepted_by_parser() {
|
||||
temp_env::with_vars(
|
||||
[
|
||||
("MINIO_VOLUMES", Some("/compat/vol1")),
|
||||
|
||||
Reference in New Issue
Block a user