mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
refactor(app): inline trivial s3 api outputs (#2460)
This commit is contained in:
@@ -28,7 +28,7 @@ use crate::storage::s3_api::bucket::{
|
||||
build_list_objects_v2_output, parse_list_object_versions_params, parse_list_objects_v2_params,
|
||||
};
|
||||
use crate::storage::s3_api::common::rustfs_owner;
|
||||
use crate::storage::s3_api::{acl, encryption, replication, tagging};
|
||||
use crate::storage::s3_api::{acl, tagging};
|
||||
use crate::storage::*;
|
||||
use futures::StreamExt;
|
||||
use http::StatusCode;
|
||||
@@ -1033,9 +1033,9 @@ impl DefaultBucketUsecase {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(S3Response::new(encryption::build_get_bucket_encryption_output(
|
||||
Ok(S3Response::new(GetBucketEncryptionOutput {
|
||||
server_side_encryption_configuration,
|
||||
)))
|
||||
}))
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
@@ -1297,9 +1297,9 @@ impl DefaultBucketUsecase {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(S3Response::new(replication::build_get_bucket_replication_output(
|
||||
replication_configuration,
|
||||
)))
|
||||
Ok(S3Response::new(GetBucketReplicationOutput {
|
||||
replication_configuration: Some(replication_configuration),
|
||||
}))
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
@@ -2355,6 +2355,20 @@ mod tests {
|
||||
assert_eq!(err.code(), &S3ErrorCode::InternalError);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn execute_get_bucket_encryption_returns_internal_error_when_store_uninitialized() {
|
||||
let input = GetBucketEncryptionInput::builder()
|
||||
.bucket("test-bucket".to_string())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let req = build_request(input, Method::GET);
|
||||
let usecase = DefaultBucketUsecase::without_context();
|
||||
|
||||
let err = usecase.execute_get_bucket_encryption(req).await.unwrap_err();
|
||||
assert_eq!(err.code(), &S3ErrorCode::InternalError);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn execute_get_bucket_replication_returns_internal_error_when_store_uninitialized() {
|
||||
let input = GetBucketReplicationInput::builder()
|
||||
|
||||
@@ -38,8 +38,8 @@ use crate::storage::options::{
|
||||
filter_object_metadata, get_content_sha256_with_query, get_opts, normalize_content_encoding_for_storage, put_opts,
|
||||
validate_archive_content_encoding,
|
||||
};
|
||||
use crate::storage::s3_api::acl;
|
||||
use crate::storage::s3_api::multipart::parse_list_parts_params;
|
||||
use crate::storage::s3_api::{acl, restore, select};
|
||||
use crate::storage::timeout_wrapper::{RequestTimeoutWrapper, TimeoutConfig};
|
||||
use crate::storage::*;
|
||||
use bytes::Bytes;
|
||||
@@ -2933,8 +2933,10 @@ impl DefaultObjectUsecase {
|
||||
.map_err(|_| S3Error::with_message(S3ErrorCode::Custom("ErrCopyObject".into()), "restore object failed."))?;
|
||||
|
||||
if already_restored {
|
||||
let output =
|
||||
restore::build_restore_object_output(Some(RequestCharged::from_static(RequestCharged::REQUESTER)), None);
|
||||
let output = RestoreObjectOutput {
|
||||
request_charged: Some(RequestCharged::from_static(RequestCharged::REQUESTER)),
|
||||
restore_output_path: None,
|
||||
};
|
||||
helper = helper
|
||||
.object(event_object_info.clone())
|
||||
.version_id(version_id_str.clone())
|
||||
@@ -2989,7 +2991,10 @@ impl DefaultObjectUsecase {
|
||||
}
|
||||
});
|
||||
|
||||
let output = restore::build_restore_object_output(Some(RequestCharged::from_static(RequestCharged::REQUESTER)), None);
|
||||
let output = RestoreObjectOutput {
|
||||
request_charged: Some(RequestCharged::from_static(RequestCharged::REQUESTER)),
|
||||
restore_output_path: None,
|
||||
};
|
||||
helper = helper.object(event_object_info).version_id(version_id_str);
|
||||
let result = Ok(S3Response::with_headers(output, header));
|
||||
let _ = helper.complete(&result);
|
||||
@@ -3070,9 +3075,9 @@ impl DefaultObjectUsecase {
|
||||
drop(tx);
|
||||
});
|
||||
|
||||
Ok(S3Response::new(select::build_select_object_content_output(
|
||||
SelectObjectContentEventStream::new(stream),
|
||||
)))
|
||||
Ok(S3Response::new(SelectObjectContentOutput {
|
||||
payload: Some(SelectObjectContentEventStream::new(stream)),
|
||||
}))
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, req, request_context))]
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use s3s::dto::{GetBucketEncryptionOutput, ServerSideEncryptionConfiguration};
|
||||
|
||||
pub(crate) fn build_get_bucket_encryption_output(
|
||||
server_side_encryption_configuration: Option<ServerSideEncryptionConfiguration>,
|
||||
) -> GetBucketEncryptionOutput {
|
||||
GetBucketEncryptionOutput {
|
||||
server_side_encryption_configuration,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::build_get_bucket_encryption_output;
|
||||
use s3s::dto::ServerSideEncryptionConfiguration;
|
||||
|
||||
#[test]
|
||||
fn test_build_get_bucket_encryption_output_preserves_configuration() {
|
||||
let config = Some(ServerSideEncryptionConfiguration::default());
|
||||
let output = build_get_bucket_encryption_output(config.clone());
|
||||
|
||||
assert_eq!(output.server_side_encryption_configuration, config);
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,5 @@
|
||||
pub(crate) mod acl;
|
||||
pub(crate) mod bucket;
|
||||
pub(crate) mod common;
|
||||
pub(crate) mod encryption;
|
||||
pub(crate) mod multipart;
|
||||
pub(crate) mod replication;
|
||||
pub(crate) mod restore;
|
||||
pub(crate) mod select;
|
||||
pub(crate) mod tagging;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use s3s::dto::{GetBucketReplicationOutput, ReplicationConfiguration};
|
||||
|
||||
pub(crate) fn build_get_bucket_replication_output(
|
||||
replication_configuration: ReplicationConfiguration,
|
||||
) -> GetBucketReplicationOutput {
|
||||
GetBucketReplicationOutput {
|
||||
replication_configuration: Some(replication_configuration),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::build_get_bucket_replication_output;
|
||||
use s3s::dto::ReplicationConfiguration;
|
||||
|
||||
#[test]
|
||||
fn test_build_get_bucket_replication_output_sets_configuration() {
|
||||
let config = ReplicationConfiguration::default();
|
||||
let output = build_get_bucket_replication_output(config.clone());
|
||||
|
||||
assert_eq!(output.replication_configuration, Some(config));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use s3s::dto::{RequestCharged, RestoreObjectOutput};
|
||||
|
||||
pub(crate) fn build_restore_object_output(
|
||||
request_charged: Option<RequestCharged>,
|
||||
restore_output_path: Option<String>,
|
||||
) -> RestoreObjectOutput {
|
||||
RestoreObjectOutput {
|
||||
request_charged,
|
||||
restore_output_path,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::build_restore_object_output;
|
||||
use s3s::dto::RequestCharged;
|
||||
|
||||
#[test]
|
||||
fn test_build_restore_object_output_preserves_fields() {
|
||||
let output = build_restore_object_output(
|
||||
Some(RequestCharged::from_static(RequestCharged::REQUESTER)),
|
||||
Some("s3://bucket/prefix/id".to_string()),
|
||||
);
|
||||
|
||||
assert_eq!(output.request_charged, Some(RequestCharged::from_static(RequestCharged::REQUESTER)));
|
||||
assert_eq!(output.restore_output_path, Some("s3://bucket/prefix/id".to_string()));
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use s3s::dto::{SelectObjectContentEventStream, SelectObjectContentOutput};
|
||||
|
||||
pub(crate) fn build_select_object_content_output(payload: SelectObjectContentEventStream) -> SelectObjectContentOutput {
|
||||
SelectObjectContentOutput { payload: Some(payload) }
|
||||
}
|
||||
Reference in New Issue
Block a user