-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored from_s3response trait, and refactored get/set/delete policy
- Loading branch information
Showing
28 changed files
with
586 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage | ||
// Copyright 2025 MinIO, Inc. | ||
// | ||
// 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 crate::s3::builders::BucketCommon; | ||
use crate::s3::error::Error; | ||
use crate::s3::response::DeleteBucketPolicyResponse; | ||
use crate::s3::types::{S3Api, S3Request, ToS3Request}; | ||
use crate::s3::utils::check_bucket_name; | ||
use crate::s3::Client; | ||
use http::Method; | ||
|
||
/// Argument builder for [delete_bucket_policy()](Client::delete_bucket_policy) API | ||
pub type DeleteBucketPolicy = BucketCommon<DeleteBucketPolicyPhantomData>; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct DeleteBucketPolicyPhantomData; | ||
|
||
impl S3Api for DeleteBucketPolicy { | ||
type S3Response = DeleteBucketPolicyResponse; | ||
} | ||
|
||
impl ToS3Request for DeleteBucketPolicy { | ||
fn to_s3request(&self) -> Result<S3Request, Error> { | ||
check_bucket_name(&self.bucket, true)?; | ||
|
||
let headers = self | ||
.extra_headers | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
let mut query_params = self | ||
.extra_query_params | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
|
||
query_params.insert(String::from("policy"), String::new()); | ||
|
||
let client: &Client = self.client.as_ref().ok_or(Error::NoClientProvided)?; | ||
|
||
let req = S3Request::new(client, Method::DELETE) | ||
.region(self.region.as_deref()) | ||
.bucket(Some(&self.bucket)) | ||
.query_params(query_params) | ||
.headers(headers); | ||
|
||
Ok(req) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage | ||
// Copyright 2025 MinIO, Inc. | ||
// | ||
// 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 crate::s3::builders::BucketCommon; | ||
use crate::s3::error::Error; | ||
use crate::s3::response::GetBucketPolicyResponse; | ||
use crate::s3::types::{S3Api, S3Request, ToS3Request}; | ||
use crate::s3::utils::check_bucket_name; | ||
use crate::s3::Client; | ||
use http::Method; | ||
|
||
/// Argument builder for [get_bucket_policy()](Client::get_bucket_policy) API | ||
pub type GetBucketPolicy = BucketCommon<GetBucketPolicyPhantomData>; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct GetBucketPolicyPhantomData; | ||
|
||
impl S3Api for GetBucketPolicy { | ||
type S3Response = GetBucketPolicyResponse; | ||
} | ||
|
||
impl ToS3Request for GetBucketPolicy { | ||
fn to_s3request(&self) -> Result<S3Request, Error> { | ||
check_bucket_name(&self.bucket, true)?; | ||
|
||
let headers = self | ||
.extra_headers | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
let mut query_params = self | ||
.extra_query_params | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
|
||
query_params.insert(String::from("policy"), String::new()); | ||
|
||
let client: &Client = self.client.as_ref().ok_or(Error::NoClientProvided)?; | ||
|
||
let req = S3Request::new(client, Method::GET) | ||
.region(self.region.as_deref()) | ||
.bucket(Some(&self.bucket)) | ||
.query_params(query_params) | ||
.headers(headers); | ||
|
||
Ok(req) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage | ||
// Copyright 2025 MinIO, Inc. | ||
// | ||
// 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 crate::s3::builders::SegmentedBytes; | ||
use crate::s3::error::Error; | ||
use crate::s3::response::SetBucketLifecycleResponse; | ||
use crate::s3::types::{S3Api, S3Request, ToS3Request}; | ||
use crate::s3::utils::{check_bucket_name, Multimap}; | ||
use crate::s3::Client; | ||
use bytes::Bytes; | ||
use http::Method; | ||
|
||
/// Argument builder for [set_bucket_policy()](crate::s3::client::Client::set_bucket_policy) API | ||
#[derive(Clone, Debug, Default)] | ||
pub struct SetBucketPolicy { | ||
pub(crate) client: Option<Client>, | ||
|
||
pub(crate) extra_headers: Option<Multimap>, | ||
pub(crate) extra_query_params: Option<Multimap>, | ||
pub(crate) region: Option<String>, | ||
pub(crate) bucket: String, | ||
|
||
pub(crate) config: String, //TODO consider PolicyConfig struct | ||
} | ||
|
||
impl SetBucketPolicy { | ||
pub fn new(bucket: &str) -> Self { | ||
Self { | ||
bucket: bucket.to_owned(), | ||
..Default::default() | ||
} | ||
} | ||
pub fn client(mut self, client: &Client) -> Self { | ||
self.client = Some(client.clone()); | ||
self | ||
} | ||
|
||
pub fn extra_headers(mut self, extra_headers: Option<Multimap>) -> Self { | ||
self.extra_headers = extra_headers; | ||
self | ||
} | ||
|
||
pub fn extra_query_params(mut self, extra_query_params: Option<Multimap>) -> Self { | ||
self.extra_query_params = extra_query_params; | ||
self | ||
} | ||
|
||
pub fn region(mut self, region: Option<String>) -> Self { | ||
self.region = region; | ||
self | ||
} | ||
|
||
pub fn config(mut self, config: String) -> Self { | ||
self.config = config; | ||
self | ||
} | ||
} | ||
|
||
impl S3Api for SetBucketPolicy { | ||
type S3Response = SetBucketLifecycleResponse; | ||
} | ||
|
||
impl ToS3Request for SetBucketPolicy { | ||
fn to_s3request(&self) -> Result<S3Request, Error> { | ||
check_bucket_name(&self.bucket, true)?; | ||
|
||
let headers = self | ||
.extra_headers | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
let mut query_params = self | ||
.extra_query_params | ||
.as_ref() | ||
.filter(|v| !v.is_empty()) | ||
.cloned() | ||
.unwrap_or_default(); | ||
|
||
query_params.insert(String::from("policy"), String::new()); | ||
|
||
let bytes: Bytes = self.config.to_string().into(); | ||
let body: Option<SegmentedBytes> = Some(SegmentedBytes::from(bytes)); | ||
|
||
let client: &Client = self.client.as_ref().ok_or(Error::NoClientProvided)?; | ||
|
||
let req = S3Request::new(client, Method::PUT) | ||
.region(self.region.as_deref()) | ||
.bucket(Some(&self.bucket)) | ||
.query_params(query_params) | ||
.headers(headers) | ||
.body(body); | ||
|
||
Ok(req) | ||
} | ||
} |
Oops, something went wrong.