fix listbucket sign (#890)

This commit is contained in:
weisd
2025-11-19 11:08:16 +08:00
committed by GitHub
parent 55d44622ed
commit a13ce08590
+20 -8
View File
@@ -2120,15 +2120,20 @@ impl S3 for FS {
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string())); return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
}; };
let mut bucket_infos = store.list_bucket(&BucketOptions::default()).await.map_err(ApiError::from)?;
let mut req = req; let mut req = req;
if authorize_request(&mut req, Action::S3Action(S3Action::ListAllMyBucketsAction)) if req.credentials.as_ref().is_none_or(|cred| cred.access_key.is_empty()) {
.await return Err(S3Error::with_message(S3ErrorCode::AccessDenied, "Access Denied"));
.is_err() }
{
bucket_infos = futures::stream::iter(bucket_infos) let bucket_infos = if let Err(e) = authorize_request(&mut req, Action::S3Action(S3Action::ListAllMyBucketsAction)).await {
if e.code() != &S3ErrorCode::AccessDenied {
return Err(e);
}
let mut list_bucket_infos = store.list_bucket(&BucketOptions::default()).await.map_err(ApiError::from)?;
list_bucket_infos = futures::stream::iter(list_bucket_infos)
.filter_map(|info| async { .filter_map(|info| async {
let mut req_clone = req.clone(); let mut req_clone = req.clone();
let req_info = req_clone.extensions.get_mut::<ReqInfo>().expect("ReqInfo not found"); let req_info = req_clone.extensions.get_mut::<ReqInfo>().expect("ReqInfo not found");
@@ -2148,7 +2153,14 @@ impl S3 for FS {
}) })
.collect() .collect()
.await; .await;
}
if list_bucket_infos.is_empty() {
return Err(S3Error::with_message(S3ErrorCode::AccessDenied, "Access Denied"));
}
list_bucket_infos
} else {
store.list_bucket(&BucketOptions::default()).await.map_err(ApiError::from)?
};
let buckets: Vec<Bucket> = bucket_infos let buckets: Vec<Bucket> = bucket_infos
.iter() .iter()