use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use ve_tos_generic::{AclHeader, BucketSetter, RequestInfo};
use super::enumeration::{ACLType, AzRedundancyType, HttpMethodType::HttpMethodPut, RedirectType, StatusType, StorageClassType};
use super::error::{GenericError, TosError};
use super::http::{HttpRequest, HttpResponse};
use super::internal::{base64_md5, get_header_value, parse_json, truncate_date_to_midnight, InputTranslator, OutputParser};
use crate::common::{Grant, Meta, Owner, RequestInfo, Tag};
use crate::constant::{HEADER_ALLOW_SAME_ACTION_OVERLAP, HEADER_AZ_REDUNDANCY, HEADER_BUCKET_REGION, HEADER_CONTENT_LENGTH, HEADER_CONTENT_MD5, HEADER_LOCATION, HEADER_PROJECT_NAME, HEADER_STORAGE_CLASS, HEADER_TAGGING, ISO8601_DATE_FORMAT, TRUE};
use crate::enumeration::HttpMethodType::{HttpMethodDelete, HttpMethodGet, HttpMethodHead};
use crate::internal::{get_header_value_str, map_insert, set_acl_header, InputDescriptor};
use crate::reader::BuildBufferReader;
pub trait BucketAPI {
fn create_bucket(&self, input: &CreateBucketInput) -> Result<CreateBucketOutput, TosError>;
fn head_bucket(&self, input: &HeadBucketInput) -> Result<HeadBucketOutput, TosError>;
fn delete_bucket(&self, input: &DeleteBucketInput) -> Result<DeleteBucketOutput, TosError>;
fn list_buckets(&self, input: &ListBucketsInput) -> Result<ListBucketsOutput, TosError>;
}
#[derive(Debug, Clone, PartialEq, Default, AclHeader)]
#[enable_grant_write]
pub struct CreateBucketInput {
pub(crate) bucket: String,
pub(crate) acl: Option<ACLType>,
pub(crate) grant_full_control: String,
pub(crate) grant_read: String,
pub(crate) grant_read_acp: String,
pub(crate) grant_write: String,
pub(crate) grant_write_acp: String,
pub(crate) storage_class: Option<StorageClassType>,
pub(crate) az_redundancy: Option<AzRedundancyType>,
pub(crate) project_name: String,
pub(crate) tagging: String,
}
impl CreateBucketInput {
pub fn new(bucket: impl Into<String>) -> Self {
let mut input = Self::default();
input.bucket = bucket.into();
input
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn storage_class(&self) -> &Option<StorageClassType> {
&self.storage_class
}
pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
&self.az_redundancy
}
pub fn project_name(&self) -> &str {
&self.project_name
}
pub fn tagging(&self) -> &str {
&self.tagging
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = Some(storage_class.into());
}
pub fn set_az_redundancy(&mut self, az_redundancy: impl Into<AzRedundancyType>) {
self.az_redundancy = Some(az_redundancy.into());
}
pub fn set_project_name(&mut self, project_name: impl Into<String>) {
self.project_name = project_name.into();
}
pub fn set_tagging(&mut self, tagging: impl Into<String>) {
self.tagging = tagging.into();
}
}
impl InputDescriptor for CreateBucketInput {
fn operation(&self) -> &str {
"CreateBucket"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for CreateBucketInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.method = HttpMethodPut;
let header = &mut request.header;
set_acl_header(header, self);
if let Some(x) = &self.storage_class {
header.insert(HEADER_STORAGE_CLASS, x.as_str().to_string());
}
if let Some(x) = &self.az_redundancy {
header.insert(HEADER_AZ_REDUNDANCY, x.as_str().to_string());
}
map_insert(header, HEADER_PROJECT_NAME, self.project_name());
map_insert(header, HEADER_TAGGING, self.tagging());
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct CreateBucketOutput {
pub(crate) request_info: RequestInfo,
pub(crate) location: String,
}
impl CreateBucketOutput {
pub fn location(&self) -> &str {
&self.location
}
}
impl OutputParser for CreateBucketOutput {
fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
let location = get_header_value(response.headers(), HEADER_LOCATION);
Ok(Self { request_info, location })
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct HeadBucketInput {
pub(crate) bucket: String,
}
impl InputDescriptor for HeadBucketInput {
fn operation(&self) -> &str {
"HeadBucket"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for HeadBucketInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.method = HttpMethodHead;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct HeadBucketOutput {
pub(crate) request_info: RequestInfo,
pub(crate) region: String,
pub(crate) storage_class: Option<StorageClassType>,
pub(crate) az_redundancy: Option<AzRedundancyType>,
pub(crate) project_name: String,
}
impl HeadBucketOutput {
pub fn region(&self) -> &str {
&self.region
}
pub fn storage_class(&self) -> &Option<StorageClassType> {
&self.storage_class
}
pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
&self.az_redundancy
}
pub fn project_name(&self) -> &str {
&self.project_name
}
}
impl OutputParser for HeadBucketOutput {
fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
let region = get_header_value(response.headers(), HEADER_BUCKET_REGION);
let storage_class = StorageClassType::from(get_header_value_str(response.headers(), HEADER_STORAGE_CLASS));
let az_redundancy = AzRedundancyType::from(get_header_value_str(response.headers(), HEADER_AZ_REDUNDANCY));
let project_name = get_header_value(response.headers(), HEADER_PROJECT_NAME);
Ok(Self { request_info, region, storage_class, az_redundancy, project_name })
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct DeleteBucketInput {
pub(crate) bucket: String,
}
impl InputDescriptor for DeleteBucketInput {
fn operation(&self) -> &str {
"DeleteBucket"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for DeleteBucketInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.method = HttpMethodDelete;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct DeleteBucketOutput {
pub(crate) request_info: RequestInfo,
}
impl OutputParser for DeleteBucketOutput {
fn parse_by_ref<B>(_: &HttpRequest<B>, _: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
Ok(Self { request_info })
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ListBucketsInput {
pub(crate) project_name: String,
}
impl ListBucketsInput {
pub fn new() -> Self {
Self::default()
}
pub fn project_name(&self) -> &str {
&self.project_name
}
pub fn set_project_name(&mut self, project_name: impl Into<String>) {
self.project_name = project_name.into();
}
}
impl InputDescriptor for ListBucketsInput {
fn operation(&self) -> &str {
"ListBuckets"
}
fn bucket(&self) -> Result<&str, TosError> {
Err(TosError::client_error("unsupported"))
}
}
impl<B> InputTranslator<B> for ListBucketsInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = HttpRequest::default();
request.operation = self.operation();
request.method = HttpMethodGet;
map_insert(&mut request.header, HEADER_PROJECT_NAME, &self.project_name);
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct ListBucketsOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(default)]
#[serde(rename = "Buckets")]
pub(crate) buckets: Vec<ListedBucket>,
#[serde(default)]
#[serde(rename = "Owner")]
pub(crate) owner: Owner,
}
#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
pub struct ListedBucket {
#[serde(default)]
#[serde(rename = "CreationDate")]
pub(crate) creation_date: String,
#[serde(default)]
#[serde(rename = "Name")]
pub(crate) name: String,
#[serde(default)]
#[serde(rename = "Location")]
pub(crate) location: String,
#[serde(default)]
#[serde(rename = "ExtranetEndpoint")]
pub(crate) extranet_endpoint: String,
#[serde(default)]
#[serde(rename = "IntranetEndpoint")]
pub(crate) intranet_endpoint: String,
#[serde(default)]
#[serde(rename = "ProjectName")]
pub(crate) project_name: String,
}
impl ListBucketsOutput {
pub fn buckets(&self) -> &Vec<ListedBucket> {
&self.buckets
}
pub fn owner(&self) -> &Owner {
&self.owner
}
}
impl OutputParser for ListBucketsOutput {
fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
let mut result = parse_json::<Self>(response)?;
result.request_info = request_info;
Ok(result)
}
}
impl ListedBucket {
pub fn creation_date(&self) -> &str {
&self.creation_date
}
pub fn name(&self) -> &str {
&self.name
}
pub fn location(&self) -> &str {
&self.location
}
pub fn extranet_endpoint(&self) -> &str {
&self.extranet_endpoint
}
pub fn intranet_endpoint(&self) -> &str {
&self.intranet_endpoint
}
pub fn project_name(&self) -> &str {
&self.project_name
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct PutBucketCORSInput {
#[serde(skip)]
pub(crate) bucket: String,
#[serde(rename = "CORSRules")]
pub(crate) rules: Vec<CORSRule>,
}
impl PutBucketCORSInput {
pub fn new(bucket: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
rules: vec![],
}
}
pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<CORSRule>>) -> Self {
Self {
bucket: bucket.into(),
rules: rules.into(),
}
}
pub fn add_rule(&mut self, rule: impl Into<CORSRule>) {
self.rules.push(rule.into());
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn rules(&self) -> &Vec<CORSRule> {
&self.rules
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_objects(&mut self, rules: impl Into<Vec<CORSRule>>) {
self.rules = rules.into();
}
}
impl InputDescriptor for PutBucketCORSInput {
fn operation(&self) -> &str {
"PutBucketCORS"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketCORSInput
where
B: BuildBufferReader,
{
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
if self.rules.len() == 0 {
return Err(TosError::client_error("empty cors rules"));
}
match serde_json::to_string(self) {
Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
Ok(json) => {
let mut request = self.trans_bucket()?;
request.method = HttpMethodPut;
request.query = Some(HashMap::from([("cors", "".to_string())]));
request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
let (body, len) = B::new(json.into_bytes())?;
request.body = Some(body);
request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
Ok(request)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct CORSRule {
#[serde(rename = "AllowedOrigins")]
#[serde(default)]
pub(crate) allowed_origins: Vec<String>,
#[serde(rename = "AllowedMethods")]
#[serde(default)]
pub(crate) allowed_methods: Vec<String>,
#[serde(rename = "AllowedHeaders")]
#[serde(default)]
pub(crate) allowed_headers: Vec<String>,
#[serde(rename = "ExposeHeaders")]
#[serde(default)]
pub(crate) expose_headers: Vec<String>,
#[serde(rename = "MaxAgeSeconds")]
#[serde(default)]
pub(crate) max_age_seconds: isize,
#[serde(rename = "ResponseVary")]
#[serde(default)]
pub(crate) response_vary: bool,
}
impl CORSRule {
pub fn new() -> Self {
Self::default()
}
pub fn allowed_origins(&self) -> &Vec<String> {
&self.allowed_origins
}
pub fn allowed_methods(&self) -> &Vec<String> {
&self.allowed_methods
}
pub fn allowed_headers(&self) -> &Vec<String> {
&self.allowed_headers
}
pub fn expose_headers(&self) -> &Vec<String> {
&self.expose_headers
}
pub fn max_age_seconds(&self) -> isize {
self.max_age_seconds
}
pub fn response_vary(&self) -> bool {
self.response_vary
}
pub fn set_allowed_origins(&mut self, allowed_origins: impl Into<Vec<String>>) {
self.allowed_origins = allowed_origins.into();
}
pub fn set_allowed_methods(&mut self, allowed_methods: impl Into<Vec<String>>) {
self.allowed_methods = allowed_methods.into();
}
pub fn set_allowed_headers(&mut self, allowed_headers: impl Into<Vec<String>>) {
self.allowed_headers = allowed_headers.into();
}
pub fn set_expose_headers(&mut self, expose_headers: impl Into<Vec<String>>) {
self.expose_headers = expose_headers.into();
}
pub fn set_max_age_seconds(&mut self, max_age_seconds: isize) {
self.max_age_seconds = max_age_seconds;
}
pub fn set_response_vary(&mut self, response_vary: bool) {
self.response_vary = response_vary;
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketCORSOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketCORSInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketCORSInput {
fn operation(&self) -> &str {
"GetBucketCORS"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketCORSInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("cors", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct GetBucketCORSOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(default)]
#[serde(rename = "CORSRules")]
pub(crate) rules: Vec<CORSRule>,
}
impl GetBucketCORSOutput {
pub fn rules(&self) -> &Vec<CORSRule> {
&self.rules
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct DeleteBucketCORSInput {
pub(crate) bucket: String,
}
impl InputDescriptor for DeleteBucketCORSInput {
fn operation(&self) -> &str {
"DeleteBucketCORS"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for DeleteBucketCORSInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("cors", "".to_string())]));
request.method = HttpMethodDelete;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct DeleteBucketCORSOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PutBucketStorageClassInput {
pub(crate) bucket: String,
pub(crate) storage_class: StorageClassType,
}
impl PutBucketStorageClassInput {
pub fn new(bucket: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
storage_class: StorageClassType::default(),
}
}
pub fn new_with_storage_class(bucket: impl Into<String>, storage_class: impl Into<StorageClassType>) -> Self {
Self {
bucket: bucket.into(),
storage_class: storage_class.into(),
}
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn storage_class(&self) -> &StorageClassType {
&self.storage_class
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = storage_class.into();
}
}
impl InputDescriptor for PutBucketStorageClassInput {
fn operation(&self) -> &str {
"PutBucketStorageClass"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketStorageClassInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.header.insert(HEADER_STORAGE_CLASS, self.storage_class.as_str().to_string());
request.query = Some(HashMap::from([("storageClass", "".to_string())]));
request.method = HttpMethodPut;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketStorageClassOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketLocationInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketLocationInput {
fn operation(&self) -> &str {
"GetBucketLocation"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketLocationInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("location", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct GetBucketLocationOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(default)]
#[serde(rename = "Region")]
pub(crate) region: String,
#[serde(default)]
#[serde(rename = "ExtranetEndpoint")]
pub(crate) extranet_endpoint: String,
#[serde(default)]
#[serde(rename = "IntranetEndpoint")]
pub(crate) intranet_endpoint: String,
}
impl GetBucketLocationOutput {
pub fn region(&self) -> &str {
&self.region
}
pub fn extranet_endpoint(&self) -> &str {
&self.extranet_endpoint
}
pub fn intranet_endpoint(&self) -> &str {
&self.intranet_endpoint
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct PutBucketLifecycleInput {
#[serde(skip)]
pub(crate) bucket: String,
#[serde(rename = "Rules")]
pub(crate) rules: Vec<LifecycleRule>,
#[serde(skip)]
pub(crate) allow_same_action_overlap: bool,
}
impl PutBucketLifecycleInput {
pub fn new(bucket: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
rules: vec![],
allow_same_action_overlap: false,
}
}
pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<LifecycleRule>>) -> Self {
Self {
bucket: bucket.into(),
rules: rules.into(),
allow_same_action_overlap: false,
}
}
pub fn add_rule(&mut self, rule: impl Into<LifecycleRule>) {
self.rules.push(rule.into());
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn rules(&self) -> &Vec<LifecycleRule> {
&self.rules
}
pub fn allow_same_action_overlap(&self) -> bool {
self.allow_same_action_overlap
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_rules(&mut self, rules: impl Into<Vec<LifecycleRule>>) {
self.rules = rules.into();
}
pub fn set_allow_same_action_overlap(&mut self, allow_same_action_overlap: bool) {
self.allow_same_action_overlap = allow_same_action_overlap;
}
}
impl InputDescriptor for PutBucketLifecycleInput {
fn operation(&self) -> &str {
"PutBucketLifecycle"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketLifecycleInput
where
B: BuildBufferReader,
{
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
if self.rules.len() == 0 {
return Err(TosError::client_error("empty lifecycle rules"));
}
match serde_json::to_string(self) {
Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
Ok(json) => {
let mut request = self.trans_bucket()?;
request.method = HttpMethodPut;
request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
if self.allow_same_action_overlap {
request.header.insert(HEADER_ALLOW_SAME_ACTION_OVERLAP, TRUE.to_string());
}
let (body, len) = B::new(json.into_bytes())?;
request.body = Some(body);
request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
Ok(request)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct LifecycleRule {
#[serde(rename = "ID")]
pub(crate) id: String,
#[serde(rename = "Prefix")]
#[serde(default)]
pub(crate) prefix: String,
#[serde(rename = "Status")]
pub(crate) status: StatusType,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) tags: Vec<Tag>,
#[serde(rename = "Filter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) filter: Option<LifecycleRuleFilter>,
#[serde(rename = "Expiration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) expiration: Option<Expiration>,
#[serde(rename = "NoncurrentVersionExpiration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) noncurrent_version_expiration: Option<NoncurrentVersionExpiration>,
#[serde(rename = "AbortIncompleteMultipartUpload")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) abort_in_complete_multipart_upload: Option<AbortInCompleteMultipartUpload>,
#[serde(rename = "Transitions")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) transitions: Vec<Transition>,
#[serde(rename = "NoncurrentVersionTransitions")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) noncurrent_version_transitions: Vec<NoncurrentVersionTransition>,
#[serde(rename = "AccessTimeTransitions")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) access_time_transitions: Vec<AccessTimeTransition>,
#[serde(rename = "NonCurrentVersionAccessTimeTransitions")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) non_current_version_access_time_transitions: Vec<NonCurrentVersionAccessTimeTransition>,
}
impl LifecycleRule {
pub fn new(id: impl Into<String>) -> Self {
let mut input = Self::default();
input.id = id.into();
input
}
pub fn new_with_prefix(id: impl Into<String>, prefix: impl Into<String>) -> Self {
let mut input = Self::default();
input.id = id.into();
input.prefix = prefix.into();
input
}
pub fn id(&self) -> &str {
&self.id
}
pub fn prefix(&self) -> &str {
&self.prefix
}
pub fn status(&self) -> &StatusType {
&self.status
}
pub fn tags(&self) -> &Vec<Tag> {
&self.tags
}
pub fn filter(&self) -> &Option<LifecycleRuleFilter> {
&self.filter
}
pub fn expiration(&self) -> &Option<Expiration> {
&self.expiration
}
pub fn noncurrent_version_expiration(&self) -> &Option<NoncurrentVersionExpiration> {
&self.noncurrent_version_expiration
}
pub fn abort_in_complete_multipart_upload(&self) -> &Option<AbortInCompleteMultipartUpload> {
&self.abort_in_complete_multipart_upload
}
pub fn transitions(&self) -> &Vec<Transition> {
&self.transitions
}
pub fn noncurrent_version_transitions(&self) -> &Vec<NoncurrentVersionTransition> {
&self.noncurrent_version_transitions
}
pub fn access_time_transitions(&self) -> &Vec<AccessTimeTransition> {
&self.access_time_transitions
}
pub fn non_current_version_access_time_transitions(&self) -> &Vec<NonCurrentVersionAccessTimeTransition> {
&self.non_current_version_access_time_transitions
}
pub fn set_id(&mut self, id: impl Into<String>) {
self.id = id.into();
}
pub fn set_prefix(&mut self, prefix: impl Into<String>) {
self.prefix = prefix.into();
}
pub fn set_status(&mut self, status: impl Into<StatusType>) {
self.status = status.into();
}
pub fn set_tags(&mut self, tags: impl Into<Vec<Tag>>) {
self.tags = tags.into();
}
pub fn set_filter(&mut self, filter: impl Into<LifecycleRuleFilter>) {
self.filter = Some(filter.into());
}
pub fn set_expiration(&mut self, expiration: impl Into<Expiration>) {
self.expiration = Some(expiration.into());
}
pub fn set_noncurrent_version_expiration(&mut self, noncurrent_version_expiration: impl Into<NoncurrentVersionExpiration>) {
self.noncurrent_version_expiration = Some(noncurrent_version_expiration.into());
}
pub fn set_abort_in_complete_multipart_upload(&mut self, abort_in_complete_multipart_upload: impl Into<AbortInCompleteMultipartUpload>) {
self.abort_in_complete_multipart_upload = Some(abort_in_complete_multipart_upload.into());
}
pub fn set_transitions(&mut self, transitions: impl Into<Vec<Transition>>) {
self.transitions = transitions.into();
}
pub fn set_noncurrent_version_transitions(&mut self, noncurrent_version_transitions: impl Into<Vec<NoncurrentVersionTransition>>) {
self.noncurrent_version_transitions = noncurrent_version_transitions.into();
}
pub fn set_access_time_transitions(&mut self, access_time_transitions: impl Into<Vec<AccessTimeTransition>>) {
self.access_time_transitions = access_time_transitions.into();
}
pub fn set_non_current_version_access_time_transitions(&mut self, non_current_version_access_time_transitions: impl Into<Vec<NonCurrentVersionAccessTimeTransition>>) {
self.non_current_version_access_time_transitions = non_current_version_access_time_transitions.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Transition {
#[serde(rename = "Date")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) date_string: Option<String>,
#[serde(skip)]
pub(crate) date: Option<DateTime<Utc>>,
#[serde(rename = "Days")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) days: Option<isize>,
#[serde(rename = "StorageClass")]
pub(crate) storage_class: StorageClassType,
}
impl Transition {
pub fn new(storage_class: impl Into<StorageClassType>) -> Self {
Self {
date_string: None,
date: None,
days: None,
storage_class: storage_class.into(),
}
}
pub fn date(&self) -> Option<DateTime<Utc>> {
self.date
}
pub fn days(&self) -> Option<isize> {
self.days
}
pub fn storage_class(&self) -> &StorageClassType {
&self.storage_class
}
pub fn set_date(&mut self, date: impl Into<DateTime<Utc>>) {
let date = date.into();
self.date_string = Some(date.format(ISO8601_DATE_FORMAT).to_string());
self.date = Some(date);
}
pub fn set_days(&mut self, days: impl Into<isize>) {
self.days = Some(days.into());
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = storage_class.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Expiration {
#[serde(rename = "Date")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) date_string: Option<String>,
#[serde(skip)]
pub(crate) date: Option<DateTime<Utc>>,
#[serde(rename = "Days")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) days: Option<isize>,
}
impl Expiration {
pub fn new_with_date(date: impl Into<DateTime<Utc>>) -> Self {
let mut exp = Self::default();
exp.set_date(date);
exp
}
pub fn new_with_days(days: impl Into<isize>) -> Self {
let mut exp = Self::default();
exp.set_days(days);
exp
}
pub fn date(&self) -> Option<DateTime<Utc>> {
self.date
}
pub fn days(&self) -> Option<isize> {
self.days
}
pub fn set_date(&mut self, date: impl Into<DateTime<Utc>>) {
let date = date.into();
self.date_string = Some(truncate_date_to_midnight(date));
self.date = Some(date.into());
}
pub fn set_days(&mut self, days: impl Into<isize>) {
self.days = Some(days.into());
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct NoncurrentVersionTransition {
#[serde(rename = "NoncurrentDate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) noncurrent_date_string: Option<String>,
#[serde(skip)]
pub(crate) noncurrent_date: Option<DateTime<Utc>>,
#[serde(rename = "NoncurrentDays")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) noncurrent_days: Option<isize>,
#[serde(rename = "StorageClass")]
pub(crate) storage_class: StorageClassType,
}
impl NoncurrentVersionTransition {
pub fn new(storage_class: impl Into<StorageClassType>) -> Self {
Self {
noncurrent_date_string: None,
noncurrent_date: None,
noncurrent_days: None,
storage_class: storage_class.into(),
}
}
pub fn noncurrent_date(&self) -> Option<DateTime<Utc>> {
self.noncurrent_date
}
pub fn noncurrent_days(&self) -> Option<isize> {
self.noncurrent_days
}
pub fn storage_class(&self) -> &StorageClassType {
&self.storage_class
}
pub fn set_noncurrent_date(&mut self, noncurrent_date: impl Into<DateTime<Utc>>) {
let noncurrent_date = noncurrent_date.into();
self.noncurrent_date_string = Some(truncate_date_to_midnight(noncurrent_date));
self.noncurrent_date = Some(noncurrent_date);
}
pub fn set_noncurrent_days(&mut self, noncurrent_days: impl Into<isize>) {
self.noncurrent_days = Some(noncurrent_days.into());
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = storage_class.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct NoncurrentVersionExpiration {
#[serde(rename = "NoncurrentDate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) noncurrent_date_string: Option<String>,
#[serde(skip)]
pub(crate) noncurrent_date: Option<DateTime<Utc>>,
#[serde(rename = "NoncurrentDays")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) noncurrent_days: Option<isize>,
}
impl NoncurrentVersionExpiration {
pub fn new_with_date(noncurrent_date: impl Into<DateTime<Utc>>) -> Self {
let mut exp = Self::default();
exp.set_noncurrent_date(noncurrent_date);
exp
}
pub fn new_with_days(noncurrent_days: impl Into<isize>) -> Self {
let mut exp = Self::default();
exp.set_noncurrent_days(noncurrent_days);
exp
}
pub fn noncurrent_date(&self) -> Option<DateTime<Utc>> {
self.noncurrent_date
}
pub fn noncurrent_days(&self) -> Option<isize> {
self.noncurrent_days
}
pub fn set_noncurrent_date(&mut self, noncurrent_date: impl Into<DateTime<Utc>>) {
let noncurrent_date = noncurrent_date.into();
self.noncurrent_date_string = Some(truncate_date_to_midnight(noncurrent_date));
self.noncurrent_date = Some(noncurrent_date);
}
pub fn set_noncurrent_days(&mut self, noncurrent_days: impl Into<isize>) {
self.noncurrent_days = Some(noncurrent_days.into());
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct AbortInCompleteMultipartUpload {
#[serde(rename = "DaysAfterInitiation")]
pub(crate) days_after_initiation: isize,
}
impl AbortInCompleteMultipartUpload {
pub fn new(days_after_initiation: isize) -> Self {
Self {
days_after_initiation
}
}
pub fn days_after_initiation(&self) -> isize {
self.days_after_initiation
}
pub fn set_days_after_initiation(&mut self, days_after_initiation: isize) {
self.days_after_initiation = days_after_initiation;
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct LifecycleRuleFilter {
#[serde(rename = "ObjectSizeGreaterThan")]
#[serde(default)]
pub(crate) object_size_greater_than: isize,
#[serde(rename = "GreaterThanIncludeEqual")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) greater_than_include_equal: Option<StatusType>,
#[serde(rename = "ObjectSizeLessThan")]
#[serde(default)]
pub(crate) object_size_less_than: isize,
#[serde(rename = "LessThanIncludeEqual")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) less_than_include_equal: Option<StatusType>,
}
impl LifecycleRuleFilter {
pub fn new() -> Self {
Self::default()
}
pub fn object_size_greater_than(&self) -> isize {
self.object_size_greater_than
}
pub fn greater_than_include_equal(&self) -> &Option<StatusType> {
&self.greater_than_include_equal
}
pub fn object_size_less_than(&self) -> isize {
self.object_size_less_than
}
pub fn less_than_include_equal(&self) -> &Option<StatusType> {
&self.less_than_include_equal
}
pub fn set_object_size_greater_than(&mut self, object_size_greater_than: isize) {
self.object_size_greater_than = object_size_greater_than;
}
pub fn set_greater_than_include_equal(&mut self, greater_than_include_equal: impl Into<StatusType>) {
self.greater_than_include_equal = Some(greater_than_include_equal.into());
}
pub fn set_object_size_less_than(&mut self, object_size_less_than: isize) {
self.object_size_less_than = object_size_less_than;
}
pub fn set_less_than_include_equal(&mut self, less_than_include_equal: impl Into<StatusType>) {
self.less_than_include_equal = Some(less_than_include_equal.into());
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct AccessTimeTransition {
#[serde(rename = "Days")]
pub(crate) days: isize,
#[serde(rename = "StorageClass")]
pub(crate) storage_class: StorageClassType,
}
impl AccessTimeTransition {
pub fn new(days: isize, storage_class: impl Into<StorageClassType>) -> Self {
Self {
days,
storage_class: storage_class.into(),
}
}
pub fn days(&self) -> isize {
self.days
}
pub fn storage_class(&self) -> &StorageClassType {
&self.storage_class
}
pub fn set_days(&mut self, days: isize) {
self.days = days;
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = storage_class.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct NonCurrentVersionAccessTimeTransition {
#[serde(rename = "NoncurrentDays")]
pub(crate) non_current_days: isize,
#[serde(rename = "StorageClass")]
pub(crate) storage_class: StorageClassType,
}
impl NonCurrentVersionAccessTimeTransition {
pub fn new(non_current_days: isize, storage_class: impl Into<StorageClassType>) -> Self {
Self {
non_current_days,
storage_class: storage_class.into(),
}
}
pub fn non_current_days(&self) -> isize {
self.non_current_days
}
pub fn storage_class(&self) -> &StorageClassType {
&self.storage_class
}
pub fn set_non_current_days(&mut self, non_current_days: isize) {
self.non_current_days = non_current_days;
}
pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
self.storage_class = storage_class.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketLifecycleOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketLifecycleInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketLifecycleInput {
fn operation(&self) -> &str {
"GetBucketLifecycle"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketLifecycleInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct GetBucketLifecycleOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(rename = "Rules")]
pub(crate) rules: Vec<LifecycleRule>,
#[serde(skip)]
pub(crate) allow_same_action_overlap: bool,
}
impl GetBucketLifecycleOutput {
pub fn request_info(&self) -> &RequestInfo {
&self.request_info
}
pub fn rules(&self) -> &Vec<LifecycleRule> {
&self.rules
}
pub fn allow_same_action_overlap(&self) -> bool {
self.allow_same_action_overlap
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct DeleteBucketLifecycleInput {
pub(crate) bucket: String,
}
impl InputDescriptor for DeleteBucketLifecycleInput {
fn operation(&self) -> &str {
"DeleteBucketLifecycle"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for DeleteBucketLifecycleInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
request.method = HttpMethodDelete;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct DeleteBucketLifecycleOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PutBucketPolicyInput {
pub(crate) bucket: String,
pub(crate) policy: String,
}
impl PutBucketPolicyInput {
pub fn new(bucket: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
policy: "".to_string(),
}
}
pub fn new_with_policy(&self, bucket: impl Into<String>, policy: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
policy: policy.into(),
}
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn policy(&self) -> &str {
&self.policy
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_policy(&mut self, policy: impl Into<String>) {
self.policy = policy.into();
}
}
impl InputDescriptor for PutBucketPolicyInput {
fn operation(&self) -> &str {
"PutBucketPolicy"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketPolicyInput
where
B: BuildBufferReader,
{
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
if self.policy == "" {
return Err(TosError::client_error("empty policy"));
}
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("policy", "".to_string())]));
request.method = HttpMethodPut;
request.header.insert(HEADER_CONTENT_MD5, base64_md5(&self.policy));
let (body, len) = B::new(self.policy.clone().into_bytes())?;
request.body = Some(body);
request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketPolicyOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketPolicyInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketPolicyInput {
fn operation(&self) -> &str {
"GetBucketPolicy"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketPolicyInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("policy", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct GetBucketPolicyOutput {
pub(crate) request_info: RequestInfo,
pub(crate) policy: String,
}
impl GetBucketPolicyOutput {
pub fn policy(&self) -> &str {
&self.policy
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct DeleteBucketPolicyInput {
pub(crate) bucket: String,
}
impl InputDescriptor for DeleteBucketPolicyInput {
fn operation(&self) -> &str {
"DeleteBucketPolicy"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for DeleteBucketPolicyInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("policy", "".to_string())]));
request.method = HttpMethodDelete;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct DeleteBucketPolicyOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct PutBucketMirrorBackInput {
#[serde(skip)]
pub(crate) bucket: String,
#[serde(rename = "Rules")]
pub(crate) rules: Vec<MirrorBackRule>,
}
impl PutBucketMirrorBackInput {
pub fn new(bucket: impl Into<String>) -> Self {
Self {
bucket: bucket.into(),
rules: vec![],
}
}
pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<MirrorBackRule>>) -> Self {
Self {
bucket: bucket.into(),
rules: rules.into(),
}
}
pub fn add_rule(&mut self, rule: impl Into<MirrorBackRule>) {
self.rules.push(rule.into());
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn rules(&self) -> &Vec<MirrorBackRule> {
&self.rules
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_rules(&mut self, rules: impl Into<Vec<MirrorBackRule>>) {
self.rules = rules.into();
}
}
impl InputDescriptor for PutBucketMirrorBackInput {
fn operation(&self) -> &str {
"PutBucketMirrorBack"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketMirrorBackInput
where
B: BuildBufferReader,
{
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
if self.rules.len() == 0 {
return Err(TosError::client_error("empty mirror back rules"));
}
match serde_json::to_string(self) {
Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
Ok(json) => {
let mut request = self.trans_bucket()?;
request.method = HttpMethodPut;
request.query = Some(HashMap::from([("mirror", "".to_string())]));
request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
let (body, len) = B::new(json.into_bytes())?;
request.body = Some(body);
request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
Ok(request)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct MirrorBackRule {
#[serde(rename = "ID")]
pub(crate) id: String,
#[serde(rename = "Condition")]
pub(crate) condition: Condition,
#[serde(rename = "Redirect")]
pub(crate) redirect: Redirect,
}
impl MirrorBackRule {
pub fn new(id: impl Into<String>) -> Self {
let mut input = Self::default();
input.id = id.into();
input
}
pub fn id(&self) -> &str {
&self.id
}
pub fn condition(&self) -> &Condition {
&self.condition
}
pub fn redirect(&self) -> &Redirect {
&self.redirect
}
pub fn set_id(&mut self, id: impl Into<String>) {
self.id = id.into();
}
pub fn set_condition(&mut self, condition: impl Into<Condition>) {
self.condition = condition.into();
}
pub fn set_redirect(&mut self, redirect: impl Into<Redirect>) {
self.redirect = redirect.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Condition {
#[serde(rename = "HttpCode")]
pub(crate) http_code: isize,
#[serde(rename = "KeyPrefix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) key_prefix: String,
#[serde(rename = "KeySuffix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) key_suffix: String,
#[serde(rename = "AllowHost")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) allow_host: Vec<String>,
#[serde(rename = "HttpMethod")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) http_method: Vec<String>,
}
impl Condition {
pub fn new(http_code: isize) -> Self {
Self {
http_code,
key_prefix: "".to_string(),
key_suffix: "".to_string(),
allow_host: vec![],
http_method: vec![],
}
}
pub fn http_code(&self) -> isize {
self.http_code
}
pub fn key_prefix(&self) -> &str {
&self.key_prefix
}
pub fn key_suffix(&self) -> &str {
&self.key_suffix
}
pub fn allow_host(&self) -> &Vec<String> {
&self.allow_host
}
pub fn http_method(&self) -> &Vec<String> {
&self.http_method
}
pub fn set_http_code(&mut self, http_code: isize) {
self.http_code = http_code;
}
pub fn set_key_prefix(&mut self, key_prefix: impl Into<String>) {
self.key_prefix = key_prefix.into();
}
pub fn set_key_suffix(&mut self, key_suffix: impl Into<String>) {
self.key_suffix = key_suffix.into();
}
pub fn set_allow_host(&mut self, allow_host: impl Into<Vec<String>>) {
self.allow_host = allow_host.into();
}
pub fn set_http_method(&mut self, http_method: impl Into<Vec<String>>) {
self.http_method = http_method.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Redirect {
#[serde(rename = "RedirectType")]
pub(crate) redirect_type: RedirectType,
#[serde(rename = "DisableUploadSourceForNoneRangeMirror")]
#[serde(default)]
pub(crate) fetch_source_on_redirect: bool,
#[serde(rename = "PassQuery")]
#[serde(default)]
pub(crate) pass_query: bool,
#[serde(rename = "FollowRedirect")]
#[serde(default)]
pub(crate) follow_redirect: bool,
#[serde(rename = "MirrorHeader")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) mirror_header: Option<MirrorHeader>,
#[serde(rename = "PublicSource")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) public_source: Option<PublicSource>,
#[serde(rename = "PrivateSource")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) private_source: Option<PrivateSource>,
#[serde(rename = "Transform")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) transform: Option<Transform>,
#[serde(rename = "FetchHeaderToMetaDataRules")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) fetch_header_to_meta_data_rules: Vec<FetchHeaderToMetaDataRule>,
#[serde(rename = "FetchSourceOnRedirectWithQuery")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) fetch_source_on_redirect_with_query: Option<bool>,
#[serde(rename = "PassStatusCodeFromSource")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) pass_status_code_from_source: Vec<isize>,
#[serde(rename = "PassHeaderFromSource")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) pass_header_from_source: Vec<String>,
}
impl Redirect {
pub fn new(redirect_type: impl Into<RedirectType>, fetch_source_on_redirect: bool) -> Self {
let mut default = Self::default();
default.redirect_type = redirect_type.into();
default.fetch_source_on_redirect = fetch_source_on_redirect;
default
}
pub fn redirect_type(&self) -> &RedirectType {
&self.redirect_type
}
pub fn fetch_source_on_redirect(&self) -> bool {
self.fetch_source_on_redirect
}
pub fn pass_query(&self) -> bool {
self.pass_query
}
pub fn follow_redirect(&self) -> bool {
self.follow_redirect
}
pub fn mirror_header(&self) -> &Option<MirrorHeader> {
&self.mirror_header
}
pub fn public_source(&self) -> &Option<PublicSource> {
&self.public_source
}
pub fn private_source(&self) -> &Option<PrivateSource> {
&self.private_source
}
pub fn transform(&self) -> &Option<Transform> {
&self.transform
}
pub fn fetch_header_to_meta_data_rules(&self) -> &Vec<FetchHeaderToMetaDataRule> {
&self.fetch_header_to_meta_data_rules
}
pub fn fetch_source_on_redirect_with_query(&self) -> Option<bool> {
self.fetch_source_on_redirect_with_query
}
pub fn pass_status_code_from_source(&self) -> &Vec<isize> {
&self.pass_status_code_from_source
}
pub fn pass_header_from_source(&self) -> &Vec<String> {
&self.pass_header_from_source
}
pub fn set_redirect_type(&mut self, redirect_type: impl Into<RedirectType>) {
self.redirect_type = redirect_type.into();
}
pub fn set_fetch_source_on_redirect(&mut self, fetch_source_on_redirect: bool) {
self.fetch_source_on_redirect = fetch_source_on_redirect;
}
pub fn set_pass_query(&mut self, pass_query: bool) {
self.pass_query = pass_query;
}
pub fn set_follow_redirect(&mut self, follow_redirect: bool) {
self.follow_redirect = follow_redirect;
}
pub fn set_mirror_header(&mut self, mirror_header: impl Into<MirrorHeader>) {
self.mirror_header = Some(mirror_header.into());
}
pub fn set_public_source(&mut self, public_source: impl Into<PublicSource>) {
self.public_source = Some(public_source.into());
}
pub fn set_private_source(&mut self, private_source: impl Into<PrivateSource>) {
self.private_source = Some(private_source.into());
}
pub fn set_transform(&mut self, transform: impl Into<Transform>) {
self.transform = Some(transform.into());
}
pub fn set_fetch_header_to_meta_data_rules(&mut self, fetch_header_to_meta_data_rules: impl Into<Vec<FetchHeaderToMetaDataRule>>) {
self.fetch_header_to_meta_data_rules = fetch_header_to_meta_data_rules.into();
}
pub fn set_fetch_source_on_redirect_with_query(&mut self, fetch_source_on_redirect_with_query: impl Into<bool>) {
self.fetch_source_on_redirect_with_query = Some(fetch_source_on_redirect_with_query.into());
}
pub fn set_pass_status_code_from_source(&mut self, pass_status_code_from_source: impl Into<Vec<isize>>) {
self.pass_status_code_from_source = pass_status_code_from_source.into();
}
pub fn set_pass_header_from_source(&mut self, pass_header_from_source: impl Into<Vec<String>>) {
self.pass_header_from_source = pass_header_from_source.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct MirrorHeader {
#[serde(rename = "PassAll")]
#[serde(default)]
pub(crate) pass_all: bool,
#[serde(rename = "Pass")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) pass: Vec<String>,
#[serde(rename = "Remove")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) remove: Vec<String>,
#[serde(rename = "Set")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) set: Vec<MirrorHeaderKeyValue>,
}
impl MirrorHeader {
pub fn new() -> Self {
Self {
pass_all: false,
pass: vec![],
remove: vec![],
set: vec![],
}
}
pub fn pass_all(&self) -> bool {
self.pass_all
}
pub fn pass(&self) -> &Vec<String> {
&self.pass
}
pub fn remove(&self) -> &Vec<String> {
&self.remove
}
pub fn set(&self) -> &Vec<MirrorHeaderKeyValue> {
&self.set
}
pub fn set_pass_all(&mut self, pass_all: bool) {
self.pass_all = pass_all;
}
pub fn set_pass(&mut self, pass: impl Into<Vec<String>>) {
self.pass = pass.into();
}
pub fn set_remove(&mut self, remove: impl Into<Vec<String>>) {
self.remove = remove.into();
}
pub fn set_set(&mut self, set: impl Into<Vec<MirrorHeaderKeyValue>>) {
self.set = set.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct MirrorHeaderKeyValue {
#[serde(rename = "Key")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) key: String,
#[serde(rename = "Value")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) value: String,
}
impl MirrorHeaderKeyValue {
pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
Self {
key: key.into(),
value: value.into(),
}
}
pub fn key(&self) -> &str {
&self.key
}
pub fn value(&self) -> &str {
&self.value
}
pub fn set_key(&mut self, key: impl Into<String>) {
self.key = key.into();
}
pub fn set_value(&mut self, value: impl Into<String>) {
self.value = value.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PublicSource {
#[serde(rename = "SourceEndpoint")]
#[serde(default)]
pub(crate) source_endpoint: SourceEndpoint,
#[serde(rename = "FixedEndpoint")]
#[serde(default)]
pub(crate) fixed_endpoint: bool,
}
impl PublicSource {
pub fn new(source_endpoint: impl Into<SourceEndpoint>) -> Self {
Self {
source_endpoint: source_endpoint.into(),
fixed_endpoint: false,
}
}
pub fn source_endpoint(&self) -> &SourceEndpoint {
&self.source_endpoint
}
pub fn fixed_endpoint(&self) -> bool {
self.fixed_endpoint
}
pub fn set_source_endpoint(&mut self, source_endpoint: impl Into<SourceEndpoint>) {
self.source_endpoint = source_endpoint.into();
}
pub fn set_fixed_endpoint(&mut self, fixed_endpoint: bool) {
self.fixed_endpoint = fixed_endpoint;
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct SourceEndpoint {
#[serde(rename = "Primary")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) primary: Vec<String>,
#[serde(rename = "Follower")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) follower: Vec<String>,
}
impl SourceEndpoint {
pub fn new(primary: impl Into<Vec<String>>) -> Self {
Self {
primary: primary.into(),
follower: vec![],
}
}
pub fn primary(&self) -> &Vec<String> {
&self.primary
}
pub fn follower(&self) -> &Vec<String> {
&self.follower
}
pub fn set_primary(&mut self, primary: impl Into<Vec<String>>) {
self.primary = primary.into();
}
pub fn set_follower(&mut self, follower: impl Into<Vec<String>>) {
self.follower = follower.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PrivateSource {
#[serde(rename = "SourceEndpoint")]
pub(crate) source_endpoint: CommonSourceEndpoint,
}
impl PrivateSource {
pub fn new(source_endpoint: impl Into<CommonSourceEndpoint>) -> Self {
Self {
source_endpoint: source_endpoint.into(),
}
}
pub fn source_endpoint(&self) -> &CommonSourceEndpoint {
&self.source_endpoint
}
pub fn set_source_endpoint(&mut self, source_endpoint: impl Into<CommonSourceEndpoint>) {
self.source_endpoint = source_endpoint.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct CommonSourceEndpoint {
#[serde(rename = "Primary")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) primary: Vec<EndpointCredentialProvider>,
#[serde(rename = "Follower")]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub(crate) follower: Vec<EndpointCredentialProvider>,
}
impl CommonSourceEndpoint {
pub fn new(primary: impl Into<Vec<EndpointCredentialProvider>>) -> Self {
Self {
primary: primary.into(),
follower: vec![],
}
}
pub fn primary(&self) -> &Vec<EndpointCredentialProvider> {
&self.primary
}
pub fn follower(&self) -> &Vec<EndpointCredentialProvider> {
&self.follower
}
pub fn set_primary(&mut self, primary: impl Into<Vec<EndpointCredentialProvider>>) {
self.primary = primary.into();
}
pub fn set_follower(&mut self, follower: impl Into<Vec<EndpointCredentialProvider>>) {
self.follower = follower.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct EndpointCredentialProvider {
#[serde(rename = "Endpoint")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) endpoint: String,
#[serde(rename = "BucketName")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) bucket_name: String,
#[serde(rename = "CredentialProvider")]
pub(crate) credential_provider: CommonCredentialProvider,
}
impl EndpointCredentialProvider {
pub fn new(endpoint: impl Into<String>) -> Self {
Self {
endpoint: endpoint.into(),
bucket_name: "".to_string(),
credential_provider: Default::default(),
}
}
pub fn endpoint(&self) -> &str {
&self.endpoint
}
pub fn bucket_name(&self) -> &str {
&self.bucket_name
}
pub fn credential_provider(&self) -> &CommonCredentialProvider {
&self.credential_provider
}
pub fn set_endpoint(&mut self, endpoint: impl Into<String>) {
self.endpoint = endpoint.into();
}
pub fn set_bucket_name(&mut self, bucket_name: impl Into<String>) {
self.bucket_name = bucket_name.into();
}
pub fn set_credential_provider(&mut self, credential_provider: impl Into<CommonCredentialProvider>) {
self.credential_provider = credential_provider.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct CommonCredentialProvider {
#[serde(rename = "Role")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) role: String,
#[serde(rename = "StaticCredential")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) static_credential: Option<CommonStaticCredential>,
#[serde(rename = "Region")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) region: String,
}
impl CommonCredentialProvider {
pub fn new_with_role(role: impl Into<String>) -> Self {
Self {
role: role.into(),
static_credential: None,
region: "".to_string(),
}
}
pub fn new_with_static_credential(static_credential: impl Into<CommonStaticCredential>, region: impl Into<String>) -> Self {
Self {
role: "".to_string(),
static_credential: Some(static_credential.into()),
region: region.into(),
}
}
pub fn role(&self) -> &str {
&self.role
}
pub fn static_credential(&self) -> &Option<CommonStaticCredential> {
&self.static_credential
}
pub fn region(&self) -> &str {
&self.region
}
pub fn set_role(&mut self, role: impl Into<String>) {
self.role = role.into();
}
pub fn set_static_credential(&mut self, static_credential: impl Into<CommonStaticCredential>) {
self.static_credential = Some(static_credential.into());
}
pub fn set_region(&mut self, region: impl Into<String>) {
self.region = region.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct CommonStaticCredential {
#[serde(rename = "StorageVendor")]
pub(crate) storage_vendor: String,
#[serde(rename = "AK")]
pub(crate) ak: String,
#[serde(rename = "SK")]
pub(crate) sk: String,
#[serde(rename = "SKEncryptType")]
#[serde(skip_serializing)]
pub(crate) sk_encrypt_type: String,
}
impl CommonStaticCredential {
pub fn new(storage_vendor: impl Into<String>) -> Self {
Self {
storage_vendor: storage_vendor.into(),
ak: "".to_string(),
sk: "".to_string(),
sk_encrypt_type: "".to_string(),
}
}
pub fn storage_vendor(&self) -> &str {
&self.storage_vendor
}
pub fn ak(&self) -> &str {
&self.ak
}
pub fn sk(&self) -> &str {
&self.sk
}
pub fn sk_encrypt_type(&self) -> &str {
&self.sk_encrypt_type
}
pub fn set_storage_vendor(&mut self, storage_vendor: impl Into<String>) {
self.storage_vendor = storage_vendor.into();
}
pub fn set_ak(&mut self, ak: impl Into<String>) {
self.ak = ak.into();
}
pub fn set_sk(&mut self, sk: impl Into<String>) {
self.sk = sk.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Transform {
#[serde(rename = "WithKeyPrefix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) with_key_prefix: String,
#[serde(rename = "WithKeySuffix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) with_key_suffix: String,
#[serde(rename = "ReplaceKeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) replace_key_prefix: Option<ReplaceKeyPrefix>,
}
impl Transform {
pub fn new() -> Self {
Self {
with_key_prefix: "".to_string(),
with_key_suffix: "".to_string(),
replace_key_prefix: Default::default(),
}
}
pub fn with_key_prefix(&self) -> &str {
&self.with_key_prefix
}
pub fn with_key_suffix(&self) -> &str {
&self.with_key_suffix
}
pub fn replace_key_prefix(&self) -> &Option<ReplaceKeyPrefix> {
&self.replace_key_prefix
}
pub fn set_with_key_prefix(&mut self, with_key_prefix: impl Into<String>) {
self.with_key_prefix = with_key_prefix.into();
}
pub fn set_with_key_suffix(&mut self, with_key_suffix: impl Into<String>) {
self.with_key_suffix = with_key_suffix.into();
}
pub fn set_replace_key_prefix(&mut self, replace_key_prefix: impl Into<ReplaceKeyPrefix>) {
self.replace_key_prefix = Some(replace_key_prefix.into());
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ReplaceKeyPrefix {
#[serde(rename = "KeyPrefix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) key_prefix: String,
#[serde(rename = "ReplaceWith")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) replace_with: String,
}
impl ReplaceKeyPrefix {
pub fn new(key_prefix: impl Into<String>, replace_with: impl Into<String>) -> Self {
Self {
key_prefix: key_prefix.into(),
replace_with: replace_with.into(),
}
}
pub fn key_prefix(&self) -> &str {
&self.key_prefix
}
pub fn replace_with(&self) -> &str {
&self.replace_with
}
pub fn set_key_prefix(&mut self, key_prefix: impl Into<String>) {
self.key_prefix = key_prefix.into();
}
pub fn set_replace_with(&mut self, replace_with: impl Into<String>) {
self.replace_with = replace_with.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct FetchHeaderToMetaDataRule {
#[serde(rename = "SourceHeader")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) source_header: String,
#[serde(rename = "MetaDataSuffix")]
#[serde(skip_serializing_if = "String::is_empty")]
#[serde(default)]
pub(crate) meta_data_suffix: String,
}
impl FetchHeaderToMetaDataRule {
pub fn new(source_header: impl Into<String>, meta_data_suffix: impl Into<String>) -> Self {
Self {
source_header: source_header.into(),
meta_data_suffix: meta_data_suffix.into(),
}
}
pub fn source_header(&self) -> &str {
&self.source_header
}
pub fn meta_data_suffix(&self) -> &str {
&self.meta_data_suffix
}
pub fn set_source_header(&mut self, source_header: impl Into<String>) {
self.source_header = source_header.into();
}
pub fn set_meta_data_suffix(&mut self, meta_data_suffix: impl Into<String>) {
self.meta_data_suffix = meta_data_suffix.into();
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketMirrorBackOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketMirrorBackInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketMirrorBackInput {
fn operation(&self) -> &str {
"GetBucketMirrorBack"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketMirrorBackInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("mirror", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct GetBucketMirrorBackOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(rename = "Rules")]
pub(crate) rules: Vec<MirrorBackRule>,
}
impl GetBucketMirrorBackOutput {
pub fn rules(&self) -> &Vec<MirrorBackRule> {
&self.rules
}
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct DeleteBucketMirrorBackInput {
pub(crate) bucket: String,
}
impl InputDescriptor for DeleteBucketMirrorBackInput {
fn operation(&self) -> &str {
"DeleteBucketMirrorBack"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for DeleteBucketMirrorBackInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("mirror", "".to_string())]));
request.method = HttpMethodDelete;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct DeleteBucketMirrorBackOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, AclHeader, Serialize)]
#[enable_grant_write]
pub struct PutBucketACLInput {
#[serde(skip)]
pub(crate) bucket: String,
#[serde(skip)]
pub(crate) acl: Option<ACLType>,
#[serde(skip)]
pub(crate) grant_full_control: String,
#[serde(skip)]
pub(crate) grant_read: String,
#[serde(skip)]
pub(crate) grant_read_acp: String,
#[serde(skip)]
pub(crate) grant_write: String,
#[serde(skip)]
pub(crate) grant_write_acp: String,
#[serde(rename = "Owner")]
pub(crate) owner: Owner,
#[serde(rename = "Grants")]
pub(crate) grants: Vec<Grant>,
#[serde(rename = "BucketAclDelivered")]
#[serde(skip_serializing_if = "<&bool as std::ops::Not>::not")]
pub(crate) bucket_acl_delivered: bool,
}
impl PutBucketACLInput {
pub fn new(bucket: impl Into<String>) -> Self {
let mut input = Self::default();
input.bucket = bucket.into();
input
}
pub fn new_with_acl(bucket: impl Into<String>, acl: impl Into<ACLType>) -> Self {
let mut input = Self::default();
input.bucket = bucket.into();
input.acl = Some(acl.into());
input
}
pub fn bucket(&self) -> &str {
&self.bucket
}
pub fn owner(&self) -> &Owner {
&self.owner
}
pub fn grants(&self) -> &Vec<Grant> {
&self.grants
}
pub fn set_bucket(&mut self, bucket: impl Into<String>) {
self.bucket = bucket.into();
}
pub fn set_owner(&mut self, owner: impl Into<Owner>) {
self.owner = owner.into();
}
pub fn set_grants(&mut self, grants: impl Into<Vec<Grant>>) {
self.grants = grants.into();
}
pub fn bucket_acl_delivered(&self) -> bool {
self.bucket_acl_delivered
}
pub fn set_bucket_acl_delivered(&mut self, bucket_acl_delivered: bool) {
self.bucket_acl_delivered = bucket_acl_delivered;
}
}
impl InputDescriptor for PutBucketACLInput {
fn operation(&self) -> &str {
"PutBucketACL"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for PutBucketACLInput
where
B: BuildBufferReader,
{
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.method = HttpMethodPut;
if self.acl.is_some() && self.grants.len() > 0 {
return Err(TosError::client_error("both acl and grants are set for put bucket acl"));
}
if self.acl.is_some() {
set_acl_header(&mut request.header, self);
} else if self.grants.len() == 0 {
return Err(TosError::client_error("neither acl nor grants is set for put bucket acl"));
} else if self.owner.id == "" {
return Err(TosError::client_error("empty owner id for put bucket acl"));
} else {
match serde_json::to_string(self) {
Err(e) => return Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
Ok(json) => {
let (body, len) = B::new(json.into_bytes())?;
request.body = Some(body);
request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
}
}
}
request.query = Some(HashMap::from([("acl", "".to_string())]));
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
pub struct PutBucketACLOutput {
pub(crate) request_info: RequestInfo,
}
#[derive(Debug, Clone, PartialEq, Default, BucketSetter)]
pub struct GetBucketACLInput {
pub(crate) bucket: String,
}
impl InputDescriptor for GetBucketACLInput {
fn operation(&self) -> &str {
"GetBucketACL"
}
fn bucket(&self) -> Result<&str, TosError> {
Ok(&self.bucket)
}
}
impl<B> InputTranslator<B> for GetBucketACLInput {
fn trans(&self) -> Result<HttpRequest<B>, TosError> {
let mut request = self.trans_bucket()?;
request.query = Some(HashMap::from([("acl", "".to_string())]));
request.method = HttpMethodGet;
Ok(request)
}
}
#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
pub struct GetBucketACLOutput {
#[serde(skip)]
pub(crate) request_info: RequestInfo,
#[serde(default)]
#[serde(rename = "Owner")]
pub(crate) owner: Owner,
#[serde(default)]
#[serde(rename = "Grants")]
pub(crate) grants: Vec<Grant>,
#[serde(default)]
#[serde(rename = "BucketAclDelivered")]
pub(crate) bucket_acl_delivered: bool,
}
impl GetBucketACLOutput {
pub fn owner(&self) -> &Owner {
&self.owner
}
pub fn grants(&self) -> &Vec<Grant> {
&self.grants
}
pub fn bucket_acl_delivered(&self) -> bool {
self.bucket_acl_delivered
}
}