Skip to main content

ve_tos_rust_sdk/
bucket.rs

1/*
2 * Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16use bytes::Bytes;
17use chrono::{DateTime, Utc};
18use serde::{Deserialize, Serialize};
19use std::collections::HashMap;
20use std::sync::Arc;
21use ve_tos_generic::{AclHeader, BucketSetter, GenericInput, RequestInfo};
22
23use super::enumeration::{ACLType, AuthProtocolType, AzRedundancyType, BucketType, CertStatusType, HttpMethodType::HttpMethodPut, InventoryFormatType, InventoryFrequencyType, InventoryIncludedObjType, ProtocolType, RedirectType, StatusType, StorageClassInheritDirectiveType, StorageClassType, VersioningStatusType};
24use super::error::{GenericError, TosError};
25use super::http::{HttpRequest, HttpResponse};
26use super::internal::{base64_md5, get_header_value, parse_json, truncate_date_to_midnight, InputTranslator, OutputParser};
27use crate::common::{GenericInput, Grant, Meta, Owner, RequestInfo, Tag, TagSet};
28use crate::config::ConfigHolder;
29use crate::constant::{HEADER_ALLOW_SAME_ACTION_OVERLAP, HEADER_AZ_REDUNDANCY, HEADER_BUCKET_REGION, HEADER_BUCKET_TYPE, HEADER_CONTENT_LENGTH, HEADER_CONTENT_MD5, HEADER_LOCATION, HEADER_PROJECT_NAME, HEADER_STORAGE_CLASS, HEADER_TAGGING, ISO8601_DATE_FORMAT, TRUE};
30use crate::enumeration::HttpMethodType::{HttpMethodDelete, HttpMethodGet, HttpMethodHead};
31use crate::internal::{get_header_value_str, map_insert, set_acl_header, InputDescriptor};
32use crate::reader::BuildBufferReader;
33
34pub trait BucketAPI {
35    fn create_bucket(&self, input: &CreateBucketInput) -> Result<CreateBucketOutput, TosError>;
36    fn head_bucket(&self, input: &HeadBucketInput) -> Result<HeadBucketOutput, TosError>;
37    fn delete_bucket(&self, input: &DeleteBucketInput) -> Result<DeleteBucketOutput, TosError>;
38    fn list_buckets(&self, input: &ListBucketsInput) -> Result<ListBucketsOutput, TosError>;
39}
40
41
42#[derive(Debug, Clone, PartialEq, Default, AclHeader, GenericInput)]
43#[enable_grant_write]
44pub struct CreateBucketInput {
45    pub(crate) generic_input: GenericInput,
46    pub(crate) bucket: String,
47    pub(crate) acl: Option<ACLType>,
48    pub(crate) grant_full_control: String,
49    pub(crate) grant_read: String,
50    pub(crate) grant_read_acp: String,
51    pub(crate) grant_write: String,
52    pub(crate) grant_write_acp: String,
53    pub(crate) storage_class: Option<StorageClassType>,
54    pub(crate) az_redundancy: Option<AzRedundancyType>,
55    pub(crate) project_name: String,
56    pub(crate) tagging: String,
57    pub(crate) bucket_type: Option<BucketType>,
58}
59
60impl CreateBucketInput {
61    pub fn new(bucket: impl Into<String>) -> Self {
62        let mut input = Self::default();
63        input.bucket = bucket.into();
64        input
65    }
66
67    pub fn bucket(&self) -> &str {
68        &self.bucket
69    }
70    pub fn storage_class(&self) -> &Option<StorageClassType> {
71        &self.storage_class
72    }
73    pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
74        &self.az_redundancy
75    }
76    pub fn project_name(&self) -> &str {
77        &self.project_name
78    }
79    pub fn tagging(&self) -> &str {
80        &self.tagging
81    }
82    pub fn bucket_type(&self) -> &Option<BucketType> {
83        &self.bucket_type
84    }
85    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
86        self.bucket = bucket.into();
87    }
88    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
89        self.storage_class = Some(storage_class.into());
90    }
91    pub fn set_az_redundancy(&mut self, az_redundancy: impl Into<AzRedundancyType>) {
92        self.az_redundancy = Some(az_redundancy.into());
93    }
94    pub fn set_project_name(&mut self, project_name: impl Into<String>) {
95        self.project_name = project_name.into();
96    }
97    pub fn set_tagging(&mut self, tagging: impl Into<String>) {
98        self.tagging = tagging.into();
99    }
100
101    pub fn set_bucket_type(&mut self, bucket_type: impl Into<BucketType>) {
102        self.bucket_type = Some(bucket_type.into());
103    }
104}
105
106
107impl InputDescriptor for CreateBucketInput {
108    fn operation(&self) -> &str {
109        "CreateBucket"
110    }
111
112    fn bucket(&self) -> Result<&str, TosError> {
113        Ok(&self.bucket)
114    }
115}
116
117impl<B> InputTranslator<B> for CreateBucketInput {
118    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
119        let mut request = self.trans_bucket()?;
120        request.method = HttpMethodPut;
121        let header = &mut request.header;
122        set_acl_header(header, self);
123        if let Some(x) = &self.storage_class {
124            header.insert(HEADER_STORAGE_CLASS, x.as_str().to_string());
125        }
126
127        if let Some(x) = &self.az_redundancy {
128            header.insert(HEADER_AZ_REDUNDANCY, x.as_str().to_string());
129        }
130        map_insert(header, HEADER_PROJECT_NAME, self.project_name());
131        map_insert(header, HEADER_TAGGING, self.tagging());
132        if let Some(x) = &self.bucket_type {
133            header.insert(HEADER_BUCKET_TYPE, x.as_str().to_string());
134        }
135        Ok(request)
136    }
137}
138
139
140#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
141pub struct CreateBucketOutput {
142    pub(crate) request_info: RequestInfo,
143    pub(crate) location: String,
144}
145
146impl CreateBucketOutput {
147    pub fn location(&self) -> &str {
148        &self.location
149    }
150}
151
152impl OutputParser for CreateBucketOutput {
153    fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
154        let location = get_header_value(response.headers(), HEADER_LOCATION);
155        Ok(Self { request_info, location })
156    }
157}
158
159#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
160pub struct HeadBucketInput {
161    pub(crate) generic_input: GenericInput,
162    pub(crate) bucket: String,
163}
164
165
166impl InputDescriptor for HeadBucketInput {
167    fn operation(&self) -> &str {
168        "HeadBucket"
169    }
170
171    fn bucket(&self) -> Result<&str, TosError> {
172        Ok(&self.bucket)
173    }
174}
175
176impl<B> InputTranslator<B> for HeadBucketInput {
177    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
178        let mut request = self.trans_bucket()?;
179        request.method = HttpMethodHead;
180        Ok(request)
181    }
182}
183
184
185#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
186pub struct HeadBucketOutput {
187    pub(crate) request_info: RequestInfo,
188    pub(crate) region: String,
189    pub(crate) storage_class: Option<StorageClassType>,
190    pub(crate) az_redundancy: Option<AzRedundancyType>,
191    pub(crate) project_name: String,
192    pub(crate) bucket_type: Option<BucketType>,
193}
194
195
196impl HeadBucketOutput {
197    pub fn region(&self) -> &str {
198        &self.region
199    }
200    pub fn storage_class(&self) -> &Option<StorageClassType> {
201        &self.storage_class
202    }
203    pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
204        &self.az_redundancy
205    }
206    pub fn project_name(&self) -> &str {
207        &self.project_name
208    }
209
210    pub fn bucket_type(&self) -> &Option<BucketType> {
211        &self.bucket_type
212    }
213}
214
215impl OutputParser for HeadBucketOutput {
216    fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
217        let region = get_header_value(response.headers(), HEADER_BUCKET_REGION);
218        let storage_class = StorageClassType::from(get_header_value_str(response.headers(), HEADER_STORAGE_CLASS));
219        let az_redundancy = AzRedundancyType::from(get_header_value_str(response.headers(), HEADER_AZ_REDUNDANCY));
220        let project_name = get_header_value(response.headers(), HEADER_PROJECT_NAME);
221        let bucket_type = BucketType::from(get_header_value_str(response.headers(), HEADER_BUCKET_TYPE));
222
223        Ok(Self { request_info, region, storage_class, az_redundancy, project_name, bucket_type })
224    }
225}
226
227#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
228pub struct DeleteBucketInput {
229    pub(crate) generic_input: GenericInput,
230    pub(crate) bucket: String,
231}
232
233
234impl InputDescriptor for DeleteBucketInput {
235    fn operation(&self) -> &str {
236        "DeleteBucket"
237    }
238
239    fn bucket(&self) -> Result<&str, TosError> {
240        Ok(&self.bucket)
241    }
242}
243
244impl<B> InputTranslator<B> for DeleteBucketInput {
245    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
246        let mut request = self.trans_bucket()?;
247        request.method = HttpMethodDelete;
248        Ok(request)
249    }
250}
251
252#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
253pub struct DeleteBucketOutput {
254    pub(crate) request_info: RequestInfo,
255}
256
257impl OutputParser for DeleteBucketOutput {
258    fn parse_by_ref<B>(_: &HttpRequest<B>, _: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
259        Ok(Self { request_info })
260    }
261}
262
263#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
264pub struct ListBucketsInput {
265    pub(crate) generic_input: GenericInput,
266    pub(crate) project_name: String,
267    pub(crate) bucket_type: Option<BucketType>,
268}
269
270impl ListBucketsInput {
271    pub fn new() -> Self {
272        Self::default()
273    }
274    pub fn project_name(&self) -> &str {
275        &self.project_name
276    }
277    pub fn bucket_type(&self) -> &Option<BucketType> {
278        &self.bucket_type
279    }
280    pub fn set_project_name(&mut self, project_name: impl Into<String>) {
281        self.project_name = project_name.into();
282    }
283    pub fn set_bucket_type(&mut self, bucket_type: impl Into<BucketType>) {
284        self.bucket_type = Some(bucket_type.into());
285    }
286}
287
288impl InputDescriptor for ListBucketsInput {
289    fn operation(&self) -> &str {
290        "ListBuckets"
291    }
292
293    fn bucket(&self) -> Result<&str, TosError> {
294        Err(TosError::client_error("unsupported"))
295    }
296}
297
298impl<B> InputTranslator<B> for ListBucketsInput {
299    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
300        let mut request = HttpRequest::default();
301        request.operation = self.operation();
302        request.method = HttpMethodGet;
303        map_insert(&mut request.header, HEADER_PROJECT_NAME, &self.project_name);
304        if let Some(x) = &self.bucket_type {
305            map_insert(&mut request.header, HEADER_BUCKET_TYPE, x.as_str());
306        }
307        Ok(request)
308    }
309}
310
311#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
312pub struct ListBucketsOutput {
313    #[serde(skip)]
314    pub(crate) request_info: RequestInfo,
315    #[serde(default)]
316    #[serde(rename = "Buckets")]
317    pub(crate) buckets: Vec<ListedBucket>,
318    #[serde(default)]
319    #[serde(rename = "Owner")]
320    pub(crate) owner: Owner,
321}
322
323#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
324pub struct ListedBucket {
325    #[serde(default)]
326    #[serde(rename = "CreationDate")]
327    pub(crate) creation_date: String,
328    #[serde(default)]
329    #[serde(rename = "Name")]
330    pub(crate) name: String,
331    #[serde(default)]
332    #[serde(rename = "Location")]
333    pub(crate) location: String,
334    #[serde(default)]
335    #[serde(rename = "ExtranetEndpoint")]
336    pub(crate) extranet_endpoint: String,
337    #[serde(default)]
338    #[serde(rename = "IntranetEndpoint")]
339    pub(crate) intranet_endpoint: String,
340    #[serde(default)]
341    #[serde(rename = "ProjectName")]
342    pub(crate) project_name: String,
343    #[serde(default)]
344    #[serde(rename = "BucketType")]
345    pub(crate) bucket_type: BucketType,
346}
347
348
349impl ListBucketsOutput {
350    pub fn buckets(&self) -> &Vec<ListedBucket> {
351        &self.buckets
352    }
353    pub fn owner(&self) -> &Owner {
354        &self.owner
355    }
356}
357
358impl OutputParser for ListBucketsOutput {
359    fn parse_by_ref<B>(_: &HttpRequest<B>, response: &mut HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError> {
360        let mut result = parse_json::<Self>(response)?;
361        result.request_info = request_info;
362        Ok(result)
363    }
364}
365
366impl ListedBucket {
367    pub fn creation_date(&self) -> &str {
368        &self.creation_date
369    }
370    pub fn name(&self) -> &str {
371        &self.name
372    }
373    pub fn location(&self) -> &str {
374        &self.location
375    }
376    pub fn extranet_endpoint(&self) -> &str {
377        &self.extranet_endpoint
378    }
379    pub fn intranet_endpoint(&self) -> &str {
380        &self.intranet_endpoint
381    }
382    pub fn project_name(&self) -> &str {
383        &self.project_name
384    }
385
386    pub fn bucket_type(&self) -> &BucketType {
387        &self.bucket_type
388    }
389}
390
391
392#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
393pub struct PutBucketCORSInput {
394    #[serde(skip)]
395    pub(crate) generic_input: GenericInput,
396    #[serde(skip)]
397    pub(crate) bucket: String,
398    #[serde(rename = "CORSRules")]
399    pub(crate) rules: Vec<CORSRule>,
400}
401
402impl PutBucketCORSInput {
403    pub fn new(bucket: impl Into<String>) -> Self {
404        Self {
405            generic_input: Default::default(),
406            bucket: bucket.into(),
407            rules: vec![],
408        }
409    }
410
411    pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<CORSRule>>) -> Self {
412        Self {
413            generic_input: Default::default(),
414            bucket: bucket.into(),
415            rules: rules.into(),
416        }
417    }
418
419    pub fn add_rule(&mut self, rule: impl Into<CORSRule>) {
420        self.rules.push(rule.into());
421    }
422
423    pub fn bucket(&self) -> &str {
424        &self.bucket
425    }
426    pub fn rules(&self) -> &Vec<CORSRule> {
427        &self.rules
428    }
429    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
430        self.bucket = bucket.into();
431    }
432    pub fn set_rules(&mut self, rules: impl Into<Vec<CORSRule>>) {
433        self.rules = rules.into();
434    }
435}
436
437impl InputDescriptor for PutBucketCORSInput {
438    fn operation(&self) -> &str {
439        "PutBucketCORS"
440    }
441
442    fn bucket(&self) -> Result<&str, TosError> {
443        Ok(&self.bucket)
444    }
445}
446
447impl<B> InputTranslator<B> for PutBucketCORSInput
448where
449    B: BuildBufferReader,
450{
451    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
452        if self.rules.len() == 0 {
453            return Err(TosError::client_error("empty cors rules"));
454        }
455
456        match serde_json::to_string(self) {
457            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
458            Ok(json) => {
459                let mut request = self.trans_bucket()?;
460                request.method = HttpMethodPut;
461                request.query = Some(HashMap::from([("cors", "".to_string())]));
462                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
463                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
464                request.body = Some(body);
465                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
466                Ok(request)
467            }
468        }
469    }
470}
471
472#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
473pub struct CORSRule {
474    #[serde(rename = "AllowedOrigins")]
475    #[serde(default)]
476    pub(crate) allowed_origins: Vec<String>,
477    #[serde(rename = "AllowedMethods")]
478    #[serde(default)]
479    pub(crate) allowed_methods: Vec<String>,
480    #[serde(rename = "AllowedHeaders")]
481    #[serde(default)]
482    pub(crate) allowed_headers: Vec<String>,
483    #[serde(rename = "ExposeHeaders")]
484    #[serde(default)]
485    pub(crate) expose_headers: Vec<String>,
486    #[serde(rename = "MaxAgeSeconds")]
487    #[serde(default)]
488    pub(crate) max_age_seconds: isize,
489    #[serde(rename = "ResponseVary")]
490    #[serde(default)]
491    pub(crate) response_vary: bool,
492}
493
494impl CORSRule {
495    pub fn new() -> Self {
496        Self::default()
497    }
498    pub fn allowed_origins(&self) -> &Vec<String> {
499        &self.allowed_origins
500    }
501
502    pub fn allowed_methods(&self) -> &Vec<String> {
503        &self.allowed_methods
504    }
505
506    pub fn allowed_headers(&self) -> &Vec<String> {
507        &self.allowed_headers
508    }
509
510    pub fn expose_headers(&self) -> &Vec<String> {
511        &self.expose_headers
512    }
513
514    pub fn max_age_seconds(&self) -> isize {
515        self.max_age_seconds
516    }
517
518    pub fn response_vary(&self) -> bool {
519        self.response_vary
520    }
521
522    pub fn set_allowed_origins(&mut self, allowed_origins: impl Into<Vec<String>>) {
523        self.allowed_origins = allowed_origins.into();
524    }
525
526    pub fn set_allowed_methods(&mut self, allowed_methods: impl Into<Vec<String>>) {
527        self.allowed_methods = allowed_methods.into();
528    }
529
530    pub fn set_allowed_headers(&mut self, allowed_headers: impl Into<Vec<String>>) {
531        self.allowed_headers = allowed_headers.into();
532    }
533
534    pub fn set_expose_headers(&mut self, expose_headers: impl Into<Vec<String>>) {
535        self.expose_headers = expose_headers.into();
536    }
537
538    pub fn set_max_age_seconds(&mut self, max_age_seconds: isize) {
539        self.max_age_seconds = max_age_seconds;
540    }
541
542    pub fn set_response_vary(&mut self, response_vary: bool) {
543        self.response_vary = response_vary;
544    }
545}
546
547#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
548pub struct PutBucketCORSOutput {
549    pub(crate) request_info: RequestInfo,
550}
551#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
552pub struct GetBucketCORSInput {
553    pub(crate) generic_input: GenericInput,
554    pub(crate) bucket: String,
555}
556
557impl InputDescriptor for GetBucketCORSInput {
558    fn operation(&self) -> &str {
559        "GetBucketCORS"
560    }
561
562    fn bucket(&self) -> Result<&str, TosError> {
563        Ok(&self.bucket)
564    }
565}
566
567impl<B> InputTranslator<B> for GetBucketCORSInput {
568    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
569        let mut request = self.trans_bucket()?;
570        request.query = Some(HashMap::from([("cors", "".to_string())]));
571        request.method = HttpMethodGet;
572        Ok(request)
573    }
574}
575#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
576pub struct GetBucketCORSOutput {
577    #[serde(skip)]
578    pub(crate) request_info: RequestInfo,
579    #[serde(default)]
580    #[serde(rename = "CORSRules")]
581    pub(crate) rules: Vec<CORSRule>,
582}
583
584impl GetBucketCORSOutput {
585    pub fn rules(&self) -> &Vec<CORSRule> {
586        &self.rules
587    }
588}
589
590#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
591pub struct DeleteBucketCORSInput {
592    pub(crate) generic_input: GenericInput,
593    pub(crate) bucket: String,
594}
595
596impl InputDescriptor for DeleteBucketCORSInput {
597    fn operation(&self) -> &str {
598        "DeleteBucketCORS"
599    }
600
601    fn bucket(&self) -> Result<&str, TosError> {
602        Ok(&self.bucket)
603    }
604}
605
606impl<B> InputTranslator<B> for DeleteBucketCORSInput {
607    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
608        let mut request = self.trans_bucket()?;
609        request.query = Some(HashMap::from([("cors", "".to_string())]));
610        request.method = HttpMethodDelete;
611        Ok(request)
612    }
613}
614#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
615pub struct DeleteBucketCORSOutput {
616    pub(crate) request_info: RequestInfo,
617}
618#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
619pub struct PutBucketStorageClassInput {
620    pub(crate) generic_input: GenericInput,
621    pub(crate) bucket: String,
622    pub(crate) storage_class: StorageClassType,
623}
624impl PutBucketStorageClassInput {
625    pub fn new(bucket: impl Into<String>) -> Self {
626        Self {
627            generic_input: Default::default(),
628            bucket: bucket.into(),
629            storage_class: StorageClassType::default(),
630        }
631    }
632
633    pub fn new_with_storage_class(bucket: impl Into<String>, storage_class: impl Into<StorageClassType>) -> Self {
634        Self {
635            generic_input: Default::default(),
636            bucket: bucket.into(),
637            storage_class: storage_class.into(),
638        }
639    }
640
641    pub fn bucket(&self) -> &str {
642        &self.bucket
643    }
644
645    pub fn storage_class(&self) -> &StorageClassType {
646        &self.storage_class
647    }
648
649    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
650        self.bucket = bucket.into();
651    }
652
653    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
654        self.storage_class = storage_class.into();
655    }
656}
657
658impl InputDescriptor for PutBucketStorageClassInput {
659    fn operation(&self) -> &str {
660        "PutBucketStorageClass"
661    }
662
663    fn bucket(&self) -> Result<&str, TosError> {
664        Ok(&self.bucket)
665    }
666}
667
668impl<B> InputTranslator<B> for PutBucketStorageClassInput {
669    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
670        let mut request = self.trans_bucket()?;
671        request.header.insert(HEADER_STORAGE_CLASS, self.storage_class.as_str().to_string());
672        request.query = Some(HashMap::from([("storageClass", "".to_string())]));
673        request.method = HttpMethodPut;
674        Ok(request)
675    }
676}
677#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
678pub struct PutBucketStorageClassOutput {
679    pub(crate) request_info: RequestInfo,
680}
681#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
682pub struct GetBucketLocationInput {
683    pub(crate) generic_input: GenericInput,
684    pub(crate) bucket: String,
685}
686
687impl InputDescriptor for GetBucketLocationInput {
688    fn operation(&self) -> &str {
689        "GetBucketLocation"
690    }
691
692    fn bucket(&self) -> Result<&str, TosError> {
693        Ok(&self.bucket)
694    }
695}
696
697impl<B> InputTranslator<B> for GetBucketLocationInput {
698    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
699        let mut request = self.trans_bucket()?;
700        request.query = Some(HashMap::from([("location", "".to_string())]));
701        request.method = HttpMethodGet;
702        Ok(request)
703    }
704}
705#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
706pub struct GetBucketLocationOutput {
707    #[serde(skip)]
708    pub(crate) request_info: RequestInfo,
709    #[serde(default)]
710    #[serde(rename = "Region")]
711    pub(crate) region: String,
712    #[serde(default)]
713    #[serde(rename = "ExtranetEndpoint")]
714    pub(crate) extranet_endpoint: String,
715    #[serde(default)]
716    #[serde(rename = "IntranetEndpoint")]
717    pub(crate) intranet_endpoint: String,
718}
719
720impl GetBucketLocationOutput {
721    pub fn region(&self) -> &str {
722        &self.region
723    }
724
725    pub fn extranet_endpoint(&self) -> &str {
726        &self.extranet_endpoint
727    }
728
729    pub fn intranet_endpoint(&self) -> &str {
730        &self.intranet_endpoint
731    }
732}
733
734#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
735pub struct PutBucketLifecycleInput {
736    #[serde(skip)]
737    pub(crate) generic_input: GenericInput,
738    #[serde(skip)]
739    pub(crate) bucket: String,
740    #[serde(rename = "Rules")]
741    pub(crate) rules: Vec<LifecycleRule>,
742    #[serde(skip)]
743    pub(crate) allow_same_action_overlap: bool,
744}
745
746impl PutBucketLifecycleInput {
747    pub fn new(bucket: impl Into<String>) -> Self {
748        Self {
749            generic_input: Default::default(),
750            bucket: bucket.into(),
751            rules: vec![],
752            allow_same_action_overlap: false,
753        }
754    }
755
756    pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<LifecycleRule>>) -> Self {
757        Self {
758            generic_input: Default::default(),
759            bucket: bucket.into(),
760            rules: rules.into(),
761            allow_same_action_overlap: false,
762        }
763    }
764
765    pub fn add_rule(&mut self, rule: impl Into<LifecycleRule>) {
766        self.rules.push(rule.into());
767    }
768
769    pub fn bucket(&self) -> &str {
770        &self.bucket
771    }
772
773    pub fn rules(&self) -> &Vec<LifecycleRule> {
774        &self.rules
775    }
776
777    pub fn allow_same_action_overlap(&self) -> bool {
778        self.allow_same_action_overlap
779    }
780
781    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
782        self.bucket = bucket.into();
783    }
784
785    pub fn set_rules(&mut self, rules: impl Into<Vec<LifecycleRule>>) {
786        self.rules = rules.into();
787    }
788
789    pub fn set_allow_same_action_overlap(&mut self, allow_same_action_overlap: bool) {
790        self.allow_same_action_overlap = allow_same_action_overlap;
791    }
792}
793
794impl InputDescriptor for PutBucketLifecycleInput {
795    fn operation(&self) -> &str {
796        "PutBucketLifecycle"
797    }
798
799    fn bucket(&self) -> Result<&str, TosError> {
800        Ok(&self.bucket)
801    }
802}
803
804impl<B> InputTranslator<B> for PutBucketLifecycleInput
805where
806    B: BuildBufferReader,
807{
808    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
809        if self.rules.len() == 0 {
810            return Err(TosError::client_error("empty lifecycle rules"));
811        }
812
813        match serde_json::to_string(self) {
814            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
815            Ok(json) => {
816                let mut request = self.trans_bucket()?;
817                request.method = HttpMethodPut;
818                request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
819                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
820                if self.allow_same_action_overlap {
821                    request.header.insert(HEADER_ALLOW_SAME_ACTION_OVERLAP, TRUE.to_string());
822                }
823                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
824                request.body = Some(body);
825                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
826                Ok(request)
827            }
828        }
829    }
830}
831
832#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
833pub struct LifecycleRule {
834    #[serde(rename = "ID")]
835    pub(crate) id: String,
836    #[serde(rename = "Prefix")]
837    #[serde(default)]
838    pub(crate) prefix: String,
839    #[serde(rename = "Status")]
840    pub(crate) status: StatusType,
841    #[serde(rename = "Tags")]
842    #[serde(skip_serializing_if = "Vec::is_empty")]
843    #[serde(default)]
844    pub(crate) tags: Vec<Tag>,
845    #[serde(rename = "Filter")]
846    #[serde(skip_serializing_if = "Option::is_none")]
847    pub(crate) filter: Option<LifecycleRuleFilter>,
848    #[serde(rename = "Expiration")]
849    #[serde(skip_serializing_if = "Option::is_none")]
850    pub(crate) expiration: Option<Expiration>,
851    #[serde(rename = "NoncurrentVersionExpiration")]
852    #[serde(skip_serializing_if = "Option::is_none")]
853    pub(crate) noncurrent_version_expiration: Option<NoncurrentVersionExpiration>,
854    #[serde(rename = "AbortIncompleteMultipartUpload")]
855    #[serde(skip_serializing_if = "Option::is_none")]
856    pub(crate) abort_in_complete_multipart_upload: Option<AbortInCompleteMultipartUpload>,
857    #[serde(rename = "Transitions")]
858    #[serde(skip_serializing_if = "Vec::is_empty")]
859    #[serde(default)]
860    pub(crate) transitions: Vec<Transition>,
861    #[serde(rename = "NoncurrentVersionTransitions")]
862    #[serde(skip_serializing_if = "Vec::is_empty")]
863    #[serde(default)]
864    pub(crate) noncurrent_version_transitions: Vec<NoncurrentVersionTransition>,
865    #[serde(rename = "AccessTimeTransitions")]
866    #[serde(skip_serializing_if = "Vec::is_empty")]
867    #[serde(default)]
868    pub(crate) access_time_transitions: Vec<AccessTimeTransition>,
869    #[serde(rename = "NoncurrentVersionAccessTimeTransitions")]
870    #[serde(skip_serializing_if = "Vec::is_empty")]
871    #[serde(default)]
872    pub(crate) non_current_version_access_time_transitions: Vec<NonCurrentVersionAccessTimeTransition>,
873}
874
875impl LifecycleRule {
876    pub fn new(id: impl Into<String>) -> Self {
877        let mut input = Self::default();
878        input.id = id.into();
879        input
880    }
881
882    pub fn new_with_prefix(id: impl Into<String>, prefix: impl Into<String>) -> Self {
883        let mut input = Self::default();
884        input.id = id.into();
885        input.prefix = prefix.into();
886        input
887    }
888
889    pub fn id(&self) -> &str {
890        &self.id
891    }
892
893    pub fn prefix(&self) -> &str {
894        &self.prefix
895    }
896
897    pub fn status(&self) -> &StatusType {
898        &self.status
899    }
900
901    pub fn tags(&self) -> &Vec<Tag> {
902        &self.tags
903    }
904
905    pub fn filter(&self) -> &Option<LifecycleRuleFilter> {
906        &self.filter
907    }
908
909    pub fn expiration(&self) -> &Option<Expiration> {
910        &self.expiration
911    }
912
913    pub fn noncurrent_version_expiration(&self) -> &Option<NoncurrentVersionExpiration> {
914        &self.noncurrent_version_expiration
915    }
916
917    pub fn abort_in_complete_multipart_upload(&self) -> &Option<AbortInCompleteMultipartUpload> {
918        &self.abort_in_complete_multipart_upload
919    }
920
921    pub fn transitions(&self) -> &Vec<Transition> {
922        &self.transitions
923    }
924
925    pub fn noncurrent_version_transitions(&self) -> &Vec<NoncurrentVersionTransition> {
926        &self.noncurrent_version_transitions
927    }
928
929    pub fn access_time_transitions(&self) -> &Vec<AccessTimeTransition> {
930        &self.access_time_transitions
931    }
932
933    pub fn non_current_version_access_time_transitions(&self) -> &Vec<NonCurrentVersionAccessTimeTransition> {
934        &self.non_current_version_access_time_transitions
935    }
936
937    pub fn set_id(&mut self, id: impl Into<String>) {
938        self.id = id.into();
939    }
940
941    pub fn set_prefix(&mut self, prefix: impl Into<String>) {
942        self.prefix = prefix.into();
943    }
944
945    pub fn set_status(&mut self, status: impl Into<StatusType>) {
946        self.status = status.into();
947    }
948
949    pub fn set_tags(&mut self, tags: impl Into<Vec<Tag>>) {
950        self.tags = tags.into();
951    }
952
953    pub fn set_filter(&mut self, filter: impl Into<LifecycleRuleFilter>) {
954        self.filter = Some(filter.into());
955    }
956
957    pub fn set_expiration(&mut self, expiration: impl Into<Expiration>) {
958        self.expiration = Some(expiration.into());
959    }
960
961    pub fn set_noncurrent_version_expiration(&mut self, noncurrent_version_expiration: impl Into<NoncurrentVersionExpiration>) {
962        self.noncurrent_version_expiration = Some(noncurrent_version_expiration.into());
963    }
964
965    pub fn set_abort_in_complete_multipart_upload(&mut self, abort_in_complete_multipart_upload: impl Into<AbortInCompleteMultipartUpload>) {
966        self.abort_in_complete_multipart_upload = Some(abort_in_complete_multipart_upload.into());
967    }
968
969    pub fn set_transitions(&mut self, transitions: impl Into<Vec<Transition>>) {
970        self.transitions = transitions.into();
971    }
972
973    pub fn set_noncurrent_version_transitions(&mut self, noncurrent_version_transitions: impl Into<Vec<NoncurrentVersionTransition>>) {
974        self.noncurrent_version_transitions = noncurrent_version_transitions.into();
975    }
976
977    pub fn set_access_time_transitions(&mut self, access_time_transitions: impl Into<Vec<AccessTimeTransition>>) {
978        self.access_time_transitions = access_time_transitions.into();
979    }
980
981    pub fn set_non_current_version_access_time_transitions(&mut self, non_current_version_access_time_transitions: impl Into<Vec<NonCurrentVersionAccessTimeTransition>>) {
982        self.non_current_version_access_time_transitions = non_current_version_access_time_transitions.into();
983    }
984}
985
986#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
987pub struct Transition {
988    #[serde(rename = "Date")]
989    #[serde(skip_serializing_if = "Option::is_none")]
990    pub(crate) date_string: Option<String>,
991    #[serde(skip)]
992    pub(crate) date: Option<DateTime<Utc>>,
993    #[serde(rename = "Days")]
994    #[serde(skip_serializing_if = "Option::is_none")]
995    pub(crate) days: Option<isize>,
996    #[serde(rename = "StorageClass")]
997    pub(crate) storage_class: StorageClassType,
998}
999
1000impl Transition {
1001    pub fn new(storage_class: impl Into<StorageClassType>) -> Self {
1002        Self {
1003            date_string: None,
1004            date: None,
1005            days: None,
1006            storage_class: storage_class.into(),
1007        }
1008    }
1009
1010    pub fn date(&self) -> Option<DateTime<Utc>> {
1011        self.date
1012    }
1013
1014    pub fn days(&self) -> Option<isize> {
1015        self.days
1016    }
1017
1018    pub fn storage_class(&self) -> &StorageClassType {
1019        &self.storage_class
1020    }
1021
1022    pub fn set_date(&mut self, date: impl Into<DateTime<Utc>>) {
1023        let date = date.into();
1024        self.date_string = Some(date.format(ISO8601_DATE_FORMAT).to_string());
1025        self.date = Some(date);
1026    }
1027
1028    pub fn set_days(&mut self, days: impl Into<isize>) {
1029        self.days = Some(days.into());
1030    }
1031
1032    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
1033        self.storage_class = storage_class.into();
1034    }
1035}
1036
1037#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1038pub struct Expiration {
1039    #[serde(rename = "Date")]
1040    #[serde(skip_serializing_if = "Option::is_none")]
1041    pub(crate) date_string: Option<String>,
1042    #[serde(skip)]
1043    pub(crate) date: Option<DateTime<Utc>>,
1044    #[serde(rename = "Days")]
1045    #[serde(skip_serializing_if = "Option::is_none")]
1046    pub(crate) days: Option<isize>,
1047}
1048
1049impl Expiration {
1050    pub fn new_with_date(date: impl Into<DateTime<Utc>>) -> Self {
1051        let mut exp = Self::default();
1052        exp.set_date(date);
1053        exp
1054    }
1055    pub fn new_with_days(days: impl Into<isize>) -> Self {
1056        let mut exp = Self::default();
1057        exp.set_days(days);
1058        exp
1059    }
1060
1061    pub fn date(&self) -> Option<DateTime<Utc>> {
1062        self.date
1063    }
1064
1065    pub fn days(&self) -> Option<isize> {
1066        self.days
1067    }
1068
1069    pub fn set_date(&mut self, date: impl Into<DateTime<Utc>>) {
1070        let date = date.into();
1071        self.date_string = Some(truncate_date_to_midnight(date));
1072        self.date = Some(date.into());
1073    }
1074
1075    pub fn set_days(&mut self, days: impl Into<isize>) {
1076        self.days = Some(days.into());
1077    }
1078}
1079
1080#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1081pub struct NoncurrentVersionTransition {
1082    #[serde(rename = "NoncurrentDate")]
1083    #[serde(skip_serializing_if = "Option::is_none")]
1084    pub(crate) noncurrent_date_string: Option<String>,
1085    #[serde(skip)]
1086    pub(crate) noncurrent_date: Option<DateTime<Utc>>,
1087    #[serde(rename = "NoncurrentDays")]
1088    #[serde(skip_serializing_if = "Option::is_none")]
1089    pub(crate) noncurrent_days: Option<isize>,
1090    #[serde(rename = "StorageClass")]
1091    pub(crate) storage_class: StorageClassType,
1092}
1093
1094impl NoncurrentVersionTransition {
1095    pub fn new(storage_class: impl Into<StorageClassType>) -> Self {
1096        Self {
1097            noncurrent_date_string: None,
1098            noncurrent_date: None,
1099            noncurrent_days: None,
1100            storage_class: storage_class.into(),
1101        }
1102    }
1103
1104    pub fn noncurrent_date(&self) -> Option<DateTime<Utc>> {
1105        self.noncurrent_date
1106    }
1107
1108    pub fn noncurrent_days(&self) -> Option<isize> {
1109        self.noncurrent_days
1110    }
1111
1112    pub fn storage_class(&self) -> &StorageClassType {
1113        &self.storage_class
1114    }
1115
1116    pub fn set_noncurrent_date(&mut self, noncurrent_date: impl Into<DateTime<Utc>>) {
1117        let noncurrent_date = noncurrent_date.into();
1118        self.noncurrent_date_string = Some(truncate_date_to_midnight(noncurrent_date));
1119        self.noncurrent_date = Some(noncurrent_date);
1120    }
1121
1122    pub fn set_noncurrent_days(&mut self, noncurrent_days: impl Into<isize>) {
1123        self.noncurrent_days = Some(noncurrent_days.into());
1124    }
1125
1126    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
1127        self.storage_class = storage_class.into();
1128    }
1129}
1130
1131#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1132pub struct NoncurrentVersionExpiration {
1133    #[serde(rename = "NoncurrentDate")]
1134    #[serde(skip_serializing_if = "Option::is_none")]
1135    pub(crate) noncurrent_date_string: Option<String>,
1136    #[serde(skip)]
1137    pub(crate) noncurrent_date: Option<DateTime<Utc>>,
1138    #[serde(rename = "NoncurrentDays")]
1139    #[serde(skip_serializing_if = "Option::is_none")]
1140    pub(crate) noncurrent_days: Option<isize>,
1141}
1142impl NoncurrentVersionExpiration {
1143    pub fn new_with_date(noncurrent_date: impl Into<DateTime<Utc>>) -> Self {
1144        let mut exp = Self::default();
1145        exp.set_noncurrent_date(noncurrent_date);
1146        exp
1147    }
1148
1149    pub fn new_with_days(noncurrent_days: impl Into<isize>) -> Self {
1150        let mut exp = Self::default();
1151        exp.set_noncurrent_days(noncurrent_days);
1152        exp
1153    }
1154
1155    pub fn noncurrent_date(&self) -> Option<DateTime<Utc>> {
1156        self.noncurrent_date
1157    }
1158
1159    pub fn noncurrent_days(&self) -> Option<isize> {
1160        self.noncurrent_days
1161    }
1162
1163    pub fn set_noncurrent_date(&mut self, noncurrent_date: impl Into<DateTime<Utc>>) {
1164        let noncurrent_date = noncurrent_date.into();
1165        self.noncurrent_date_string = Some(truncate_date_to_midnight(noncurrent_date));
1166        self.noncurrent_date = Some(noncurrent_date);
1167    }
1168
1169    pub fn set_noncurrent_days(&mut self, noncurrent_days: impl Into<isize>) {
1170        self.noncurrent_days = Some(noncurrent_days.into());
1171    }
1172}
1173
1174#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1175pub struct AbortInCompleteMultipartUpload {
1176    #[serde(rename = "DaysAfterInitiation")]
1177    pub(crate) days_after_initiation: isize,
1178}
1179impl AbortInCompleteMultipartUpload {
1180    pub fn new(days_after_initiation: isize) -> Self {
1181        Self {
1182            days_after_initiation
1183        }
1184    }
1185
1186    pub fn days_after_initiation(&self) -> isize {
1187        self.days_after_initiation
1188    }
1189
1190    pub fn set_days_after_initiation(&mut self, days_after_initiation: isize) {
1191        self.days_after_initiation = days_after_initiation;
1192    }
1193}
1194#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1195pub struct LifecycleRuleFilter {
1196    #[serde(rename = "ObjectSizeGreaterThan")]
1197    #[serde(default)]
1198    pub(crate) object_size_greater_than: isize,
1199    #[serde(rename = "GreaterThanIncludeEqual")]
1200    #[serde(skip_serializing_if = "Option::is_none")]
1201    pub(crate) greater_than_include_equal: Option<StatusType>,
1202    #[serde(rename = "ObjectSizeLessThan")]
1203    #[serde(default)]
1204    pub(crate) object_size_less_than: isize,
1205    #[serde(rename = "LessThanIncludeEqual")]
1206    #[serde(skip_serializing_if = "Option::is_none")]
1207    pub(crate) less_than_include_equal: Option<StatusType>,
1208}
1209
1210impl LifecycleRuleFilter {
1211    pub fn new() -> Self {
1212        Self::default()
1213    }
1214
1215    pub fn object_size_greater_than(&self) -> isize {
1216        self.object_size_greater_than
1217    }
1218
1219    pub fn greater_than_include_equal(&self) -> &Option<StatusType> {
1220        &self.greater_than_include_equal
1221    }
1222
1223    pub fn object_size_less_than(&self) -> isize {
1224        self.object_size_less_than
1225    }
1226
1227    pub fn less_than_include_equal(&self) -> &Option<StatusType> {
1228        &self.less_than_include_equal
1229    }
1230
1231    pub fn set_object_size_greater_than(&mut self, object_size_greater_than: isize) {
1232        self.object_size_greater_than = object_size_greater_than;
1233    }
1234
1235    pub fn set_greater_than_include_equal(&mut self, greater_than_include_equal: impl Into<StatusType>) {
1236        self.greater_than_include_equal = Some(greater_than_include_equal.into());
1237    }
1238
1239    pub fn set_object_size_less_than(&mut self, object_size_less_than: isize) {
1240        self.object_size_less_than = object_size_less_than;
1241    }
1242
1243    pub fn set_less_than_include_equal(&mut self, less_than_include_equal: impl Into<StatusType>) {
1244        self.less_than_include_equal = Some(less_than_include_equal.into());
1245    }
1246}
1247
1248#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1249pub struct AccessTimeTransition {
1250    #[serde(rename = "Days")]
1251    pub(crate) days: isize,
1252    #[serde(rename = "StorageClass")]
1253    pub(crate) storage_class: StorageClassType,
1254}
1255impl AccessTimeTransition {
1256    pub fn new(days: isize, storage_class: impl Into<StorageClassType>) -> Self {
1257        Self {
1258            days,
1259            storage_class: storage_class.into(),
1260        }
1261    }
1262
1263    pub fn days(&self) -> isize {
1264        self.days
1265    }
1266
1267    pub fn storage_class(&self) -> &StorageClassType {
1268        &self.storage_class
1269    }
1270
1271    pub fn set_days(&mut self, days: isize) {
1272        self.days = days;
1273    }
1274
1275    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
1276        self.storage_class = storage_class.into();
1277    }
1278}
1279#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1280pub struct NonCurrentVersionAccessTimeTransition {
1281    #[serde(rename = "NoncurrentDays")]
1282    pub(crate) non_current_days: isize,
1283    #[serde(rename = "StorageClass")]
1284    pub(crate) storage_class: StorageClassType,
1285}
1286
1287impl NonCurrentVersionAccessTimeTransition {
1288    pub fn new(non_current_days: isize, storage_class: impl Into<StorageClassType>) -> Self {
1289        Self {
1290            non_current_days,
1291            storage_class: storage_class.into(),
1292        }
1293    }
1294
1295    pub fn non_current_days(&self) -> isize {
1296        self.non_current_days
1297    }
1298
1299    pub fn storage_class(&self) -> &StorageClassType {
1300        &self.storage_class
1301    }
1302
1303    pub fn set_non_current_days(&mut self, non_current_days: isize) {
1304        self.non_current_days = non_current_days;
1305    }
1306
1307    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
1308        self.storage_class = storage_class.into();
1309    }
1310}
1311#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
1312pub struct PutBucketLifecycleOutput {
1313    pub(crate) request_info: RequestInfo,
1314}
1315
1316#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
1317pub struct GetBucketLifecycleInput {
1318    pub(crate) generic_input: GenericInput,
1319    pub(crate) bucket: String,
1320}
1321
1322impl InputDescriptor for GetBucketLifecycleInput {
1323    fn operation(&self) -> &str {
1324        "GetBucketLifecycle"
1325    }
1326
1327    fn bucket(&self) -> Result<&str, TosError> {
1328        Ok(&self.bucket)
1329    }
1330}
1331
1332
1333impl<B> InputTranslator<B> for GetBucketLifecycleInput {
1334    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1335        let mut request = self.trans_bucket()?;
1336        request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
1337        request.method = HttpMethodGet;
1338        Ok(request)
1339    }
1340}
1341
1342#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
1343pub struct GetBucketLifecycleOutput {
1344    #[serde(skip)]
1345    pub(crate) request_info: RequestInfo,
1346    #[serde(rename = "Rules")]
1347    pub(crate) rules: Vec<LifecycleRule>,
1348    #[serde(skip)]
1349    pub(crate) allow_same_action_overlap: bool,
1350}
1351
1352impl GetBucketLifecycleOutput {
1353    pub fn request_info(&self) -> &RequestInfo {
1354        &self.request_info
1355    }
1356
1357    pub fn rules(&self) -> &Vec<LifecycleRule> {
1358        &self.rules
1359    }
1360
1361    pub fn allow_same_action_overlap(&self) -> bool {
1362        self.allow_same_action_overlap
1363    }
1364}
1365
1366#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
1367pub struct DeleteBucketLifecycleInput {
1368    pub(crate) generic_input: GenericInput,
1369    pub(crate) bucket: String,
1370}
1371
1372
1373impl InputDescriptor for DeleteBucketLifecycleInput {
1374    fn operation(&self) -> &str {
1375        "DeleteBucketLifecycle"
1376    }
1377
1378    fn bucket(&self) -> Result<&str, TosError> {
1379        Ok(&self.bucket)
1380    }
1381}
1382
1383impl<B> InputTranslator<B> for DeleteBucketLifecycleInput {
1384    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1385        let mut request = self.trans_bucket()?;
1386        request.query = Some(HashMap::from([("lifecycle", "".to_string())]));
1387        request.method = HttpMethodDelete;
1388        Ok(request)
1389    }
1390}
1391
1392#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
1393pub struct DeleteBucketLifecycleOutput {
1394    pub(crate) request_info: RequestInfo,
1395}
1396#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
1397pub struct PutBucketPolicyInput {
1398    pub(crate) generic_input: GenericInput,
1399    pub(crate) bucket: String,
1400    pub(crate) policy: String,
1401}
1402impl PutBucketPolicyInput {
1403    pub fn new(bucket: impl Into<String>) -> Self {
1404        Self {
1405            generic_input: Default::default(),
1406            bucket: bucket.into(),
1407            policy: "".to_string(),
1408        }
1409    }
1410
1411    pub fn new_with_policy(&self, bucket: impl Into<String>, policy: impl Into<String>) -> Self {
1412        Self {
1413            generic_input: Default::default(),
1414            bucket: bucket.into(),
1415            policy: policy.into(),
1416        }
1417    }
1418
1419    pub fn bucket(&self) -> &str {
1420        &self.bucket
1421    }
1422
1423    pub fn policy(&self) -> &str {
1424        &self.policy
1425    }
1426
1427    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
1428        self.bucket = bucket.into();
1429    }
1430
1431    pub fn set_policy(&mut self, policy: impl Into<String>) {
1432        self.policy = policy.into();
1433    }
1434}
1435
1436impl InputDescriptor for PutBucketPolicyInput {
1437    fn operation(&self) -> &str {
1438        "PutBucketPolicy"
1439    }
1440
1441    fn bucket(&self) -> Result<&str, TosError> {
1442        Ok(&self.bucket)
1443    }
1444}
1445
1446impl<B> InputTranslator<B> for PutBucketPolicyInput
1447where
1448    B: BuildBufferReader,
1449{
1450    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1451        if self.policy == "" {
1452            return Err(TosError::client_error("empty policy"));
1453        }
1454
1455        let mut request = self.trans_bucket()?;
1456        request.query = Some(HashMap::from([("policy", "".to_string())]));
1457        request.method = HttpMethodPut;
1458        request.header.insert(HEADER_CONTENT_MD5, base64_md5(&self.policy));
1459        let (body, len) = B::new(Bytes::from(self.policy.clone().into_bytes()))?;
1460        request.body = Some(body);
1461        request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
1462        Ok(request)
1463    }
1464}
1465
1466#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
1467pub struct PutBucketPolicyOutput {
1468    pub(crate) request_info: RequestInfo,
1469}
1470
1471#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
1472pub struct GetBucketPolicyInput {
1473    pub(crate) generic_input: GenericInput,
1474    pub(crate) bucket: String,
1475}
1476
1477impl InputDescriptor for GetBucketPolicyInput {
1478    fn operation(&self) -> &str {
1479        "GetBucketPolicy"
1480    }
1481
1482    fn bucket(&self) -> Result<&str, TosError> {
1483        Ok(&self.bucket)
1484    }
1485}
1486
1487impl<B> InputTranslator<B> for GetBucketPolicyInput {
1488    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1489        let mut request = self.trans_bucket()?;
1490        request.query = Some(HashMap::from([("policy", "".to_string())]));
1491        request.method = HttpMethodGet;
1492        Ok(request)
1493    }
1494}
1495
1496#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
1497pub struct GetBucketPolicyOutput {
1498    pub(crate) request_info: RequestInfo,
1499    pub(crate) policy: String,
1500}
1501
1502impl GetBucketPolicyOutput {
1503    pub fn policy(&self) -> &str {
1504        &self.policy
1505    }
1506}
1507
1508#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
1509pub struct DeleteBucketPolicyInput {
1510    pub(crate) generic_input: GenericInput,
1511    pub(crate) bucket: String,
1512}
1513
1514impl InputDescriptor for DeleteBucketPolicyInput {
1515    fn operation(&self) -> &str {
1516        "DeleteBucketPolicy"
1517    }
1518
1519    fn bucket(&self) -> Result<&str, TosError> {
1520        Ok(&self.bucket)
1521    }
1522}
1523
1524impl<B> InputTranslator<B> for DeleteBucketPolicyInput {
1525    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1526        let mut request = self.trans_bucket()?;
1527        request.query = Some(HashMap::from([("policy", "".to_string())]));
1528        request.method = HttpMethodDelete;
1529        Ok(request)
1530    }
1531}
1532
1533#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
1534pub struct DeleteBucketPolicyOutput {
1535    pub(crate) request_info: RequestInfo,
1536}
1537#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
1538pub struct PutBucketMirrorBackInput {
1539    #[serde(skip)]
1540    pub(crate) generic_input: GenericInput,
1541    #[serde(skip)]
1542    pub(crate) bucket: String,
1543    #[serde(rename = "Rules")]
1544    pub(crate) rules: Vec<MirrorBackRule>,
1545}
1546
1547impl PutBucketMirrorBackInput {
1548    pub fn new(bucket: impl Into<String>) -> Self {
1549        Self {
1550            generic_input: Default::default(),
1551            bucket: bucket.into(),
1552            rules: vec![],
1553        }
1554    }
1555    pub fn new_with_rules(bucket: impl Into<String>, rules: impl Into<Vec<MirrorBackRule>>) -> Self {
1556        Self {
1557            generic_input: Default::default(),
1558            bucket: bucket.into(),
1559            rules: rules.into(),
1560        }
1561    }
1562
1563    pub fn add_rule(&mut self, rule: impl Into<MirrorBackRule>) {
1564        self.rules.push(rule.into());
1565    }
1566
1567    pub fn bucket(&self) -> &str {
1568        &self.bucket
1569    }
1570
1571    pub fn rules(&self) -> &Vec<MirrorBackRule> {
1572        &self.rules
1573    }
1574
1575    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
1576        self.bucket = bucket.into();
1577    }
1578
1579    pub fn set_rules(&mut self, rules: impl Into<Vec<MirrorBackRule>>) {
1580        self.rules = rules.into();
1581    }
1582}
1583
1584impl InputDescriptor for PutBucketMirrorBackInput {
1585    fn operation(&self) -> &str {
1586        "PutBucketMirrorBack"
1587    }
1588
1589    fn bucket(&self) -> Result<&str, TosError> {
1590        Ok(&self.bucket)
1591    }
1592}
1593
1594impl<B> InputTranslator<B> for PutBucketMirrorBackInput
1595where
1596    B: BuildBufferReader,
1597{
1598    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
1599        if self.rules.len() == 0 {
1600            return Err(TosError::client_error("empty mirror back rules"));
1601        }
1602
1603        match serde_json::to_string(self) {
1604            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
1605            Ok(json) => {
1606                let mut request = self.trans_bucket()?;
1607                request.method = HttpMethodPut;
1608                request.query = Some(HashMap::from([("mirror", "".to_string())]));
1609                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
1610                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
1611                request.body = Some(body);
1612                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
1613                Ok(request)
1614            }
1615        }
1616    }
1617}
1618
1619#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1620pub struct MirrorBackRule {
1621    #[serde(rename = "ID")]
1622    pub(crate) id: String,
1623    #[serde(rename = "Condition")]
1624    pub(crate) condition: Condition,
1625    #[serde(rename = "Redirect")]
1626    pub(crate) redirect: Redirect,
1627}
1628
1629impl MirrorBackRule {
1630    pub fn new(id: impl Into<String>) -> Self {
1631        let mut input = Self::default();
1632        input.id = id.into();
1633        input
1634    }
1635
1636    pub fn id(&self) -> &str {
1637        &self.id
1638    }
1639
1640    pub fn condition(&self) -> &Condition {
1641        &self.condition
1642    }
1643
1644    pub fn redirect(&self) -> &Redirect {
1645        &self.redirect
1646    }
1647
1648    pub fn set_id(&mut self, id: impl Into<String>) {
1649        self.id = id.into();
1650    }
1651
1652    pub fn set_condition(&mut self, condition: impl Into<Condition>) {
1653        self.condition = condition.into();
1654    }
1655
1656    pub fn set_redirect(&mut self, redirect: impl Into<Redirect>) {
1657        self.redirect = redirect.into();
1658    }
1659}
1660
1661#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1662pub struct Condition {
1663    #[serde(rename = "HttpCode")]
1664    pub(crate) http_code: isize,
1665    #[serde(rename = "KeyPrefix")]
1666    #[serde(skip_serializing_if = "String::is_empty")]
1667    #[serde(default)]
1668    pub(crate) key_prefix: String,
1669    #[serde(rename = "KeySuffix")]
1670    #[serde(skip_serializing_if = "String::is_empty")]
1671    #[serde(default)]
1672    pub(crate) key_suffix: String,
1673    #[serde(rename = "AllowHost")]
1674    #[serde(skip_serializing_if = "Vec::is_empty")]
1675    #[serde(default)]
1676    pub(crate) allow_host: Vec<String>,
1677    #[serde(rename = "HttpMethod")]
1678    #[serde(skip_serializing_if = "Vec::is_empty")]
1679    #[serde(default)]
1680    pub(crate) http_method: Vec<String>,
1681}
1682impl Condition {
1683    pub fn new(http_code: isize) -> Self {
1684        Self {
1685            http_code,
1686            key_prefix: "".to_string(),
1687            key_suffix: "".to_string(),
1688            allow_host: vec![],
1689            http_method: vec![],
1690        }
1691    }
1692
1693    pub fn http_code(&self) -> isize {
1694        self.http_code
1695    }
1696
1697    pub fn key_prefix(&self) -> &str {
1698        &self.key_prefix
1699    }
1700
1701    pub fn key_suffix(&self) -> &str {
1702        &self.key_suffix
1703    }
1704
1705    pub fn allow_host(&self) -> &Vec<String> {
1706        &self.allow_host
1707    }
1708
1709    pub fn http_method(&self) -> &Vec<String> {
1710        &self.http_method
1711    }
1712
1713    pub fn set_http_code(&mut self, http_code: isize) {
1714        self.http_code = http_code;
1715    }
1716
1717    pub fn set_key_prefix(&mut self, key_prefix: impl Into<String>) {
1718        self.key_prefix = key_prefix.into();
1719    }
1720
1721    pub fn set_key_suffix(&mut self, key_suffix: impl Into<String>) {
1722        self.key_suffix = key_suffix.into();
1723    }
1724
1725    pub fn set_allow_host(&mut self, allow_host: impl Into<Vec<String>>) {
1726        self.allow_host = allow_host.into();
1727    }
1728
1729    pub fn set_http_method(&mut self, http_method: impl Into<Vec<String>>) {
1730        self.http_method = http_method.into();
1731    }
1732}
1733
1734#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1735pub struct Redirect {
1736    #[serde(rename = "RedirectType")]
1737    pub(crate) redirect_type: RedirectType,
1738    #[serde(rename = "DisableUploadSourceForNoneRangeMirror")]
1739    #[serde(default)]
1740    pub(crate) fetch_source_on_redirect: bool,
1741    #[serde(rename = "PassQuery")]
1742    #[serde(default)]
1743    pub(crate) pass_query: bool,
1744    #[serde(rename = "FollowRedirect")]
1745    #[serde(default)]
1746    pub(crate) follow_redirect: bool,
1747    #[serde(rename = "MirrorHeader")]
1748    #[serde(skip_serializing_if = "Option::is_none")]
1749    pub(crate) mirror_header: Option<MirrorHeader>,
1750    #[serde(rename = "PublicSource")]
1751    #[serde(skip_serializing_if = "Option::is_none")]
1752    pub(crate) public_source: Option<PublicSource>,
1753    #[serde(rename = "PrivateSource")]
1754    #[serde(skip_serializing_if = "Option::is_none")]
1755    pub(crate) private_source: Option<PrivateSource>,
1756    #[serde(rename = "Transform")]
1757    #[serde(skip_serializing_if = "Option::is_none")]
1758    pub(crate) transform: Option<Transform>,
1759    #[serde(rename = "FetchHeaderToMetaDataRules")]
1760    #[serde(skip_serializing_if = "Vec::is_empty")]
1761    #[serde(default)]
1762    pub(crate) fetch_header_to_meta_data_rules: Vec<FetchHeaderToMetaDataRule>,
1763    #[serde(rename = "FetchSourceOnRedirectWithQuery")]
1764    #[serde(skip_serializing_if = "Option::is_none")]
1765    pub(crate) fetch_source_on_redirect_with_query: Option<bool>,
1766    #[serde(rename = "PassStatusCodeFromSource")]
1767    #[serde(skip_serializing_if = "Vec::is_empty")]
1768    #[serde(default)]
1769    pub(crate) pass_status_code_from_source: Vec<isize>,
1770    #[serde(rename = "PassHeaderFromSource")]
1771    #[serde(skip_serializing_if = "Vec::is_empty")]
1772    #[serde(default)]
1773    pub(crate) pass_header_from_source: Vec<String>,
1774}
1775impl Redirect {
1776    pub fn new(redirect_type: impl Into<RedirectType>, fetch_source_on_redirect: bool) -> Self {
1777        let mut default = Self::default();
1778        default.redirect_type = redirect_type.into();
1779        default.fetch_source_on_redirect = fetch_source_on_redirect;
1780        default
1781    }
1782
1783    pub fn redirect_type(&self) -> &RedirectType {
1784        &self.redirect_type
1785    }
1786
1787    pub fn fetch_source_on_redirect(&self) -> bool {
1788        self.fetch_source_on_redirect
1789    }
1790
1791    pub fn pass_query(&self) -> bool {
1792        self.pass_query
1793    }
1794
1795    pub fn follow_redirect(&self) -> bool {
1796        self.follow_redirect
1797    }
1798
1799    pub fn mirror_header(&self) -> &Option<MirrorHeader> {
1800        &self.mirror_header
1801    }
1802
1803    pub fn public_source(&self) -> &Option<PublicSource> {
1804        &self.public_source
1805    }
1806
1807    pub fn private_source(&self) -> &Option<PrivateSource> {
1808        &self.private_source
1809    }
1810
1811    pub fn transform(&self) -> &Option<Transform> {
1812        &self.transform
1813    }
1814
1815    pub fn fetch_header_to_meta_data_rules(&self) -> &Vec<FetchHeaderToMetaDataRule> {
1816        &self.fetch_header_to_meta_data_rules
1817    }
1818
1819    pub fn fetch_source_on_redirect_with_query(&self) -> Option<bool> {
1820        self.fetch_source_on_redirect_with_query
1821    }
1822
1823    pub fn pass_status_code_from_source(&self) -> &Vec<isize> {
1824        &self.pass_status_code_from_source
1825    }
1826
1827    pub fn pass_header_from_source(&self) -> &Vec<String> {
1828        &self.pass_header_from_source
1829    }
1830
1831    pub fn set_redirect_type(&mut self, redirect_type: impl Into<RedirectType>) {
1832        self.redirect_type = redirect_type.into();
1833    }
1834
1835    pub fn set_fetch_source_on_redirect(&mut self, fetch_source_on_redirect: bool) {
1836        self.fetch_source_on_redirect = fetch_source_on_redirect;
1837    }
1838
1839    pub fn set_pass_query(&mut self, pass_query: bool) {
1840        self.pass_query = pass_query;
1841    }
1842
1843    pub fn set_follow_redirect(&mut self, follow_redirect: bool) {
1844        self.follow_redirect = follow_redirect;
1845    }
1846
1847    pub fn set_mirror_header(&mut self, mirror_header: impl Into<MirrorHeader>) {
1848        self.mirror_header = Some(mirror_header.into());
1849    }
1850
1851    pub fn set_public_source(&mut self, public_source: impl Into<PublicSource>) {
1852        self.public_source = Some(public_source.into());
1853    }
1854
1855    pub fn set_private_source(&mut self, private_source: impl Into<PrivateSource>) {
1856        self.private_source = Some(private_source.into());
1857    }
1858
1859    pub fn set_transform(&mut self, transform: impl Into<Transform>) {
1860        self.transform = Some(transform.into());
1861    }
1862
1863    pub fn set_fetch_header_to_meta_data_rules(&mut self, fetch_header_to_meta_data_rules: impl Into<Vec<FetchHeaderToMetaDataRule>>) {
1864        self.fetch_header_to_meta_data_rules = fetch_header_to_meta_data_rules.into();
1865    }
1866
1867    pub fn set_fetch_source_on_redirect_with_query(&mut self, fetch_source_on_redirect_with_query: impl Into<bool>) {
1868        self.fetch_source_on_redirect_with_query = Some(fetch_source_on_redirect_with_query.into());
1869    }
1870
1871    pub fn set_pass_status_code_from_source(&mut self, pass_status_code_from_source: impl Into<Vec<isize>>) {
1872        self.pass_status_code_from_source = pass_status_code_from_source.into();
1873    }
1874
1875    pub fn set_pass_header_from_source(&mut self, pass_header_from_source: impl Into<Vec<String>>) {
1876        self.pass_header_from_source = pass_header_from_source.into();
1877    }
1878}
1879#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1880pub struct MirrorHeader {
1881    #[serde(rename = "PassAll")]
1882    #[serde(default)]
1883    pub(crate) pass_all: bool,
1884    #[serde(rename = "Pass")]
1885    #[serde(skip_serializing_if = "Vec::is_empty")]
1886    #[serde(default)]
1887    pub(crate) pass: Vec<String>,
1888    #[serde(rename = "Remove")]
1889    #[serde(skip_serializing_if = "Vec::is_empty")]
1890    #[serde(default)]
1891    pub(crate) remove: Vec<String>,
1892    #[serde(rename = "Set")]
1893    #[serde(skip_serializing_if = "Vec::is_empty")]
1894    #[serde(default)]
1895    pub(crate) set: Vec<MirrorHeaderKeyValue>,
1896}
1897impl MirrorHeader {
1898    pub fn new() -> Self {
1899        Self {
1900            pass_all: false,
1901            pass: vec![],
1902            remove: vec![],
1903            set: vec![],
1904        }
1905    }
1906
1907    pub fn pass_all(&self) -> bool {
1908        self.pass_all
1909    }
1910
1911    pub fn pass(&self) -> &Vec<String> {
1912        &self.pass
1913    }
1914
1915    pub fn remove(&self) -> &Vec<String> {
1916        &self.remove
1917    }
1918
1919    pub fn set(&self) -> &Vec<MirrorHeaderKeyValue> {
1920        &self.set
1921    }
1922
1923    pub fn set_pass_all(&mut self, pass_all: bool) {
1924        self.pass_all = pass_all;
1925    }
1926
1927    pub fn set_pass(&mut self, pass: impl Into<Vec<String>>) {
1928        self.pass = pass.into();
1929    }
1930
1931    pub fn set_remove(&mut self, remove: impl Into<Vec<String>>) {
1932        self.remove = remove.into();
1933    }
1934
1935    pub fn set_set(&mut self, set: impl Into<Vec<MirrorHeaderKeyValue>>) {
1936        self.set = set.into();
1937    }
1938}
1939#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1940pub struct MirrorHeaderKeyValue {
1941    #[serde(rename = "Key")]
1942    #[serde(skip_serializing_if = "String::is_empty")]
1943    #[serde(default)]
1944    pub(crate) key: String,
1945    #[serde(rename = "Value")]
1946    #[serde(skip_serializing_if = "String::is_empty")]
1947    #[serde(default)]
1948    pub(crate) value: String,
1949}
1950impl MirrorHeaderKeyValue {
1951    pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
1952        Self {
1953            key: key.into(),
1954            value: value.into(),
1955        }
1956    }
1957
1958    pub fn key(&self) -> &str {
1959        &self.key
1960    }
1961
1962    pub fn value(&self) -> &str {
1963        &self.value
1964    }
1965
1966    pub fn set_key(&mut self, key: impl Into<String>) {
1967        self.key = key.into();
1968    }
1969
1970    pub fn set_value(&mut self, value: impl Into<String>) {
1971        self.value = value.into();
1972    }
1973}
1974
1975#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1976pub struct PublicSource {
1977    #[serde(rename = "SourceEndpoint")]
1978    #[serde(default)]
1979    pub(crate) source_endpoint: SourceEndpoint,
1980    #[serde(rename = "FixedEndpoint")]
1981    #[serde(default)]
1982    pub(crate) fixed_endpoint: bool,
1983}
1984impl PublicSource {
1985    pub fn new(source_endpoint: impl Into<SourceEndpoint>) -> Self {
1986        Self {
1987            source_endpoint: source_endpoint.into(),
1988            fixed_endpoint: false,
1989        }
1990    }
1991
1992    pub fn source_endpoint(&self) -> &SourceEndpoint {
1993        &self.source_endpoint
1994    }
1995
1996    pub fn fixed_endpoint(&self) -> bool {
1997        self.fixed_endpoint
1998    }
1999
2000    pub fn set_source_endpoint(&mut self, source_endpoint: impl Into<SourceEndpoint>) {
2001        self.source_endpoint = source_endpoint.into();
2002    }
2003
2004    pub fn set_fixed_endpoint(&mut self, fixed_endpoint: bool) {
2005        self.fixed_endpoint = fixed_endpoint;
2006    }
2007}
2008
2009#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2010pub struct SourceEndpoint {
2011    #[serde(rename = "Primary")]
2012    #[serde(skip_serializing_if = "Vec::is_empty")]
2013    #[serde(default)]
2014    pub(crate) primary: Vec<String>,
2015    #[serde(rename = "Follower")]
2016    #[serde(skip_serializing_if = "Vec::is_empty")]
2017    #[serde(default)]
2018    pub(crate) follower: Vec<String>,
2019}
2020impl SourceEndpoint {
2021    pub fn new(primary: impl Into<Vec<String>>) -> Self {
2022        Self {
2023            primary: primary.into(),
2024            follower: vec![],
2025        }
2026    }
2027
2028    pub fn primary(&self) -> &Vec<String> {
2029        &self.primary
2030    }
2031
2032    pub fn follower(&self) -> &Vec<String> {
2033        &self.follower
2034    }
2035
2036    pub fn set_primary(&mut self, primary: impl Into<Vec<String>>) {
2037        self.primary = primary.into();
2038    }
2039
2040    pub fn set_follower(&mut self, follower: impl Into<Vec<String>>) {
2041        self.follower = follower.into();
2042    }
2043}
2044#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2045pub struct PrivateSource {
2046    #[serde(rename = "SourceEndpoint")]
2047    pub(crate) source_endpoint: CommonSourceEndpoint,
2048}
2049impl PrivateSource {
2050    pub fn new(source_endpoint: impl Into<CommonSourceEndpoint>) -> Self {
2051        Self {
2052            source_endpoint: source_endpoint.into(),
2053        }
2054    }
2055
2056    pub fn source_endpoint(&self) -> &CommonSourceEndpoint {
2057        &self.source_endpoint
2058    }
2059
2060    pub fn set_source_endpoint(&mut self, source_endpoint: impl Into<CommonSourceEndpoint>) {
2061        self.source_endpoint = source_endpoint.into();
2062    }
2063}
2064#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2065pub struct CommonSourceEndpoint {
2066    #[serde(rename = "Primary")]
2067    #[serde(skip_serializing_if = "Vec::is_empty")]
2068    #[serde(default)]
2069    pub(crate) primary: Vec<EndpointCredentialProvider>,
2070    #[serde(rename = "Follower")]
2071    #[serde(skip_serializing_if = "Vec::is_empty")]
2072    #[serde(default)]
2073    pub(crate) follower: Vec<EndpointCredentialProvider>,
2074}
2075impl CommonSourceEndpoint {
2076    pub fn new(primary: impl Into<Vec<EndpointCredentialProvider>>) -> Self {
2077        Self {
2078            primary: primary.into(),
2079            follower: vec![],
2080        }
2081    }
2082
2083    pub fn primary(&self) -> &Vec<EndpointCredentialProvider> {
2084        &self.primary
2085    }
2086
2087    pub fn follower(&self) -> &Vec<EndpointCredentialProvider> {
2088        &self.follower
2089    }
2090
2091    pub fn set_primary(&mut self, primary: impl Into<Vec<EndpointCredentialProvider>>) {
2092        self.primary = primary.into();
2093    }
2094
2095    pub fn set_follower(&mut self, follower: impl Into<Vec<EndpointCredentialProvider>>) {
2096        self.follower = follower.into();
2097    }
2098}
2099#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2100pub struct EndpointCredentialProvider {
2101    #[serde(rename = "Endpoint")]
2102    #[serde(skip_serializing_if = "String::is_empty")]
2103    #[serde(default)]
2104    pub(crate) endpoint: String,
2105    #[serde(rename = "BucketName")]
2106    #[serde(skip_serializing_if = "String::is_empty")]
2107    #[serde(default)]
2108    pub(crate) bucket_name: String,
2109    #[serde(rename = "CredentialProvider")]
2110    pub(crate) credential_provider: CommonCredentialProvider,
2111}
2112impl EndpointCredentialProvider {
2113    pub fn new(endpoint: impl Into<String>) -> Self {
2114        Self {
2115            endpoint: endpoint.into(),
2116            bucket_name: "".to_string(),
2117            credential_provider: Default::default(),
2118        }
2119    }
2120
2121    pub fn endpoint(&self) -> &str {
2122        &self.endpoint
2123    }
2124
2125    pub fn bucket_name(&self) -> &str {
2126        &self.bucket_name
2127    }
2128
2129    pub fn credential_provider(&self) -> &CommonCredentialProvider {
2130        &self.credential_provider
2131    }
2132
2133    pub fn set_endpoint(&mut self, endpoint: impl Into<String>) {
2134        self.endpoint = endpoint.into();
2135    }
2136
2137    pub fn set_bucket_name(&mut self, bucket_name: impl Into<String>) {
2138        self.bucket_name = bucket_name.into();
2139    }
2140
2141    pub fn set_credential_provider(&mut self, credential_provider: impl Into<CommonCredentialProvider>) {
2142        self.credential_provider = credential_provider.into();
2143    }
2144}
2145#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2146pub struct CommonCredentialProvider {
2147    #[serde(rename = "Role")]
2148    #[serde(skip_serializing_if = "String::is_empty")]
2149    #[serde(default)]
2150    pub(crate) role: String,
2151    #[serde(rename = "StaticCredential")]
2152    #[serde(skip_serializing_if = "Option::is_none")]
2153    pub(crate) static_credential: Option<CommonStaticCredential>,
2154    #[serde(rename = "Region")]
2155    #[serde(skip_serializing_if = "String::is_empty")]
2156    #[serde(default)]
2157    pub(crate) region: String,
2158}
2159impl CommonCredentialProvider {
2160    pub fn new_with_role(role: impl Into<String>) -> Self {
2161        Self {
2162            role: role.into(),
2163            static_credential: None,
2164            region: "".to_string(),
2165        }
2166    }
2167    pub fn new_with_static_credential(static_credential: impl Into<CommonStaticCredential>, region: impl Into<String>) -> Self {
2168        Self {
2169            role: "".to_string(),
2170            static_credential: Some(static_credential.into()),
2171            region: region.into(),
2172        }
2173    }
2174
2175    pub fn role(&self) -> &str {
2176        &self.role
2177    }
2178
2179    pub fn static_credential(&self) -> &Option<CommonStaticCredential> {
2180        &self.static_credential
2181    }
2182
2183    pub fn region(&self) -> &str {
2184        &self.region
2185    }
2186
2187    pub fn set_role(&mut self, role: impl Into<String>) {
2188        self.role = role.into();
2189    }
2190
2191    pub fn set_static_credential(&mut self, static_credential: impl Into<CommonStaticCredential>) {
2192        self.static_credential = Some(static_credential.into());
2193    }
2194
2195    pub fn set_region(&mut self, region: impl Into<String>) {
2196        self.region = region.into();
2197    }
2198}
2199#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2200pub struct CommonStaticCredential {
2201    #[serde(rename = "StorageVendor")]
2202    pub(crate) storage_vendor: String,
2203    #[serde(rename = "AK")]
2204    pub(crate) ak: String,
2205    #[serde(rename = "SK")]
2206    pub(crate) sk: String,
2207    #[serde(rename = "SKEncryptType")]
2208    #[serde(skip_serializing)]
2209    pub(crate) sk_encrypt_type: String,
2210}
2211impl CommonStaticCredential {
2212    pub fn new(storage_vendor: impl Into<String>) -> Self {
2213        Self {
2214            storage_vendor: storage_vendor.into(),
2215            ak: "".to_string(),
2216            sk: "".to_string(),
2217            sk_encrypt_type: "".to_string(),
2218        }
2219    }
2220
2221    pub fn storage_vendor(&self) -> &str {
2222        &self.storage_vendor
2223    }
2224
2225    pub fn ak(&self) -> &str {
2226        &self.ak
2227    }
2228
2229    pub fn sk(&self) -> &str {
2230        &self.sk
2231    }
2232
2233    pub fn sk_encrypt_type(&self) -> &str {
2234        &self.sk_encrypt_type
2235    }
2236
2237    pub fn set_storage_vendor(&mut self, storage_vendor: impl Into<String>) {
2238        self.storage_vendor = storage_vendor.into();
2239    }
2240
2241    pub fn set_ak(&mut self, ak: impl Into<String>) {
2242        self.ak = ak.into();
2243    }
2244
2245    pub fn set_sk(&mut self, sk: impl Into<String>) {
2246        self.sk = sk.into();
2247    }
2248}
2249
2250#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2251pub struct Transform {
2252    #[serde(rename = "WithKeyPrefix")]
2253    #[serde(skip_serializing_if = "String::is_empty")]
2254    #[serde(default)]
2255    pub(crate) with_key_prefix: String,
2256    #[serde(rename = "WithKeySuffix")]
2257    #[serde(skip_serializing_if = "String::is_empty")]
2258    #[serde(default)]
2259    pub(crate) with_key_suffix: String,
2260    #[serde(rename = "ReplaceKeyPrefix")]
2261    #[serde(skip_serializing_if = "Option::is_none")]
2262    pub(crate) replace_key_prefix: Option<ReplaceKeyPrefix>,
2263}
2264impl Transform {
2265    pub fn new() -> Self {
2266        Self {
2267            with_key_prefix: "".to_string(),
2268            with_key_suffix: "".to_string(),
2269            replace_key_prefix: Default::default(),
2270        }
2271    }
2272
2273    pub fn with_key_prefix(&self) -> &str {
2274        &self.with_key_prefix
2275    }
2276
2277    pub fn with_key_suffix(&self) -> &str {
2278        &self.with_key_suffix
2279    }
2280
2281    pub fn replace_key_prefix(&self) -> &Option<ReplaceKeyPrefix> {
2282        &self.replace_key_prefix
2283    }
2284
2285    pub fn set_with_key_prefix(&mut self, with_key_prefix: impl Into<String>) {
2286        self.with_key_prefix = with_key_prefix.into();
2287    }
2288
2289    pub fn set_with_key_suffix(&mut self, with_key_suffix: impl Into<String>) {
2290        self.with_key_suffix = with_key_suffix.into();
2291    }
2292
2293    pub fn set_replace_key_prefix(&mut self, replace_key_prefix: impl Into<ReplaceKeyPrefix>) {
2294        self.replace_key_prefix = Some(replace_key_prefix.into());
2295    }
2296}
2297#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2298pub struct ReplaceKeyPrefix {
2299    #[serde(rename = "KeyPrefix")]
2300    #[serde(skip_serializing_if = "String::is_empty")]
2301    #[serde(default)]
2302    pub(crate) key_prefix: String,
2303    #[serde(rename = "ReplaceWith")]
2304    #[serde(skip_serializing_if = "String::is_empty")]
2305    #[serde(default)]
2306    pub(crate) replace_with: String,
2307}
2308impl ReplaceKeyPrefix {
2309    pub fn new(key_prefix: impl Into<String>, replace_with: impl Into<String>) -> Self {
2310        Self {
2311            key_prefix: key_prefix.into(),
2312            replace_with: replace_with.into(),
2313        }
2314    }
2315
2316    pub fn key_prefix(&self) -> &str {
2317        &self.key_prefix
2318    }
2319
2320    pub fn replace_with(&self) -> &str {
2321        &self.replace_with
2322    }
2323
2324    pub fn set_key_prefix(&mut self, key_prefix: impl Into<String>) {
2325        self.key_prefix = key_prefix.into();
2326    }
2327
2328    pub fn set_replace_with(&mut self, replace_with: impl Into<String>) {
2329        self.replace_with = replace_with.into();
2330    }
2331}
2332#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2333pub struct FetchHeaderToMetaDataRule {
2334    #[serde(rename = "SourceHeader")]
2335    #[serde(skip_serializing_if = "String::is_empty")]
2336    #[serde(default)]
2337    pub(crate) source_header: String,
2338    #[serde(rename = "MetaDataSuffix")]
2339    #[serde(skip_serializing_if = "String::is_empty")]
2340    #[serde(default)]
2341    pub(crate) meta_data_suffix: String,
2342}
2343impl FetchHeaderToMetaDataRule {
2344    pub fn new(source_header: impl Into<String>, meta_data_suffix: impl Into<String>) -> Self {
2345        Self {
2346            source_header: source_header.into(),
2347            meta_data_suffix: meta_data_suffix.into(),
2348        }
2349    }
2350
2351    pub fn source_header(&self) -> &str {
2352        &self.source_header
2353    }
2354
2355    pub fn meta_data_suffix(&self) -> &str {
2356        &self.meta_data_suffix
2357    }
2358
2359    pub fn set_source_header(&mut self, source_header: impl Into<String>) {
2360        self.source_header = source_header.into();
2361    }
2362
2363    pub fn set_meta_data_suffix(&mut self, meta_data_suffix: impl Into<String>) {
2364        self.meta_data_suffix = meta_data_suffix.into();
2365    }
2366}
2367#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
2368pub struct PutBucketMirrorBackOutput {
2369    pub(crate) request_info: RequestInfo,
2370}
2371
2372#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
2373pub struct GetBucketMirrorBackInput {
2374    pub(crate) generic_input: GenericInput,
2375    pub(crate) bucket: String,
2376}
2377impl InputDescriptor for GetBucketMirrorBackInput {
2378    fn operation(&self) -> &str {
2379        "GetBucketMirrorBack"
2380    }
2381
2382    fn bucket(&self) -> Result<&str, TosError> {
2383        Ok(&self.bucket)
2384    }
2385}
2386
2387impl<B> InputTranslator<B> for GetBucketMirrorBackInput {
2388    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2389        let mut request = self.trans_bucket()?;
2390        request.query = Some(HashMap::from([("mirror", "".to_string())]));
2391        request.method = HttpMethodGet;
2392        Ok(request)
2393    }
2394}
2395#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
2396pub struct GetBucketMirrorBackOutput {
2397    #[serde(skip)]
2398    pub(crate) request_info: RequestInfo,
2399    #[serde(rename = "Rules")]
2400    pub(crate) rules: Vec<MirrorBackRule>,
2401}
2402
2403impl GetBucketMirrorBackOutput {
2404    pub fn rules(&self) -> &Vec<MirrorBackRule> {
2405        &self.rules
2406    }
2407}
2408
2409#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
2410pub struct DeleteBucketMirrorBackInput {
2411    pub(crate) generic_input: GenericInput,
2412    pub(crate) bucket: String,
2413}
2414impl InputDescriptor for DeleteBucketMirrorBackInput {
2415    fn operation(&self) -> &str {
2416        "DeleteBucketMirrorBack"
2417    }
2418
2419    fn bucket(&self) -> Result<&str, TosError> {
2420        Ok(&self.bucket)
2421    }
2422}
2423
2424impl<B> InputTranslator<B> for DeleteBucketMirrorBackInput {
2425    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2426        let mut request = self.trans_bucket()?;
2427        request.query = Some(HashMap::from([("mirror", "".to_string())]));
2428        request.method = HttpMethodDelete;
2429        Ok(request)
2430    }
2431}
2432#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
2433pub struct DeleteBucketMirrorBackOutput {
2434    pub(crate) request_info: RequestInfo,
2435}
2436#[derive(Debug, Clone, PartialEq, Default, AclHeader, Serialize, GenericInput)]
2437#[enable_grant_write]
2438pub struct PutBucketACLInput {
2439    #[serde(skip)]
2440    pub(crate) generic_input: GenericInput,
2441    #[serde(skip)]
2442    pub(crate) bucket: String,
2443    #[serde(skip)]
2444    pub(crate) acl: Option<ACLType>,
2445    #[serde(skip)]
2446    pub(crate) grant_full_control: String,
2447    #[serde(skip)]
2448    pub(crate) grant_read: String,
2449    #[serde(skip)]
2450    pub(crate) grant_read_acp: String,
2451    #[serde(skip)]
2452    pub(crate) grant_write: String,
2453    #[serde(skip)]
2454    pub(crate) grant_write_acp: String,
2455    #[serde(rename = "Owner")]
2456    pub(crate) owner: Owner,
2457    #[serde(rename = "Grants")]
2458    pub(crate) grants: Vec<Grant>,
2459    #[serde(rename = "BucketAclDelivered")]
2460    #[serde(skip_serializing_if = "<&bool as std::ops::Not>::not")]
2461    pub(crate) bucket_acl_delivered: bool,
2462}
2463
2464impl PutBucketACLInput {
2465    pub fn new(bucket: impl Into<String>) -> Self {
2466        let mut input = Self::default();
2467        input.bucket = bucket.into();
2468        input
2469    }
2470
2471    pub fn new_with_acl(bucket: impl Into<String>, acl: impl Into<ACLType>) -> Self {
2472        let mut input = Self::default();
2473        input.bucket = bucket.into();
2474        input.acl = Some(acl.into());
2475        input
2476    }
2477    pub fn bucket(&self) -> &str {
2478        &self.bucket
2479    }
2480    pub fn owner(&self) -> &Owner {
2481        &self.owner
2482    }
2483    pub fn grants(&self) -> &Vec<Grant> {
2484        &self.grants
2485    }
2486
2487    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
2488        self.bucket = bucket.into();
2489    }
2490    pub fn set_owner(&mut self, owner: impl Into<Owner>) {
2491        self.owner = owner.into();
2492    }
2493    pub fn set_grants(&mut self, grants: impl Into<Vec<Grant>>) {
2494        self.grants = grants.into();
2495    }
2496
2497    pub fn bucket_acl_delivered(&self) -> bool {
2498        self.bucket_acl_delivered
2499    }
2500    pub fn set_bucket_acl_delivered(&mut self, bucket_acl_delivered: bool) {
2501        self.bucket_acl_delivered = bucket_acl_delivered;
2502    }
2503}
2504
2505impl InputDescriptor for PutBucketACLInput {
2506    fn operation(&self) -> &str {
2507        "PutBucketACL"
2508    }
2509
2510    fn bucket(&self) -> Result<&str, TosError> {
2511        Ok(&self.bucket)
2512    }
2513}
2514
2515impl<B> InputTranslator<B> for PutBucketACLInput
2516where
2517    B: BuildBufferReader,
2518{
2519    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2520        let mut request = self.trans_bucket()?;
2521        request.method = HttpMethodPut;
2522        if self.acl.is_some() && self.grants.len() > 0 {
2523            return Err(TosError::client_error("both acl and grants are set for put bucket acl"));
2524        }
2525
2526        if self.acl.is_some() {
2527            set_acl_header(&mut request.header, self);
2528        } else if self.grants.len() == 0 {
2529            return Err(TosError::client_error("neither acl nor grants is set for put bucket acl"));
2530        } else if self.owner.id == "" {
2531            return Err(TosError::client_error("empty owner id for put bucket acl"));
2532        } else {
2533            match serde_json::to_string(self) {
2534                Err(e) => return Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
2535                Ok(json) => {
2536                    let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
2537                    request.body = Some(body);
2538                    request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
2539                }
2540            }
2541        }
2542        request.query = Some(HashMap::from([("acl", "".to_string())]));
2543        Ok(request)
2544    }
2545}
2546
2547#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
2548pub struct PutBucketACLOutput {
2549    pub(crate) request_info: RequestInfo,
2550}
2551
2552#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
2553pub struct GetBucketACLInput {
2554    pub(crate) generic_input: GenericInput,
2555    pub(crate) bucket: String,
2556}
2557impl InputDescriptor for GetBucketACLInput {
2558    fn operation(&self) -> &str {
2559        "GetBucketACL"
2560    }
2561
2562    fn bucket(&self) -> Result<&str, TosError> {
2563        Ok(&self.bucket)
2564    }
2565}
2566
2567impl<B> InputTranslator<B> for GetBucketACLInput {
2568    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2569        let mut request = self.trans_bucket()?;
2570        request.query = Some(HashMap::from([("acl", "".to_string())]));
2571        request.method = HttpMethodGet;
2572        Ok(request)
2573    }
2574}
2575#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
2576pub struct GetBucketACLOutput {
2577    #[serde(skip)]
2578    pub(crate) request_info: RequestInfo,
2579    #[serde(default)]
2580    #[serde(rename = "Owner")]
2581    pub(crate) owner: Owner,
2582    #[serde(default)]
2583    #[serde(rename = "Grants")]
2584    pub(crate) grants: Vec<Grant>,
2585    #[serde(default)]
2586    #[serde(rename = "BucketAclDelivered")]
2587    pub(crate) bucket_acl_delivered: bool,
2588}
2589
2590impl GetBucketACLOutput {
2591    pub fn owner(&self) -> &Owner {
2592        &self.owner
2593    }
2594
2595    pub fn grants(&self) -> &Vec<Grant> {
2596        &self.grants
2597    }
2598
2599    pub fn bucket_acl_delivered(&self) -> bool {
2600        self.bucket_acl_delivered
2601    }
2602}
2603#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
2604pub struct PutBucketReplicationInput {
2605    #[serde(skip)]
2606    pub(crate) generic_input: GenericInput,
2607    #[serde(skip)]
2608    pub(crate) bucket: String,
2609    #[serde(rename = "Role")]
2610    #[serde(skip_serializing_if = "String::is_empty")]
2611    pub(crate) role: String,
2612    #[serde(rename = "Rules")]
2613    #[serde(skip_serializing_if = "Vec::is_empty")]
2614    pub(crate) rules: Vec<ReplicationRule>,
2615}
2616
2617impl PutBucketReplicationInput {
2618    pub fn new(bucket: impl Into<String>, role: impl Into<String>) -> Self {
2619        Self {
2620            generic_input: Default::default(),
2621            bucket: bucket.into(),
2622            role: role.into(),
2623            rules: vec![],
2624        }
2625    }
2626
2627    pub fn new_with_rules(bucket: impl Into<String>, role: impl Into<String>, rules: impl Into<Vec<ReplicationRule>>) -> Self {
2628        Self {
2629            generic_input: Default::default(),
2630            bucket: bucket.into(),
2631            role: role.into(),
2632            rules: rules.into(),
2633        }
2634    }
2635
2636    pub fn add_rule(&mut self, rule: impl Into<ReplicationRule>) {
2637        self.rules.push(rule.into());
2638    }
2639
2640    pub fn bucket(&self) -> &str {
2641        &self.bucket
2642    }
2643    pub fn rules(&self) -> &Vec<ReplicationRule> {
2644        &self.rules
2645    }
2646
2647    pub fn role(&self) -> &str {
2648        &self.role
2649    }
2650    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
2651        self.bucket = bucket.into();
2652    }
2653    pub fn set_rules(&mut self, rules: impl Into<Vec<ReplicationRule>>) {
2654        self.rules = rules.into();
2655    }
2656    pub fn set_role(&mut self, role: impl Into<String>) {
2657        self.role = role.into();
2658    }
2659}
2660
2661impl InputDescriptor for PutBucketReplicationInput {
2662    fn operation(&self) -> &str {
2663        "PutBucketReplication"
2664    }
2665
2666    fn bucket(&self) -> Result<&str, TosError> {
2667        Ok(&self.bucket)
2668    }
2669}
2670
2671impl<B> InputTranslator<B> for PutBucketReplicationInput
2672where
2673    B: BuildBufferReader,
2674{
2675    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2676        if self.rules.len() == 0 {
2677            return Err(TosError::client_error("empty replication rules"));
2678        }
2679
2680        match serde_json::to_string(self) {
2681            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
2682            Ok(json) => {
2683                let mut request = self.trans_bucket()?;
2684                request.method = HttpMethodPut;
2685                request.query = Some(HashMap::from([("replication", "".to_string())]));
2686                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
2687                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
2688                request.body = Some(body);
2689                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
2690                Ok(request)
2691            }
2692        }
2693    }
2694}
2695
2696fn default_historical_object_replication() -> StatusType {
2697    StatusType::StatusDisabled
2698}
2699
2700#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2701pub struct ReplicationRule {
2702    #[serde(rename = "ID")]
2703    #[serde(skip_serializing_if = "String::is_empty")]
2704    #[serde(default)]
2705    pub(crate) id: String,
2706    #[serde(rename = "Status")]
2707    #[serde(default)]
2708    pub(crate) status: StatusType,
2709    #[serde(rename = "PrefixSet")]
2710    #[serde(skip_serializing_if = "Vec::is_empty")]
2711    #[serde(default)]
2712    pub(crate) prefix_set: Vec<String>,
2713    #[serde(rename = "Tags")]
2714    #[serde(skip_serializing_if = "Vec::is_empty")]
2715    #[serde(default)]
2716    pub(crate) tags: Vec<Tag>,
2717    #[serde(rename = "Destination")]
2718    #[serde(default)]
2719    pub(crate) destination: Destination,
2720    #[serde(rename = "HistoricalObjectReplication")]
2721    #[serde(default = "default_historical_object_replication")]
2722    pub(crate) historical_object_replication: StatusType,
2723    #[serde(rename = "AccessControlTranslation")]
2724    #[serde(skip_serializing_if = "Option::is_none")]
2725    #[serde(default)]
2726    pub(crate) access_control_translation: Option<AccessControlTranslation>,
2727    #[serde(rename = "Progress")]
2728    #[serde(skip_serializing)]
2729    #[serde(default)]
2730    pub(crate) progress: Option<Progress>,
2731}
2732
2733impl ReplicationRule {
2734    pub fn new(id: impl Into<String>) -> Self {
2735        Self {
2736            id: id.into(),
2737            status: Default::default(),
2738            prefix_set: vec![],
2739            tags: vec![],
2740            destination: Default::default(),
2741            historical_object_replication: StatusType::StatusDisabled,
2742            access_control_translation: None,
2743            progress: None,
2744        }
2745    }
2746
2747    pub fn id(&self) -> &str {
2748        &self.id
2749    }
2750
2751    pub fn status(&self) -> &StatusType {
2752        &self.status
2753    }
2754
2755    pub fn prefix_set(&self) -> &Vec<String> {
2756        &self.prefix_set
2757    }
2758
2759    pub fn tags(&self) -> &Vec<Tag> {
2760        &self.tags
2761    }
2762
2763    pub fn destination(&self) -> &Destination {
2764        &self.destination
2765    }
2766
2767    pub fn historical_object_replication(&self) -> &StatusType {
2768        &self.historical_object_replication
2769    }
2770
2771    pub fn access_control_translation(&self) -> &Option<AccessControlTranslation> {
2772        &self.access_control_translation
2773    }
2774    pub fn progress(&self) -> &Option<Progress> {
2775        &self.progress
2776    }
2777
2778    pub fn set_id(&mut self, id: impl Into<String>) {
2779        self.id = id.into();
2780    }
2781
2782    pub fn set_status(&mut self, status: impl Into<StatusType>) {
2783        self.status = status.into();
2784    }
2785
2786    pub fn set_prefix_set(&mut self, prefix_set: impl Into<Vec<String>>) {
2787        self.prefix_set = prefix_set.into();
2788    }
2789
2790    pub fn set_tags(&mut self, tags: impl Into<Vec<Tag>>) {
2791        self.tags = tags.into();
2792    }
2793
2794    pub fn set_destination(&mut self, destination: impl Into<Destination>) {
2795        self.destination = destination.into();
2796    }
2797
2798    pub fn set_historical_object_replication(&mut self, historical_object_replication: impl Into<StatusType>) {
2799        self.historical_object_replication = historical_object_replication.into();
2800    }
2801
2802    pub fn set_access_control_translation(&mut self, access_control_translation: impl Into<AccessControlTranslation>) {
2803        self.access_control_translation = Some(access_control_translation.into());
2804    }
2805}
2806#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2807pub struct Destination {
2808    #[serde(rename = "Bucket")]
2809    #[serde(skip_serializing_if = "String::is_empty")]
2810    #[serde(default)]
2811    pub(crate) bucket: String,
2812    #[serde(rename = "Location")]
2813    #[serde(skip_serializing_if = "String::is_empty")]
2814    #[serde(default)]
2815    pub(crate) location: String,
2816    #[serde(rename = "StorageClass")]
2817    #[serde(default)]
2818    pub(crate) storage_class: Option<StorageClassType>,
2819    #[serde(rename = "StorageClassInheritDirective")]
2820    #[serde(default)]
2821    pub(crate) storage_class_inherit_directive: Option<StorageClassInheritDirectiveType>,
2822}
2823
2824impl Destination {
2825    pub fn new(bucket: impl Into<String>, location: impl Into<String>) -> Self {
2826        Self {
2827            bucket: bucket.into(),
2828            location: location.into(),
2829            storage_class: None,
2830            storage_class_inherit_directive: None,
2831        }
2832    }
2833
2834    pub fn bucket(&self) -> &str {
2835        &self.bucket
2836    }
2837
2838    pub fn location(&self) -> &str {
2839        &self.location
2840    }
2841
2842    pub fn storage_class(&self) -> &Option<StorageClassType> {
2843        &self.storage_class
2844    }
2845
2846    pub fn storage_class_inherit_directive(&self) -> &Option<StorageClassInheritDirectiveType> {
2847        &self.storage_class_inherit_directive
2848    }
2849
2850    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
2851        self.bucket = bucket.into();
2852    }
2853
2854    pub fn set_location(&mut self, location: impl Into<String>) {
2855        self.location = location.into();
2856    }
2857
2858    pub fn set_storage_class(&mut self, storage_class: impl Into<StorageClassType>) {
2859        self.storage_class = Some(storage_class.into());
2860    }
2861
2862    pub fn set_storage_class_inherit_directive(&mut self, storage_class_inherit_directive: impl Into<StorageClassInheritDirectiveType>) {
2863        self.storage_class_inherit_directive = Some(storage_class_inherit_directive.into());
2864    }
2865}
2866#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2867pub struct AccessControlTranslation {
2868    #[serde(rename = "Owner")]
2869    #[serde(default)]
2870    pub(crate) owner: String,
2871}
2872impl AccessControlTranslation {
2873    pub fn new(owner: impl Into<String>) -> Self {
2874        Self {
2875            owner: owner.into(),
2876        }
2877    }
2878
2879    pub fn owner(&self) -> &str {
2880        &self.owner
2881    }
2882
2883    pub fn set_owner(&mut self, owner: impl Into<String>) {
2884        self.owner = owner.into();
2885    }
2886}
2887#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2888pub struct Progress {
2889    #[serde(rename = "HistoricalObject")]
2890    #[serde(default)]
2891    pub(crate) historical_object: f64,
2892    #[serde(rename = "NewObject")]
2893    #[serde(default)]
2894    pub(crate) new_object: String,
2895}
2896impl Progress {
2897    pub fn historical_object(&self) -> f64 {
2898        self.historical_object
2899    }
2900
2901    pub fn new_object(&self) -> &str {
2902        &self.new_object
2903    }
2904}
2905#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
2906pub struct PutBucketReplicationOutput {
2907    pub(crate) request_info: RequestInfo,
2908}
2909#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
2910pub struct GetBucketReplicationInput {
2911    pub(crate) generic_input: GenericInput,
2912    pub(crate) bucket: String,
2913    pub(crate) rule_id: String,
2914}
2915
2916impl GetBucketReplicationInput {
2917    pub fn rule_id(&self) -> &str {
2918        &self.rule_id
2919    }
2920
2921    pub fn set_rule_id(&mut self, rule_id: impl Into<String>) {
2922        self.rule_id = rule_id.into();
2923    }
2924}
2925
2926impl InputDescriptor for GetBucketReplicationInput {
2927    fn operation(&self) -> &str {
2928        "GetBucketReplication"
2929    }
2930
2931    fn bucket(&self) -> Result<&str, TosError> {
2932        Ok(&self.bucket)
2933    }
2934}
2935
2936impl<B> InputTranslator<B> for GetBucketReplicationInput {
2937    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2938        let mut request = self.trans_bucket()?;
2939        let mut query = HashMap::with_capacity(2);
2940        query.insert("replication", "".to_string());
2941        if self.rule_id != "" {
2942            query.insert("rule-id", self.rule_id.to_string());
2943        }
2944        request.query = Some(query);
2945        request.method = HttpMethodGet;
2946        Ok(request)
2947    }
2948}
2949
2950#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
2951pub struct GetBucketReplicationOutput {
2952    #[serde(skip)]
2953    pub(crate) request_info: RequestInfo,
2954    #[serde(rename = "Role")]
2955    #[serde(default)]
2956    pub(crate) role: String,
2957    #[serde(rename = "Rules")]
2958    #[serde(default)]
2959    pub(crate) rules: Vec<ReplicationRule>,
2960}
2961
2962impl GetBucketReplicationOutput {
2963    pub fn role(&self) -> &str {
2964        &self.role
2965    }
2966
2967    pub fn rules(&self) -> &Vec<ReplicationRule> {
2968        &self.rules
2969    }
2970}
2971
2972#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
2973pub struct DeleteBucketReplicationInput {
2974    pub(crate) generic_input: GenericInput,
2975    pub(crate) bucket: String,
2976}
2977
2978impl InputDescriptor for DeleteBucketReplicationInput {
2979    fn operation(&self) -> &str {
2980        "DeleteBucketReplication"
2981    }
2982
2983    fn bucket(&self) -> Result<&str, TosError> {
2984        Ok(&self.bucket)
2985    }
2986}
2987
2988impl<B> InputTranslator<B> for DeleteBucketReplicationInput {
2989    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
2990        let mut request = self.trans_bucket()?;
2991        request.query = Some(HashMap::from([("replication", "".to_string())]));
2992        request.method = HttpMethodDelete;
2993        Ok(request)
2994    }
2995}
2996
2997#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
2998pub struct DeleteBucketReplicationOutput {
2999    pub(crate) request_info: RequestInfo,
3000}
3001#[derive(Debug, Clone, PartialEq, Default, BucketSetter, Serialize, GenericInput)]
3002pub struct PutBucketVersioningInput {
3003    #[serde(skip)]
3004    pub(crate) generic_input: GenericInput,
3005    #[serde(skip)]
3006    pub(crate) bucket: String,
3007    #[serde(rename = "Status")]
3008    pub(crate) status: VersioningStatusType,
3009}
3010
3011impl PutBucketVersioningInput {
3012    pub fn new_with_status(bucket: impl Into<String>, status: impl Into<VersioningStatusType>) -> Self {
3013        Self {
3014            generic_input: Default::default(),
3015            bucket: bucket.into(),
3016            status: status.into(),
3017        }
3018    }
3019
3020    pub fn status(&self) -> &VersioningStatusType {
3021        &self.status
3022    }
3023
3024    pub fn set_status(&mut self, status: impl Into<VersioningStatusType>) {
3025        self.status = status.into();
3026    }
3027}
3028
3029impl InputDescriptor for PutBucketVersioningInput {
3030    fn operation(&self) -> &str {
3031        "PutBucketVersioning"
3032    }
3033
3034    fn bucket(&self) -> Result<&str, TosError> {
3035        Ok(&self.bucket)
3036    }
3037}
3038
3039impl<B> InputTranslator<B> for PutBucketVersioningInput
3040where
3041    B: BuildBufferReader,
3042{
3043    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3044        match serde_json::to_string(self) {
3045            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
3046            Ok(json) => {
3047                let mut request = self.trans_bucket()?;
3048                request.method = HttpMethodPut;
3049                request.query = Some(HashMap::from([("versioning", "".to_string())]));
3050                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
3051                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
3052                request.body = Some(body);
3053                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
3054                Ok(request)
3055            }
3056        }
3057    }
3058}
3059
3060#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3061pub struct PutBucketVersioningOutput {
3062    pub(crate) request_info: RequestInfo,
3063}
3064#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3065pub struct GetBucketVersioningInput {
3066    pub(crate) generic_input: GenericInput,
3067    pub(crate) bucket: String,
3068}
3069
3070impl InputDescriptor for GetBucketVersioningInput {
3071    fn operation(&self) -> &str {
3072        "GetBucketVersioning"
3073    }
3074
3075    fn bucket(&self) -> Result<&str, TosError> {
3076        Ok(&self.bucket)
3077    }
3078}
3079
3080impl<B> InputTranslator<B> for GetBucketVersioningInput {
3081    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3082        let mut request = self.trans_bucket()?;
3083        request.query = Some(HashMap::from([("versioning", "".to_string())]));
3084        request.method = HttpMethodGet;
3085        Ok(request)
3086    }
3087}
3088#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
3089pub struct GetBucketVersioningOutput {
3090    #[serde(skip)]
3091    pub(crate) request_info: RequestInfo,
3092    #[serde(rename = "Status")]
3093    #[serde(default)]
3094    pub(crate) status: VersioningStatusType,
3095}
3096impl GetBucketVersioningOutput {
3097    pub fn status(&self) -> &VersioningStatusType {
3098        &self.status
3099    }
3100}
3101#[derive(Debug, Clone, PartialEq, Default, BucketSetter, Serialize, GenericInput)]
3102pub struct PutBucketWebsiteInput {
3103    #[serde(skip)]
3104    pub(crate) generic_input: GenericInput,
3105    #[serde(skip)]
3106    pub(crate) bucket: String,
3107    #[serde(rename = "RedirectAllRequestsTo")]
3108    #[serde(skip_serializing_if = "Option::is_none")]
3109    pub(crate) redirect_all_requests_to: Option<RedirectAllRequestsTo>,
3110    #[serde(rename = "IndexDocument")]
3111    #[serde(skip_serializing_if = "Option::is_none")]
3112    pub(crate) index_document: Option<IndexDocument>,
3113    #[serde(rename = "ErrorDocument")]
3114    #[serde(skip_serializing_if = "Option::is_none")]
3115    pub(crate) error_document: Option<ErrorDocument>,
3116    #[serde(rename = "RoutingRules")]
3117    #[serde(skip_serializing_if = "Vec::is_empty")]
3118    pub(crate) routing_rules: Vec<RoutingRule>,
3119}
3120
3121impl PutBucketWebsiteInput {
3122    pub fn add_rule(&mut self, routing_rule: impl Into<RoutingRule>) {
3123        self.routing_rules.push(routing_rule.into());
3124    }
3125    pub fn redirect_all_requests_to(&self) -> &Option<RedirectAllRequestsTo> {
3126        &self.redirect_all_requests_to
3127    }
3128
3129    pub fn index_document(&self) -> &Option<IndexDocument> {
3130        &self.index_document
3131    }
3132
3133    pub fn error_document(&self) -> &Option<ErrorDocument> {
3134        &self.error_document
3135    }
3136
3137    pub fn routing_rules(&self) -> &Vec<RoutingRule> {
3138        &self.routing_rules
3139    }
3140
3141    pub fn set_redirect_all_requests_to(&mut self, redirect_all_requests_to: impl Into<RedirectAllRequestsTo>) {
3142        self.redirect_all_requests_to = Some(redirect_all_requests_to.into());
3143    }
3144
3145    pub fn set_index_document(&mut self, index_document: impl Into<IndexDocument>) {
3146        self.index_document = Some(index_document.into());
3147    }
3148
3149    pub fn set_error_document(&mut self, error_document: impl Into<ErrorDocument>) {
3150        self.error_document = Some(error_document.into());
3151    }
3152
3153    pub fn set_routing_rules(&mut self, routing_rules: impl Into<Vec<RoutingRule>>) {
3154        self.routing_rules = routing_rules.into();
3155    }
3156}
3157
3158impl InputDescriptor for PutBucketWebsiteInput {
3159    fn operation(&self) -> &str {
3160        "PutBucketWebsite"
3161    }
3162
3163    fn bucket(&self) -> Result<&str, TosError> {
3164        Ok(&self.bucket)
3165    }
3166}
3167
3168impl<B> InputTranslator<B> for PutBucketWebsiteInput
3169where
3170    B: BuildBufferReader,
3171{
3172    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3173        match serde_json::to_string(self) {
3174            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
3175            Ok(json) => {
3176                let mut request = self.trans_bucket()?;
3177                request.method = HttpMethodPut;
3178                request.query = Some(HashMap::from([("website", "".to_string())]));
3179                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
3180                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
3181                request.body = Some(body);
3182                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
3183                Ok(request)
3184            }
3185        }
3186    }
3187}
3188
3189#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3190pub struct RedirectAllRequestsTo {
3191    #[serde(rename = "HostName")]
3192    #[serde(skip_serializing_if = "String::is_empty")]
3193    #[serde(default)]
3194    pub(crate) host_name: String,
3195    #[serde(rename = "Protocol")]
3196    #[serde(skip_serializing_if = "Option::is_none")]
3197    #[serde(default)]
3198    pub(crate) protocol: Option<ProtocolType>,
3199}
3200impl RedirectAllRequestsTo {
3201    pub fn new(host_name: impl Into<String>, protocol: impl Into<ProtocolType>) -> Self {
3202        Self {
3203            host_name: host_name.into(),
3204            protocol: Some(protocol.into()),
3205        }
3206    }
3207
3208    pub fn host_name(&self) -> &str {
3209        &self.host_name
3210    }
3211
3212    pub fn protocol(&self) -> &Option<ProtocolType> {
3213        &self.protocol
3214    }
3215
3216    pub fn set_host_name(&mut self, host_name: impl Into<String>) {
3217        self.host_name = host_name.into();
3218    }
3219
3220    pub fn set_protocol(&mut self, protocol: impl Into<ProtocolType>) {
3221        self.protocol = Some(protocol.into());
3222    }
3223}
3224#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3225pub struct IndexDocument {
3226    #[serde(rename = "Suffix")]
3227    #[serde(skip_serializing_if = "String::is_empty")]
3228    #[serde(default)]
3229    pub(crate) suffix: String,
3230    #[serde(rename = "ForbiddenSubDir")]
3231    #[serde(skip_serializing_if = "<&bool as std::ops::Not>::not")]
3232    #[serde(default)]
3233    pub(crate) forbidden_sub_dir: bool,
3234}
3235impl IndexDocument {
3236    pub fn new(suffix: impl Into<String>) -> Self {
3237        Self {
3238            suffix: suffix.into(),
3239            forbidden_sub_dir: false,
3240        }
3241    }
3242
3243    pub fn suffix(&self) -> &str {
3244        &self.suffix
3245    }
3246
3247    pub fn forbidden_sub_dir(&self) -> bool {
3248        self.forbidden_sub_dir
3249    }
3250
3251    pub fn set_suffix(&mut self, suffix: impl Into<String>) {
3252        self.suffix = suffix.into();
3253    }
3254
3255    pub fn set_forbidden_sub_dir(&mut self, forbidden_sub_dir: bool) {
3256        self.forbidden_sub_dir = forbidden_sub_dir;
3257    }
3258}
3259#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3260pub struct ErrorDocument {
3261    #[serde(rename = "Key")]
3262    #[serde(skip_serializing_if = "String::is_empty")]
3263    #[serde(default)]
3264    pub(crate) key: String,
3265}
3266impl ErrorDocument {
3267    pub fn new(key: impl Into<String>) -> Self {
3268        Self {
3269            key: key.into(),
3270        }
3271    }
3272
3273    pub fn key(&self) -> &str {
3274        &self.key
3275    }
3276
3277    pub fn set_key(&mut self, key: impl Into<String>) {
3278        self.key = key.into();
3279    }
3280}
3281#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3282pub struct RoutingRule {
3283    #[serde(rename = "Condition")]
3284    #[serde(default)]
3285    pub(crate) condition: RoutingRuleCondition,
3286    #[serde(rename = "Redirect")]
3287    #[serde(default)]
3288    pub(crate) redirect: RoutingRuleRedirect,
3289}
3290impl RoutingRule {
3291    pub fn new(condition: impl Into<RoutingRuleCondition>, redirect: impl Into<RoutingRuleRedirect>) -> Self {
3292        Self {
3293            condition: condition.into(),
3294            redirect: redirect.into(),
3295        }
3296    }
3297
3298    pub fn condition(&self) -> &RoutingRuleCondition {
3299        &self.condition
3300    }
3301
3302    pub fn redirect(&self) -> &RoutingRuleRedirect {
3303        &self.redirect
3304    }
3305    pub fn set_condition(&mut self, condition: impl Into<RoutingRuleCondition>) {
3306        self.condition = condition.into();
3307    }
3308
3309    pub fn set_redirect(&mut self, redirect: impl Into<RoutingRuleRedirect>) {
3310        self.redirect = redirect.into();
3311    }
3312}
3313
3314pub(crate) fn is_non_positive(x: &isize) -> bool {
3315    *x <= 0
3316}
3317
3318#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3319pub struct RoutingRuleCondition {
3320    #[serde(rename = "KeyPrefixEquals")]
3321    #[serde(skip_serializing_if = "String::is_empty")]
3322    #[serde(default)]
3323    pub(crate) key_prefix_equals: String,
3324    #[serde(rename = "HttpErrorCodeReturnedEquals")]
3325    #[serde(skip_serializing_if = "is_non_positive")]
3326    #[serde(default)]
3327    pub(crate) http_error_code_returned_equals: isize,
3328}
3329impl RoutingRuleCondition {
3330    pub fn new(key_prefix_equals: impl Into<String>) -> Self {
3331        Self {
3332            key_prefix_equals: key_prefix_equals.into(),
3333            http_error_code_returned_equals: -1,
3334        }
3335    }
3336
3337    pub fn key_prefix_equals(&self) -> &str {
3338        &self.key_prefix_equals
3339    }
3340
3341    pub fn http_error_code_returned_equals(&self) -> isize {
3342        self.http_error_code_returned_equals
3343    }
3344
3345    pub fn set_key_prefix_equals(&mut self, key_prefix_equals: impl Into<String>) {
3346        self.key_prefix_equals = key_prefix_equals.into();
3347    }
3348
3349    pub fn set_http_error_code_returned_equals(&mut self, http_error_code_returned_equals: isize) {
3350        self.http_error_code_returned_equals = http_error_code_returned_equals;
3351    }
3352}
3353#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3354pub struct RoutingRuleRedirect {
3355    #[serde(rename = "Protocol")]
3356    #[serde(skip_serializing_if = "Option::is_none")]
3357    #[serde(default)]
3358    pub(crate) protocol: Option<ProtocolType>,
3359    #[serde(rename = "HostName")]
3360    #[serde(skip_serializing_if = "String::is_empty")]
3361    #[serde(default)]
3362    pub(crate) host_name: String,
3363    #[serde(rename = "ReplaceKeyPrefixWith")]
3364    #[serde(skip_serializing_if = "String::is_empty")]
3365    #[serde(default)]
3366    pub(crate) replace_key_prefix_with: String,
3367    #[serde(rename = "ReplaceKeyWith")]
3368    #[serde(skip_serializing_if = "String::is_empty")]
3369    #[serde(default)]
3370    pub(crate) replace_key_with: String,
3371    #[serde(rename = "HttpRedirectCode")]
3372    #[serde(skip_serializing_if = "is_non_positive")]
3373    #[serde(default)]
3374    pub(crate) http_redirect_code: isize,
3375}
3376impl RoutingRuleRedirect {
3377    pub fn new() -> Self {
3378        Self {
3379            protocol: None,
3380            host_name: "".to_string(),
3381            replace_key_prefix_with: "".to_string(),
3382            replace_key_with: "".to_string(),
3383            http_redirect_code: -1,
3384        }
3385    }
3386
3387    pub fn protocol(&self) -> &Option<ProtocolType> {
3388        &self.protocol
3389    }
3390
3391    pub fn host_name(&self) -> &str {
3392        &self.host_name
3393    }
3394
3395    pub fn replace_key_prefix_with(&self) -> &str {
3396        &self.replace_key_prefix_with
3397    }
3398
3399    pub fn replace_key_with(&self) -> &str {
3400        &self.replace_key_with
3401    }
3402
3403    pub fn http_redirect_code(&self) -> isize {
3404        self.http_redirect_code
3405    }
3406
3407    pub fn set_protocol(&mut self, protocol: impl Into<ProtocolType>) {
3408        self.protocol = Some(protocol.into());
3409    }
3410
3411    pub fn set_host_name(&mut self, host_name: impl Into<String>) {
3412        self.host_name = host_name.into();
3413    }
3414
3415    pub fn set_replace_key_prefix_with(&mut self, replace_key_prefix_with: impl Into<String>) {
3416        self.replace_key_prefix_with = replace_key_prefix_with.into();
3417    }
3418
3419    pub fn set_replace_key_with(&mut self, replace_key_with: impl Into<String>) {
3420        self.replace_key_with = replace_key_with.into();
3421    }
3422
3423    pub fn set_http_redirect_code(&mut self, http_redirect_code: isize) {
3424        self.http_redirect_code = http_redirect_code;
3425    }
3426}
3427#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3428pub struct PutBucketWebsiteOutput {
3429    pub(crate) request_info: RequestInfo,
3430}
3431#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3432pub struct GetBucketWebsiteInput {
3433    pub(crate) generic_input: GenericInput,
3434    pub(crate) bucket: String,
3435}
3436
3437impl InputDescriptor for GetBucketWebsiteInput {
3438    fn operation(&self) -> &str {
3439        "GetBucketWebsite"
3440    }
3441
3442    fn bucket(&self) -> Result<&str, TosError> {
3443        Ok(&self.bucket)
3444    }
3445}
3446
3447impl<B> InputTranslator<B> for GetBucketWebsiteInput {
3448    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3449        let mut request = self.trans_bucket()?;
3450        request.query = Some(HashMap::from([("website", "".to_string())]));
3451        request.method = HttpMethodGet;
3452        Ok(request)
3453    }
3454}
3455#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
3456pub struct GetBucketWebsiteOutput {
3457    #[serde(skip)]
3458    pub(crate) request_info: RequestInfo,
3459    #[serde(rename = "RedirectAllRequestsTo")]
3460    #[serde(default)]
3461    pub(crate) redirect_all_requests_to: Option<RedirectAllRequestsTo>,
3462    #[serde(rename = "IndexDocument")]
3463    #[serde(default)]
3464    pub(crate) index_document: Option<IndexDocument>,
3465    #[serde(rename = "ErrorDocument")]
3466    #[serde(default)]
3467    pub(crate) error_document: Option<ErrorDocument>,
3468    #[serde(rename = "RoutingRules")]
3469    #[serde(default)]
3470    pub(crate) routing_rules: Vec<RoutingRule>,
3471}
3472impl GetBucketWebsiteOutput {
3473    pub fn redirect_all_requests_to(&self) -> &Option<RedirectAllRequestsTo> {
3474        &self.redirect_all_requests_to
3475    }
3476
3477    pub fn index_document(&self) -> &Option<IndexDocument> {
3478        &self.index_document
3479    }
3480
3481    pub fn error_document(&self) -> &Option<ErrorDocument> {
3482        &self.error_document
3483    }
3484
3485    pub fn routing_rules(&self) -> &Vec<RoutingRule> {
3486        &self.routing_rules
3487    }
3488}
3489#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3490pub struct DeleteBucketWebsiteInput {
3491    pub(crate) generic_input: GenericInput,
3492    pub(crate) bucket: String,
3493}
3494impl InputDescriptor for DeleteBucketWebsiteInput {
3495    fn operation(&self) -> &str {
3496        "DeleteBucketWebsite"
3497    }
3498
3499    fn bucket(&self) -> Result<&str, TosError> {
3500        Ok(&self.bucket)
3501    }
3502}
3503
3504impl<B> InputTranslator<B> for DeleteBucketWebsiteInput {
3505    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3506        let mut request = self.trans_bucket()?;
3507        request.query = Some(HashMap::from([("website", "".to_string())]));
3508        request.method = HttpMethodDelete;
3509        Ok(request)
3510    }
3511}
3512#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3513pub struct DeleteBucketWebsiteOutput {
3514    pub(crate) request_info: RequestInfo,
3515}
3516#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
3517pub struct PutBucketCustomDomainInput {
3518    #[serde(skip)]
3519    pub(crate) generic_input: GenericInput,
3520    #[serde(skip)]
3521    pub(crate) bucket: String,
3522    #[serde(rename = "CustomDomainRule")]
3523    pub(crate) rule: CustomDomainRule,
3524}
3525
3526impl PutBucketCustomDomainInput {
3527    pub fn new(bucket: impl Into<String>, rule: impl Into<CustomDomainRule>) -> Self {
3528        Self {
3529            generic_input: Default::default(),
3530            bucket: bucket.into(),
3531            rule: rule.into(),
3532        }
3533    }
3534
3535    pub fn bucket(&self) -> &str {
3536        &self.bucket
3537    }
3538
3539    pub fn rule(&self) -> &CustomDomainRule {
3540        &self.rule
3541    }
3542
3543    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
3544        self.bucket = bucket.into();
3545    }
3546
3547    pub fn set_rule(&mut self, rule: impl Into<CustomDomainRule>) {
3548        self.rule = rule.into();
3549    }
3550}
3551
3552impl InputDescriptor for PutBucketCustomDomainInput {
3553    fn operation(&self) -> &str {
3554        "PutBucketCustomDomain"
3555    }
3556
3557    fn bucket(&self) -> Result<&str, TosError> {
3558        Ok(&self.bucket)
3559    }
3560}
3561
3562impl<B> InputTranslator<B> for PutBucketCustomDomainInput
3563where
3564    B: BuildBufferReader,
3565{
3566    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3567        match serde_json::to_string(self) {
3568            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
3569            Ok(json) => {
3570                let mut request = self.trans_bucket()?;
3571                request.method = HttpMethodPut;
3572                request.query = Some(HashMap::from([("customdomain", "".to_string())]));
3573                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
3574                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
3575                request.body = Some(body);
3576                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
3577                Ok(request)
3578            }
3579        }
3580    }
3581}
3582#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3583pub struct CustomDomainRule {
3584    #[serde(rename = "CertId")]
3585    #[serde(skip_serializing_if = "String::is_empty")]
3586    #[serde(default)]
3587    pub(crate) cert_id: String,
3588    #[serde(rename = "CertStatus")]
3589    #[serde(skip_serializing)]
3590    #[serde(default)]
3591    pub(crate) cert_status: CertStatusType,
3592    #[serde(rename = "Domain")]
3593    #[serde(skip_serializing_if = "String::is_empty")]
3594    #[serde(default)]
3595    pub(crate) domain: String,
3596    #[serde(rename = "Forbidden")]
3597    #[serde(skip_serializing)]
3598    #[serde(default)]
3599    pub(crate) forbidden: bool,
3600    #[serde(rename = "ForbiddenReason")]
3601    #[serde(skip_serializing)]
3602    #[serde(default)]
3603    pub(crate) forbidden_reason: String,
3604    #[serde(rename = "Protocol")]
3605    #[serde(default)]
3606    pub(crate) protocol: AuthProtocolType,
3607}
3608
3609impl CustomDomainRule {
3610    pub fn new(domain: impl Into<String>, protocol: impl Into<AuthProtocolType>) -> Self {
3611        Self {
3612            cert_id: "".to_string(),
3613            cert_status: Default::default(),
3614            domain: domain.into(),
3615            forbidden: false,
3616            forbidden_reason: "".to_string(),
3617            protocol: protocol.into(),
3618        }
3619    }
3620
3621    pub fn cert_id(&self) -> &str {
3622        &self.cert_id
3623    }
3624
3625    pub fn cert_status(&self) -> &CertStatusType {
3626        &self.cert_status
3627    }
3628
3629    pub fn domain(&self) -> &str {
3630        &self.domain
3631    }
3632
3633    pub fn forbidden(&self) -> bool {
3634        self.forbidden
3635    }
3636
3637    pub fn forbidden_reason(&self) -> &str {
3638        &self.forbidden_reason
3639    }
3640
3641    pub fn protocol(&self) -> &AuthProtocolType {
3642        &self.protocol
3643    }
3644
3645    pub fn set_cert_id(&mut self, cert_id: impl Into<String>) {
3646        self.cert_id = cert_id.into();
3647    }
3648
3649    pub fn set_domain(&mut self, domain: impl Into<String>) {
3650        self.domain = domain.into();
3651    }
3652
3653    pub fn set_protocol(&mut self, protocol: impl Into<AuthProtocolType>) {
3654        self.protocol = protocol.into();
3655    }
3656}
3657#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3658pub struct PutBucketCustomDomainOutput {
3659    pub(crate) request_info: RequestInfo,
3660}
3661#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3662pub struct ListBucketCustomDomainInput {
3663    pub(crate) generic_input: GenericInput,
3664    pub(crate) bucket: String,
3665}
3666
3667impl InputDescriptor for ListBucketCustomDomainInput {
3668    fn operation(&self) -> &str {
3669        "ListBucketCustomDomain"
3670    }
3671
3672    fn bucket(&self) -> Result<&str, TosError> {
3673        Ok(&self.bucket)
3674    }
3675}
3676
3677impl<B> InputTranslator<B> for ListBucketCustomDomainInput {
3678    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3679        let mut request = self.trans_bucket()?;
3680        request.query = Some(HashMap::from([("customdomain", "".to_string())]));
3681        request.method = HttpMethodGet;
3682        Ok(request)
3683    }
3684}
3685#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
3686pub struct ListBucketCustomDomainOutput {
3687    #[serde(skip)]
3688    pub(crate) request_info: RequestInfo,
3689    #[serde(rename = "CustomDomainRules")]
3690    pub(crate) rules: Vec<CustomDomainRule>,
3691}
3692impl ListBucketCustomDomainOutput {
3693    pub fn rules(&self) -> &Vec<CustomDomainRule> {
3694        &self.rules
3695    }
3696}
3697
3698#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
3699pub struct DeleteBucketCustomDomainInput {
3700    pub(crate) generic_input: GenericInput,
3701    pub(crate) bucket: String,
3702    pub(crate) domain: String,
3703}
3704
3705impl DeleteBucketCustomDomainInput {
3706    pub fn new(bucket: impl Into<String>, domain: impl Into<String>) -> Self {
3707        Self {
3708            generic_input: Default::default(),
3709            bucket: bucket.into(),
3710            domain: domain.into(),
3711        }
3712    }
3713
3714    pub fn bucket(&self) -> &str {
3715        &self.bucket
3716    }
3717
3718    pub fn domain(&self) -> &str {
3719        &self.domain
3720    }
3721
3722    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
3723        self.bucket = bucket.into();
3724    }
3725
3726    pub fn set_domain(&mut self, domain: impl Into<String>) {
3727        self.domain = domain.into();
3728    }
3729}
3730
3731impl InputDescriptor for DeleteBucketCustomDomainInput {
3732    fn operation(&self) -> &str {
3733        "DeleteBucketCustomDomain"
3734    }
3735
3736    fn bucket(&self) -> Result<&str, TosError> {
3737        Ok(&self.bucket)
3738    }
3739}
3740
3741impl<B> InputTranslator<B> for DeleteBucketCustomDomainInput {
3742    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3743        let mut request = self.trans_bucket()?;
3744        request.query = Some(HashMap::from([("customdomain", self.domain.clone())]));
3745        request.method = HttpMethodDelete;
3746        Ok(request)
3747    }
3748}
3749
3750#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3751pub struct DeleteBucketCustomDomainOutput {
3752    pub(crate) request_info: RequestInfo,
3753}
3754#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
3755pub struct PutBucketRealTimeLogInput {
3756    #[serde(skip)]
3757    pub(crate) generic_input: GenericInput,
3758    #[serde(skip)]
3759    pub(crate) bucket: String,
3760    #[serde(rename = "RealTimeLogConfiguration")]
3761    pub(crate) configuration: RealTimeLogConfiguration,
3762}
3763
3764impl PutBucketRealTimeLogInput {
3765    pub fn new(bucket: impl Into<String>, configuration: impl Into<RealTimeLogConfiguration>) -> Self {
3766        Self {
3767            generic_input: Default::default(),
3768            bucket: bucket.into(),
3769            configuration: configuration.into(),
3770        }
3771    }
3772
3773    pub fn bucket(&self) -> &str {
3774        &self.bucket
3775    }
3776
3777    pub fn configuration(&self) -> &RealTimeLogConfiguration {
3778        &self.configuration
3779    }
3780
3781    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
3782        self.bucket = bucket.into();
3783    }
3784
3785    pub fn set_configuration(&mut self, configuration: impl Into<RealTimeLogConfiguration>) {
3786        self.configuration = configuration.into();
3787    }
3788}
3789
3790impl InputDescriptor for PutBucketRealTimeLogInput {
3791    fn operation(&self) -> &str {
3792        "PutBucketRealTimeLog"
3793    }
3794
3795    fn bucket(&self) -> Result<&str, TosError> {
3796        Ok(&self.bucket)
3797    }
3798}
3799
3800impl<B> InputTranslator<B> for PutBucketRealTimeLogInput
3801where
3802    B: BuildBufferReader,
3803{
3804    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3805        match serde_json::to_string(self) {
3806            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
3807            Ok(json) => {
3808                let mut request = self.trans_bucket()?;
3809                request.method = HttpMethodPut;
3810                request.query = Some(HashMap::from([("realtimeLog", "".to_string())]));
3811                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
3812                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
3813                request.body = Some(body);
3814                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
3815                Ok(request)
3816            }
3817        }
3818    }
3819}
3820
3821#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3822pub struct RealTimeLogConfiguration {
3823    #[serde(rename = "Role")]
3824    #[serde(skip_serializing_if = "String::is_empty")]
3825    #[serde(default)]
3826    pub(crate) role: String,
3827    #[serde(rename = "AccessLogConfiguration")]
3828    #[serde(default)]
3829    pub(crate) configuration: AccessLogConfiguration,
3830}
3831impl RealTimeLogConfiguration {
3832    pub fn new(role: impl Into<String>, configuration: impl Into<AccessLogConfiguration>) -> Self {
3833        Self {
3834            role: role.into(),
3835            configuration: configuration.into(),
3836        }
3837    }
3838
3839    pub fn role(&self) -> &str {
3840        &self.role
3841    }
3842
3843    pub fn configuration(&self) -> &AccessLogConfiguration {
3844        &self.configuration
3845    }
3846
3847    pub fn set_role(&mut self, role: impl Into<String>) {
3848        self.role = role.into();
3849    }
3850
3851    pub fn set_configuration(&mut self, configuration: impl Into<AccessLogConfiguration>) {
3852        self.configuration = configuration.into();
3853    }
3854}
3855#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
3856pub struct AccessLogConfiguration {
3857    #[serde(rename = "UseServiceTopic")]
3858    #[serde(default)]
3859    pub(crate) use_service_topic: bool,
3860    #[serde(rename = "TLSProjectID")]
3861    #[serde(skip_serializing_if = "String::is_empty")]
3862    #[serde(default)]
3863    pub(crate) tls_project_id: String,
3864    #[serde(rename = "TLSTopicID")]
3865    #[serde(skip_serializing_if = "String::is_empty")]
3866    #[serde(default)]
3867    pub(crate) tls_topic_id: String,
3868    #[serde(rename = "TLSDashboardID")]
3869    #[serde(skip_serializing_if = "String::is_empty")]
3870    #[serde(default)]
3871    pub(crate) tls_dashboard_id: String,
3872    #[serde(rename = "TTL")]
3873    #[serde(skip_serializing_if = "is_non_positive")]
3874    #[serde(default)]
3875    pub(crate) ttl: isize,
3876}
3877
3878impl AccessLogConfiguration {
3879    pub fn new() -> Self {
3880        Self::default()
3881    }
3882    pub fn use_service_topic(&self) -> bool {
3883        self.use_service_topic
3884    }
3885
3886    pub fn tls_project_id(&self) -> &str {
3887        &self.tls_project_id
3888    }
3889
3890    pub fn tls_topic_id(&self) -> &str {
3891        &self.tls_topic_id
3892    }
3893
3894    pub fn tls_dashboard_id(&self) -> &str {
3895        &self.tls_dashboard_id
3896    }
3897
3898    pub fn ttl(&self) -> isize {
3899        self.ttl
3900    }
3901
3902    pub fn set_use_service_topic(&mut self, use_service_topic: bool) {
3903        self.use_service_topic = use_service_topic;
3904    }
3905
3906    pub fn set_tls_project_id(&mut self, tls_project_id: impl Into<String>) {
3907        self.tls_project_id = tls_project_id.into();
3908    }
3909
3910    pub fn set_tls_topic_id(&mut self, tls_topic_id: impl Into<String>) {
3911        self.tls_topic_id = tls_topic_id.into();
3912    }
3913
3914    pub fn set_tls_dashboard_id(&mut self, tls_dashboard_id: impl Into<String>) {
3915        self.tls_dashboard_id = tls_dashboard_id.into();
3916    }
3917
3918    pub fn set_ttl(&mut self, ttl: isize) {
3919        self.ttl = ttl;
3920    }
3921}
3922#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3923pub struct PutBucketRealTimeLogOutput {
3924    pub(crate) request_info: RequestInfo,
3925}
3926#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3927pub struct GetBucketRealTimeLogInput {
3928    pub(crate) generic_input: GenericInput,
3929    pub(crate) bucket: String,
3930}
3931
3932impl InputDescriptor for GetBucketRealTimeLogInput {
3933    fn operation(&self) -> &str {
3934        "GetBucketRealTimeLog"
3935    }
3936
3937    fn bucket(&self) -> Result<&str, TosError> {
3938        Ok(&self.bucket)
3939    }
3940}
3941
3942impl<B> InputTranslator<B> for GetBucketRealTimeLogInput {
3943    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3944        let mut request = self.trans_bucket()?;
3945        request.query = Some(HashMap::from([("realtimeLog", "".to_string())]));
3946        request.method = HttpMethodGet;
3947        Ok(request)
3948    }
3949}
3950#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
3951pub struct GetBucketRealTimeLogOutput {
3952    #[serde(skip)]
3953    pub(crate) request_info: RequestInfo,
3954    #[serde(rename = "RealTimeLogConfiguration")]
3955    pub(crate) configuration: RealTimeLogConfiguration,
3956}
3957
3958impl GetBucketRealTimeLogOutput {
3959    pub fn configuration(&self) -> &RealTimeLogConfiguration {
3960        &self.configuration
3961    }
3962}
3963#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
3964pub struct DeleteBucketRealTimeLogInput {
3965    pub(crate) generic_input: GenericInput,
3966    pub(crate) bucket: String,
3967}
3968impl InputDescriptor for DeleteBucketRealTimeLogInput {
3969    fn operation(&self) -> &str {
3970        "DeleteBucketRealTimeLog"
3971    }
3972
3973    fn bucket(&self) -> Result<&str, TosError> {
3974        Ok(&self.bucket)
3975    }
3976}
3977
3978impl<B> InputTranslator<B> for DeleteBucketRealTimeLogInput {
3979    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
3980        let mut request = self.trans_bucket()?;
3981        request.query = Some(HashMap::from([("realtimeLog", "".to_string())]));
3982        request.method = HttpMethodDelete;
3983        Ok(request)
3984    }
3985}
3986#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
3987pub struct DeleteBucketRealTimeLogOutput {
3988    pub(crate) request_info: RequestInfo,
3989}
3990#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
3991pub struct PutBucketRenameInput {
3992    #[serde(skip)]
3993    pub(crate) generic_input: GenericInput,
3994    #[serde(skip)]
3995    pub(crate) bucket: String,
3996    #[serde(rename = "RenameEnable")]
3997    pub(crate) rename_enable: bool,
3998}
3999impl PutBucketRenameInput {
4000    pub fn new(bucket: impl Into<String>, rename_enable: bool) -> Self {
4001        Self {
4002            generic_input: Default::default(),
4003            bucket: bucket.into(),
4004            rename_enable,
4005        }
4006    }
4007
4008    pub fn bucket(&self) -> &str {
4009        &self.bucket
4010    }
4011
4012    pub fn rename_enable(&self) -> bool {
4013        self.rename_enable
4014    }
4015
4016    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
4017        self.bucket = bucket.into();
4018    }
4019
4020    pub fn set_rename_enable(&mut self, rename_enable: bool) {
4021        self.rename_enable = rename_enable;
4022    }
4023}
4024
4025impl InputDescriptor for PutBucketRenameInput {
4026    fn operation(&self) -> &str {
4027        "PutBucketRename"
4028    }
4029
4030    fn bucket(&self) -> Result<&str, TosError> {
4031        Ok(&self.bucket)
4032    }
4033}
4034
4035impl<B> InputTranslator<B> for PutBucketRenameInput
4036where
4037    B: BuildBufferReader,
4038{
4039    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4040        match serde_json::to_string(self) {
4041            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
4042            Ok(json) => {
4043                let mut request = self.trans_bucket()?;
4044                request.method = HttpMethodPut;
4045                request.query = Some(HashMap::from([("rename", "".to_string())]));
4046                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
4047                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
4048                request.body = Some(body);
4049                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
4050                Ok(request)
4051            }
4052        }
4053    }
4054}
4055#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4056pub struct PutBucketRenameOutput {
4057    pub(crate) request_info: RequestInfo,
4058}
4059
4060#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4061pub struct GetBucketRenameInput {
4062    pub(crate) generic_input: GenericInput,
4063    pub(crate) bucket: String,
4064}
4065impl InputDescriptor for GetBucketRenameInput {
4066    fn operation(&self) -> &str {
4067        "GetBucketRename"
4068    }
4069
4070    fn bucket(&self) -> Result<&str, TosError> {
4071        Ok(&self.bucket)
4072    }
4073}
4074
4075impl<B> InputTranslator<B> for GetBucketRenameInput
4076where
4077    B: BuildBufferReader,
4078{
4079    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4080        let mut request = self.trans_bucket()?;
4081        request.method = HttpMethodGet;
4082        request.query = Some(HashMap::from([("rename", "".to_string())]));
4083        Ok(request)
4084    }
4085}
4086#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
4087pub struct GetBucketRenameOutput {
4088    #[serde(skip)]
4089    pub(crate) request_info: RequestInfo,
4090    #[serde(rename = "RenameEnable")]
4091    #[serde(default)]
4092    pub(crate) rename_enable: bool,
4093}
4094impl GetBucketRenameOutput {
4095    pub fn rename_enable(&self) -> bool {
4096        self.rename_enable
4097    }
4098}
4099#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4100pub struct DeleteBucketRenameInput {
4101    pub(crate) generic_input: GenericInput,
4102    pub(crate) bucket: String,
4103}
4104impl InputDescriptor for DeleteBucketRenameInput {
4105    fn operation(&self) -> &str {
4106        "DeleteBucketRename"
4107    }
4108
4109    fn bucket(&self) -> Result<&str, TosError> {
4110        Ok(&self.bucket)
4111    }
4112}
4113
4114impl<B> InputTranslator<B> for DeleteBucketRenameInput
4115where
4116    B: BuildBufferReader,
4117{
4118    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4119        let mut request = self.trans_bucket()?;
4120        request.method = HttpMethodDelete;
4121        request.query = Some(HashMap::from([("rename", "".to_string())]));
4122        Ok(request)
4123    }
4124}
4125#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4126pub struct DeleteBucketRenameOutput {
4127    pub(crate) request_info: RequestInfo,
4128}
4129#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
4130pub struct PutBucketEncryptionInput {
4131    #[serde(skip)]
4132    pub(crate) generic_input: GenericInput,
4133    #[serde(skip)]
4134    pub(crate) bucket: String,
4135    #[serde(rename = "Rule")]
4136    pub(crate) rule: BucketEncryptionRule,
4137}
4138impl PutBucketEncryptionInput {
4139    pub fn new(bucket: impl Into<String>, rule: impl Into<BucketEncryptionRule>) -> Self {
4140        Self {
4141            generic_input: Default::default(),
4142            bucket: bucket.into(),
4143            rule: rule.into(),
4144        }
4145    }
4146
4147    pub fn bucket(&self) -> &str {
4148        &self.bucket
4149    }
4150
4151    pub fn rule(&self) -> &BucketEncryptionRule {
4152        &self.rule
4153    }
4154
4155    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
4156        self.bucket = bucket.into();
4157    }
4158
4159    pub fn set_rule(&mut self, rule: impl Into<BucketEncryptionRule>) {
4160        self.rule = rule.into();
4161    }
4162}
4163
4164impl InputDescriptor for PutBucketEncryptionInput {
4165    fn operation(&self) -> &str {
4166        "PutBucketEncryption"
4167    }
4168
4169    fn bucket(&self) -> Result<&str, TosError> {
4170        Ok(&self.bucket)
4171    }
4172}
4173
4174impl<B> InputTranslator<B> for PutBucketEncryptionInput
4175where
4176    B: BuildBufferReader,
4177{
4178    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4179        match serde_json::to_string(self) {
4180            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
4181            Ok(json) => {
4182                let mut request = self.trans_bucket()?;
4183                request.method = HttpMethodPut;
4184                request.query = Some(HashMap::from([("encryption", "".to_string())]));
4185                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
4186                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
4187                request.body = Some(body);
4188                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
4189                Ok(request)
4190            }
4191        }
4192    }
4193}
4194
4195#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4196pub struct BucketEncryptionRule {
4197    #[serde(rename = "ApplyServerSideEncryptionByDefault")]
4198    pub(crate) apply_server_side_encryption_by_default: ApplyServerSideEncryptionByDefault,
4199}
4200impl BucketEncryptionRule {
4201    pub fn new(apply_server_side_encryption_by_default: impl Into<ApplyServerSideEncryptionByDefault>) -> Self {
4202        Self {
4203            apply_server_side_encryption_by_default: apply_server_side_encryption_by_default.into(),
4204        }
4205    }
4206
4207    pub fn apply_server_side_encryption_by_default(&self) -> &ApplyServerSideEncryptionByDefault {
4208        &self.apply_server_side_encryption_by_default
4209    }
4210
4211    pub fn set_apply_server_side_encryption_by_default(&mut self, apply_server_side_encryption_by_default: impl Into<ApplyServerSideEncryptionByDefault>) {
4212        self.apply_server_side_encryption_by_default = apply_server_side_encryption_by_default.into();
4213    }
4214}
4215#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4216pub struct ApplyServerSideEncryptionByDefault {
4217    #[serde(rename = "SSEAlgorithm")]
4218    #[serde(skip_serializing_if = "String::is_empty")]
4219    #[serde(default)]
4220    pub(crate) sse_algorithm: String,
4221    #[serde(rename = "KMSMasterKeyID")]
4222    #[serde(skip_serializing_if = "String::is_empty")]
4223    #[serde(default)]
4224    pub(crate) kms_master_key_id: String,
4225}
4226impl ApplyServerSideEncryptionByDefault {
4227    pub fn new(sse_algorithm: impl Into<String>, kms_master_key_id: impl Into<String>) -> Self {
4228        Self {
4229            sse_algorithm: sse_algorithm.into(),
4230            kms_master_key_id: kms_master_key_id.into(),
4231        }
4232    }
4233
4234    pub fn sse_algorithm(&self) -> &str {
4235        &self.sse_algorithm
4236    }
4237
4238    pub fn kms_master_key_id(&self) -> &str {
4239        &self.kms_master_key_id
4240    }
4241
4242    pub fn set_kms_master_key_id(&mut self, kms_master_key_id: impl Into<String>) {
4243        self.kms_master_key_id = kms_master_key_id.into();
4244    }
4245
4246    pub fn set_sse_algorithm(&mut self, sse_algorithm: impl Into<String>) {
4247        self.sse_algorithm = sse_algorithm.into();
4248    }
4249}
4250#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4251pub struct PutBucketEncryptionOutput {
4252    pub(crate) request_info: RequestInfo,
4253}
4254#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4255pub struct GetBucketEncryptionInput {
4256    pub(crate) generic_input: GenericInput,
4257    pub(crate) bucket: String,
4258}
4259
4260impl InputDescriptor for GetBucketEncryptionInput {
4261    fn operation(&self) -> &str {
4262        "GetBucketEncryption"
4263    }
4264
4265    fn bucket(&self) -> Result<&str, TosError> {
4266        Ok(&self.bucket)
4267    }
4268}
4269
4270impl<B> InputTranslator<B> for GetBucketEncryptionInput {
4271    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4272        let mut request = self.trans_bucket()?;
4273        request.method = HttpMethodGet;
4274        request.query = Some(HashMap::from([("encryption", "".to_string())]));
4275        Ok(request)
4276    }
4277}
4278#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
4279pub struct GetBucketEncryptionOutput {
4280    #[serde(skip)]
4281    pub(crate) request_info: RequestInfo,
4282    #[serde(rename = "Rule")]
4283    pub(crate) rule: BucketEncryptionRule,
4284}
4285impl GetBucketEncryptionOutput {
4286    pub fn rule(&self) -> &BucketEncryptionRule {
4287        &self.rule
4288    }
4289}
4290#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4291pub struct DeleteBucketEncryptionInput {
4292    pub(crate) generic_input: GenericInput,
4293    pub(crate) bucket: String,
4294}
4295
4296impl InputDescriptor for DeleteBucketEncryptionInput {
4297    fn operation(&self) -> &str {
4298        "DeleteBucketEncryption"
4299    }
4300
4301    fn bucket(&self) -> Result<&str, TosError> {
4302        Ok(&self.bucket)
4303    }
4304}
4305
4306impl<B> InputTranslator<B> for DeleteBucketEncryptionInput {
4307    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4308        let mut request = self.trans_bucket()?;
4309        request.method = HttpMethodDelete;
4310        request.query = Some(HashMap::from([("encryption", "".to_string())]));
4311        Ok(request)
4312    }
4313}
4314#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4315pub struct DeleteBucketEncryptionOutput {
4316    pub(crate) request_info: RequestInfo,
4317}
4318#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
4319pub struct PutBucketTaggingInput {
4320    #[serde(skip)]
4321    pub(crate) generic_input: GenericInput,
4322    #[serde(skip)]
4323    pub(crate) bucket: String,
4324    #[serde(rename = "TagSet")]
4325    pub(crate) tag_set: TagSet,
4326}
4327
4328impl PutBucketTaggingInput {
4329    pub fn new(bucket: impl Into<String>, tag_set: impl Into<TagSet>) -> Self {
4330        Self {
4331            generic_input: Default::default(),
4332            bucket: bucket.into(),
4333            tag_set: tag_set.into(),
4334        }
4335    }
4336
4337    pub fn bucket(&self) -> &str {
4338        &self.bucket
4339    }
4340
4341    pub fn tag_set(&self) -> &TagSet {
4342        &self.tag_set
4343    }
4344
4345    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
4346        self.bucket = bucket.into();
4347    }
4348
4349    pub fn set_tag_set(&mut self, tag_set: impl Into<TagSet>) {
4350        self.tag_set = tag_set.into();
4351    }
4352}
4353
4354impl InputDescriptor for PutBucketTaggingInput {
4355    fn operation(&self) -> &str {
4356        "PutBucketTagging"
4357    }
4358
4359    fn bucket(&self) -> Result<&str, TosError> {
4360        Ok(&self.bucket)
4361    }
4362}
4363
4364impl<B> InputTranslator<B> for PutBucketTaggingInput
4365where
4366    B: BuildBufferReader,
4367{
4368    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4369        match serde_json::to_string(self) {
4370            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
4371            Ok(json) => {
4372                let mut request = self.trans_bucket()?;
4373                request.method = HttpMethodPut;
4374                request.query = Some(HashMap::from([("tagging", "".to_string())]));
4375                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
4376                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
4377                request.body = Some(body);
4378                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
4379                Ok(request)
4380            }
4381        }
4382    }
4383}
4384#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4385pub struct PutBucketTaggingOutput {
4386    pub(crate) request_info: RequestInfo,
4387}
4388#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4389pub struct GetBucketTaggingInput {
4390    pub(crate) generic_input: GenericInput,
4391    pub(crate) bucket: String,
4392}
4393impl InputDescriptor for GetBucketTaggingInput {
4394    fn operation(&self) -> &str {
4395        "GetBucketTagging"
4396    }
4397
4398    fn bucket(&self) -> Result<&str, TosError> {
4399        Ok(&self.bucket)
4400    }
4401}
4402
4403impl<B> InputTranslator<B> for GetBucketTaggingInput {
4404    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4405        let mut request = self.trans_bucket()?;
4406        request.method = HttpMethodGet;
4407        request.query = Some(HashMap::from([("tagging", "".to_string())]));
4408        Ok(request)
4409    }
4410}
4411
4412#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
4413pub struct GetBucketTaggingOutput {
4414    #[serde(skip)]
4415    pub(crate) request_info: RequestInfo,
4416    #[serde(rename = "TagSet")]
4417    pub(crate) tag_set: TagSet,
4418}
4419impl GetBucketTaggingOutput {
4420    pub fn tag_set(&self) -> &TagSet {
4421        &self.tag_set
4422    }
4423}
4424#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4425pub struct DeleteBucketTaggingInput {
4426    pub(crate) generic_input: GenericInput,
4427    pub(crate) bucket: String,
4428}
4429
4430impl InputDescriptor for DeleteBucketTaggingInput {
4431    fn operation(&self) -> &str {
4432        "DeleteBucketTagging"
4433    }
4434
4435    fn bucket(&self) -> Result<&str, TosError> {
4436        Ok(&self.bucket)
4437    }
4438}
4439
4440impl<B> InputTranslator<B> for DeleteBucketTaggingInput {
4441    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4442        let mut request = self.trans_bucket()?;
4443        request.method = HttpMethodDelete;
4444        request.query = Some(HashMap::from([("tagging", "".to_string())]));
4445        Ok(request)
4446    }
4447}
4448#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4449pub struct DeleteBucketTaggingOutput {
4450    pub(crate) request_info: RequestInfo,
4451}
4452#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
4453pub struct PutBucketNotificationType2Input {
4454    #[serde(skip)]
4455    pub(crate) generic_input: GenericInput,
4456    #[serde(skip)]
4457    pub(crate) bucket: String,
4458    #[serde(rename = "Rules")]
4459    pub(crate) rules: Vec<NotificationRule>,
4460    #[serde(rename = "Version")]
4461    pub(crate) version: String,
4462}
4463impl PutBucketNotificationType2Input {
4464    pub fn new(bucket: impl Into<String>, rules: impl Into<Vec<NotificationRule>>) -> Self {
4465        Self {
4466            generic_input: Default::default(),
4467            bucket: bucket.into(),
4468            rules: rules.into(),
4469            version: "".to_string(),
4470        }
4471    }
4472
4473    pub fn bucket(&self) -> &str {
4474        &self.bucket
4475    }
4476
4477    pub fn rules(&self) -> &Vec<NotificationRule> {
4478        &self.rules
4479    }
4480
4481    pub fn version(&self) -> &str {
4482        &self.version
4483    }
4484
4485    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
4486        self.bucket = bucket.into();
4487    }
4488
4489    pub fn add_rule(&mut self, rules: impl Into<NotificationRule>) {
4490        self.rules.push(rules.into());
4491    }
4492    pub fn set_rules(&mut self, rules: impl Into<Vec<NotificationRule>>) {
4493        self.rules = rules.into();
4494    }
4495
4496    pub fn set_version(&mut self, version: impl Into<String>) {
4497        self.version = version.into();
4498    }
4499}
4500
4501impl InputDescriptor for PutBucketNotificationType2Input {
4502    fn operation(&self) -> &str {
4503        "PutBucketNotificationType2"
4504    }
4505
4506    fn bucket(&self) -> Result<&str, TosError> {
4507        Ok(&self.bucket)
4508    }
4509}
4510
4511impl<B> InputTranslator<B> for PutBucketNotificationType2Input
4512where
4513    B: BuildBufferReader,
4514{
4515    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4516        match serde_json::to_string(self) {
4517            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
4518            Ok(json) => {
4519                let mut request = self.trans_bucket()?;
4520                request.method = HttpMethodPut;
4521                request.query = Some(HashMap::from([("notification_v2", "".to_string())]));
4522                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
4523                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
4524                request.body = Some(body);
4525                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
4526                Ok(request)
4527            }
4528        }
4529    }
4530}
4531#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4532pub struct NotificationRule {
4533    #[serde(rename = "RuleId")]
4534    #[serde(skip_serializing_if = "String::is_empty")]
4535    #[serde(default)]
4536    pub(crate) rule_id: String,
4537    #[serde(rename = "Events")]
4538    #[serde(skip_serializing_if = "Vec::is_empty")]
4539    #[serde(default)]
4540    pub(crate) events: Vec<String>,
4541    #[serde(rename = "Filter")]
4542    pub(crate) filter: NotificationFilter,
4543    #[serde(rename = "Destination")]
4544    pub(crate) destination: NotificationDestination,
4545}
4546impl NotificationRule {
4547    pub fn new(rule_id: impl Into<String>) -> Self {
4548        Self {
4549            rule_id: rule_id.into(),
4550            events: vec![],
4551            filter: Default::default(),
4552            destination: Default::default(),
4553        }
4554    }
4555
4556    pub fn rule_id(&self) -> &str {
4557        &self.rule_id
4558    }
4559
4560    pub fn events(&self) -> &Vec<String> {
4561        &self.events
4562    }
4563
4564    pub fn filter(&self) -> &NotificationFilter {
4565        &self.filter
4566    }
4567
4568    pub fn destination(&self) -> &NotificationDestination {
4569        &self.destination
4570    }
4571
4572    pub fn set_rule_id(&mut self, rule_id: impl Into<String>) {
4573        self.rule_id = rule_id.into();
4574    }
4575
4576    pub fn set_events(&mut self, events: impl Into<Vec<String>>) {
4577        self.events = events.into();
4578    }
4579
4580    pub fn set_filter(&mut self, filter: impl Into<NotificationFilter>) {
4581        self.filter = filter.into();
4582    }
4583
4584    pub fn set_destination(&mut self, destination: impl Into<NotificationDestination>) {
4585        self.destination = destination.into();
4586    }
4587}
4588#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4589pub struct NotificationFilter {
4590    #[serde(rename = "TOSKey")]
4591    pub(crate) tos_key: NotificationFilterKey,
4592}
4593impl NotificationFilter {
4594    pub fn new(tos_key: impl Into<NotificationFilterKey>) -> Self {
4595        Self {
4596            tos_key: tos_key.into(),
4597        }
4598    }
4599
4600    pub fn tos_key(&self) -> &NotificationFilterKey {
4601        &self.tos_key
4602    }
4603
4604    pub fn set_tos_key(&mut self, tos_key: impl Into<NotificationFilterKey>) {
4605        self.tos_key = tos_key.into();
4606    }
4607}
4608#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4609pub struct NotificationFilterKey {
4610    #[serde(rename = "FilterRules")]
4611    #[serde(skip_serializing_if = "Vec::is_empty")]
4612    #[serde(default)]
4613    pub(crate) filter_rules: Vec<NotificationFilterRule>,
4614}
4615impl NotificationFilterKey {
4616    pub fn new(filter_rules: impl Into<Vec<NotificationFilterRule>>) -> Self {
4617        Self {
4618            filter_rules: filter_rules.into(),
4619        }
4620    }
4621
4622    pub fn filter_rules(&self) -> &Vec<NotificationFilterRule> {
4623        &self.filter_rules
4624    }
4625
4626    pub fn set_filter_rules(&mut self, filter_rules: impl Into<Vec<NotificationFilterRule>>) {
4627        self.filter_rules = filter_rules.into();
4628    }
4629}
4630#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4631pub struct NotificationFilterRule {
4632    #[serde(rename = "Name")]
4633    #[serde(skip_serializing_if = "String::is_empty")]
4634    #[serde(default)]
4635    pub(crate) name: String,
4636    #[serde(rename = "Value")]
4637    #[serde(skip_serializing_if = "String::is_empty")]
4638    #[serde(default)]
4639    pub(crate) value: String,
4640}
4641impl NotificationFilterRule {
4642    pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4643        Self {
4644            name: name.into(),
4645            value: value.into(),
4646        }
4647    }
4648
4649    pub fn name(&self) -> &str {
4650        &self.name
4651    }
4652
4653    pub fn value(&self) -> &str {
4654        &self.value
4655    }
4656
4657    pub fn set_name(&mut self, name: impl Into<String>) {
4658        self.name = name.into();
4659    }
4660
4661    pub fn set_value(&mut self, value: impl Into<String>) {
4662        self.value = value.into();
4663    }
4664}
4665#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4666pub struct NotificationDestination {
4667    #[serde(rename = "RocketMQ")]
4668    #[serde(skip_serializing_if = "Vec::is_empty")]
4669    #[serde(default)]
4670    pub(crate) rocket_mq: Vec<DestinationRocketMQ>,
4671    #[serde(rename = "VeFaaS")]
4672    #[serde(skip_serializing_if = "Vec::is_empty")]
4673    #[serde(default)]
4674    pub(crate) ve_faas: Vec<DestinationVeFaaS>,
4675    #[serde(rename = "Kafka")]
4676    #[serde(skip_serializing_if = "Vec::is_empty")]
4677    #[serde(default)]
4678    pub(crate) kafka: Vec<DestinationKafka>,
4679    #[serde(rename = "HttpServer")]
4680    #[serde(skip_serializing_if = "Vec::is_empty")]
4681    #[serde(default)]
4682    pub(crate) http_server: Vec<DestinationHttpServer>,
4683}
4684impl NotificationDestination {
4685    pub fn new() -> Self {
4686        Self {
4687            rocket_mq: vec![],
4688            ve_faas: vec![],
4689            kafka: vec![],
4690            http_server: vec![],
4691        }
4692    }
4693
4694    pub fn rocket_mq(&self) -> &Vec<DestinationRocketMQ> {
4695        &self.rocket_mq
4696    }
4697
4698    pub fn ve_faas(&self) -> &Vec<DestinationVeFaaS> {
4699        &self.ve_faas
4700    }
4701
4702    pub fn kafka(&self) -> &Vec<DestinationKafka> {
4703        &self.kafka
4704    }
4705
4706    pub fn http_server(&self) -> &Vec<DestinationHttpServer> {
4707        &self.http_server
4708    }
4709
4710    pub fn set_rocket_mq(&mut self, rocket_mq: impl Into<Vec<DestinationRocketMQ>>) {
4711        self.rocket_mq = rocket_mq.into();
4712    }
4713
4714    pub fn set_ve_faas(&mut self, ve_faas: impl Into<Vec<DestinationVeFaaS>>) {
4715        self.ve_faas = ve_faas.into();
4716    }
4717
4718    pub fn set_kafka(&mut self, kafka: impl Into<Vec<DestinationKafka>>) {
4719        self.kafka = kafka.into();
4720    }
4721
4722    pub fn set_http_server(&mut self, http_server: impl Into<Vec<DestinationHttpServer>>) {
4723        self.http_server = http_server.into();
4724    }
4725}
4726#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4727pub struct DestinationRocketMQ {
4728    #[serde(rename = "Role")]
4729    #[serde(skip_serializing_if = "String::is_empty")]
4730    #[serde(default)]
4731    pub(crate) role: String,
4732    #[serde(rename = "InstanceId")]
4733    #[serde(skip_serializing_if = "String::is_empty")]
4734    #[serde(default)]
4735    pub(crate) instance_id: String,
4736    #[serde(rename = "Topic")]
4737    #[serde(skip_serializing_if = "String::is_empty")]
4738    #[serde(default)]
4739    pub(crate) topic: String,
4740    #[serde(rename = "AccessKeyId")]
4741    #[serde(skip_serializing_if = "String::is_empty")]
4742    #[serde(default)]
4743    pub(crate) access_key_id: String,
4744    #[serde(rename = "Region")]
4745    #[serde(skip_serializing_if = "String::is_empty")]
4746    #[serde(default)]
4747    pub(crate) region: String,
4748}
4749impl DestinationRocketMQ {
4750    pub fn new(role: impl Into<String>) -> Self {
4751        Self {
4752            role: role.into(),
4753            instance_id: "".to_string(),
4754            topic: "".to_string(),
4755            access_key_id: "".to_string(),
4756            region: "".to_string(),
4757        }
4758    }
4759
4760    pub fn role(&self) -> &str {
4761        &self.role
4762    }
4763
4764    pub fn instance_id(&self) -> &str {
4765        &self.instance_id
4766    }
4767
4768    pub fn topic(&self) -> &str {
4769        &self.topic
4770    }
4771
4772    pub fn access_key_id(&self) -> &str {
4773        &self.access_key_id
4774    }
4775
4776    pub fn region(&self) -> &str {
4777        &self.region
4778    }
4779
4780    pub fn set_role(&mut self, role: impl Into<String>) {
4781        self.role = role.into();
4782    }
4783
4784    pub fn set_instance_id(&mut self, instance_id: impl Into<String>) {
4785        self.instance_id = instance_id.into();
4786    }
4787
4788    pub fn set_topic(&mut self, topic: impl Into<String>) {
4789        self.topic = topic.into();
4790    }
4791
4792    pub fn set_access_key_id(&mut self, access_key_id: impl Into<String>) {
4793        self.access_key_id = access_key_id.into();
4794    }
4795
4796    pub fn set_region(&mut self, region: impl Into<String>) {
4797        self.region = region.into();
4798    }
4799}
4800#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4801pub struct DestinationVeFaaS {
4802    #[serde(rename = "FunctionId")]
4803    #[serde(skip_serializing_if = "String::is_empty")]
4804    #[serde(default)]
4805    pub(crate) function_id: String,
4806}
4807impl DestinationVeFaaS {
4808    pub fn new(function_id: impl Into<String>) -> Self {
4809        Self {
4810            function_id: function_id.into(),
4811        }
4812    }
4813
4814    pub fn function_id(&self) -> &str {
4815        &self.function_id
4816    }
4817
4818    pub fn set_function_id(&mut self, function_id: impl Into<String>) {
4819        self.function_id = function_id.into();
4820    }
4821}
4822#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4823pub struct DestinationKafka {
4824    #[serde(rename = "Role")]
4825    #[serde(skip_serializing_if = "String::is_empty")]
4826    #[serde(default)]
4827    pub(crate) role: String,
4828    #[serde(rename = "InstanceId")]
4829    #[serde(skip_serializing_if = "String::is_empty")]
4830    #[serde(default)]
4831    pub(crate) instance_id: String,
4832    #[serde(rename = "Topic")]
4833    #[serde(skip_serializing_if = "String::is_empty")]
4834    #[serde(default)]
4835    pub(crate) topic: String,
4836    #[serde(rename = "User")]
4837    #[serde(skip_serializing_if = "String::is_empty")]
4838    #[serde(default)]
4839    pub(crate) user: String,
4840    #[serde(rename = "Region")]
4841    #[serde(skip_serializing_if = "String::is_empty")]
4842    #[serde(default)]
4843    pub(crate) region: String,
4844}
4845impl DestinationKafka {
4846    pub fn new(role: impl Into<String>) -> Self {
4847        Self {
4848            role: role.into(),
4849            instance_id: "".to_string(),
4850            topic: "".to_string(),
4851            user: "".to_string(),
4852            region: "".to_string(),
4853        }
4854    }
4855
4856    pub fn role(&self) -> &str {
4857        &self.role
4858    }
4859
4860    pub fn instance_id(&self) -> &str {
4861        &self.instance_id
4862    }
4863
4864    pub fn topic(&self) -> &str {
4865        &self.topic
4866    }
4867
4868    pub fn user(&self) -> &str {
4869        &self.user
4870    }
4871
4872    pub fn region(&self) -> &str {
4873        &self.region
4874    }
4875
4876    pub fn set_role(&mut self, role: impl Into<String>) {
4877        self.role = role.into();
4878    }
4879
4880    pub fn set_instance_id(&mut self, instance_id: impl Into<String>) {
4881        self.instance_id = instance_id.into();
4882    }
4883
4884    pub fn set_topic(&mut self, topic: impl Into<String>) {
4885        self.topic = topic.into();
4886    }
4887
4888    pub fn set_user(&mut self, user: impl Into<String>) {
4889        self.user = user.into();
4890    }
4891
4892    pub fn set_region(&mut self, region: impl Into<String>) {
4893        self.region = region.into();
4894    }
4895}
4896#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4897pub struct DestinationHttpServer {
4898    #[serde(rename = "Url")]
4899    #[serde(skip_serializing_if = "String::is_empty")]
4900    #[serde(default)]
4901    pub(crate) url: String,
4902}
4903impl DestinationHttpServer {
4904    pub fn new(url: impl Into<String>) -> Self {
4905        Self {
4906            url: url.into(),
4907        }
4908    }
4909
4910    pub fn url(&self) -> &str {
4911        &self.url
4912    }
4913
4914    pub fn set_url(&mut self, url: impl Into<String>) {
4915        self.url = url.into();
4916    }
4917}
4918#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
4919pub struct PutBucketNotificationType2Output {
4920    pub(crate) request_info: RequestInfo,
4921}
4922#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
4923pub struct GetBucketNotificationType2Input {
4924    pub(crate) generic_input: GenericInput,
4925    pub(crate) bucket: String,
4926}
4927
4928impl InputDescriptor for GetBucketNotificationType2Input {
4929    fn operation(&self) -> &str {
4930        "GetBucketNotificationType2"
4931    }
4932
4933    fn bucket(&self) -> Result<&str, TosError> {
4934        Ok(&self.bucket)
4935    }
4936}
4937
4938impl<B> InputTranslator<B> for GetBucketNotificationType2Input {
4939    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
4940        let mut request = self.trans_bucket()?;
4941        request.method = HttpMethodGet;
4942        request.query = Some(HashMap::from([("notification_v2", "".to_string())]));
4943        Ok(request)
4944    }
4945}
4946
4947#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
4948pub struct GetBucketNotificationType2Output {
4949    #[serde(skip)]
4950    pub(crate) request_info: RequestInfo,
4951    #[serde(rename = "Rules")]
4952    pub(crate) rules: Vec<NotificationRule>,
4953    #[serde(rename = "Version")]
4954    pub(crate) version: String,
4955}
4956impl GetBucketNotificationType2Output {
4957    pub fn rules(&self) -> &Vec<NotificationRule> {
4958        &self.rules
4959    }
4960
4961    pub fn version(&self) -> &str {
4962        &self.version
4963    }
4964}
4965
4966#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
4967pub struct PutBucketInventoryInput {
4968    #[serde(skip)]
4969    pub(crate) generic_input: GenericInput,
4970    #[serde(skip)]
4971    pub(crate) bucket: String,
4972    #[serde(rename = "Id")]
4973    pub(crate) id: String,
4974    #[serde(rename = "IsEnabled")]
4975    #[serde(skip_serializing_if = "<&bool as std::ops::Not>::not")]
4976    pub(crate) is_enabled: bool,
4977    #[serde(rename = "Filter")]
4978    #[serde(skip_serializing_if = "Option::is_none")]
4979    pub(crate) filter: Option<InventoryFilter>,
4980    #[serde(rename = "Destination")]
4981    #[serde(skip_serializing_if = "Option::is_none")]
4982    pub(crate) destination: Option<InventoryDestination>,
4983    #[serde(rename = "Schedule")]
4984    #[serde(skip_serializing_if = "Option::is_none")]
4985    pub(crate) schedule: Option<InventorySchedule>,
4986    #[serde(rename = "IncludedObjectVersions")]
4987    pub(crate) included_object_versions: InventoryIncludedObjType,
4988    #[serde(rename = "OptionalFields")]
4989    #[serde(skip_serializing_if = "Option::is_none")]
4990    pub(crate) optional_fields: Option<InventoryOptionalFields>,
4991    #[serde(rename = "IsUnCompressed")]
4992    #[serde(skip_serializing_if = "<&bool as std::ops::Not>::not")]
4993    pub(crate) is_un_compressed: bool,
4994}
4995
4996impl PutBucketInventoryInput {
4997    pub fn new(bucket: impl Into<String>, id: impl Into<String>) -> Self {
4998        Self {
4999            generic_input: Default::default(),
5000            bucket: bucket.into(),
5001            id: id.into(),
5002            is_enabled: true,
5003            filter: None,
5004            destination: None,
5005            schedule: None,
5006            included_object_versions: Default::default(),
5007            optional_fields: None,
5008            is_un_compressed: false,
5009        }
5010    }
5011
5012    pub fn bucket(&self) -> &str {
5013        &self.bucket
5014    }
5015
5016    pub fn id(&self) -> &str {
5017        &self.id
5018    }
5019
5020    pub fn is_enabled(&self) -> bool {
5021        self.is_enabled
5022    }
5023
5024    pub fn filter(&self) -> &Option<InventoryFilter> {
5025        &self.filter
5026    }
5027
5028    pub fn destination(&self) -> &Option<InventoryDestination> {
5029        &self.destination
5030    }
5031
5032    pub fn schedule(&self) -> &Option<InventorySchedule> {
5033        &self.schedule
5034    }
5035
5036    pub fn included_object_versions(&self) -> &InventoryIncludedObjType {
5037        &self.included_object_versions
5038    }
5039
5040    pub fn optional_fields(&self) -> &Option<InventoryOptionalFields> {
5041        &self.optional_fields
5042    }
5043
5044    pub fn is_un_compressed(&self) -> bool {
5045        self.is_un_compressed
5046    }
5047
5048    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5049        self.bucket = bucket.into();
5050    }
5051
5052    pub fn set_id(&mut self, id: impl Into<String>) {
5053        self.id = id.into();
5054    }
5055
5056    pub fn set_is_enabled(&mut self, is_enabled: bool) {
5057        self.is_enabled = is_enabled;
5058    }
5059
5060    pub fn set_filter(&mut self, filter: impl Into<InventoryFilter>) {
5061        self.filter = Some(filter.into());
5062    }
5063
5064    pub fn set_destination(&mut self, destination: impl Into<InventoryDestination>) {
5065        self.destination = Some(destination.into());
5066    }
5067
5068    pub fn set_schedule(&mut self, schedule: impl Into<InventorySchedule>) {
5069        self.schedule = Some(schedule.into());
5070    }
5071
5072    pub fn set_included_object_versions(&mut self, included_object_versions: impl Into<InventoryIncludedObjType>) {
5073        self.included_object_versions = included_object_versions.into();
5074    }
5075
5076    pub fn set_optional_fields(&mut self, optional_fields: impl Into<InventoryOptionalFields>) {
5077        self.optional_fields = Some(optional_fields.into());
5078    }
5079
5080    pub fn set_is_un_compressed(&mut self, is_un_compressed: bool) {
5081        self.is_un_compressed = is_un_compressed;
5082    }
5083}
5084
5085impl InputDescriptor for PutBucketInventoryInput {
5086    fn operation(&self) -> &str {
5087        "PutBucketInventory"
5088    }
5089
5090    fn bucket(&self) -> Result<&str, TosError> {
5091        Ok(&self.bucket)
5092    }
5093}
5094
5095impl<B> InputTranslator<B> for PutBucketInventoryInput
5096where
5097    B: BuildBufferReader,
5098{
5099    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5100        if self.id == "" {
5101            return Err(TosError::client_error("empty id"));
5102        }
5103
5104        match serde_json::to_string(self) {
5105            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
5106            Ok(json) => {
5107                let mut request = self.trans_bucket()?;
5108                request.method = HttpMethodPut;
5109                let mut query = HashMap::with_capacity(2);
5110                query.insert("inventory", "".to_string());
5111                query.insert("id", self.id.to_string());
5112                request.query = Some(query);
5113                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
5114                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
5115                request.body = Some(body);
5116                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
5117                Ok(request)
5118            }
5119        }
5120    }
5121}
5122
5123#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
5124pub struct InventoryFilter {
5125    #[serde(rename = "Prefix")]
5126    #[serde(skip_serializing_if = "String::is_empty")]
5127    #[serde(default)]
5128    pub(crate) prefix: String,
5129}
5130impl InventoryFilter {
5131    pub fn new(prefix: impl Into<String>) -> Self {
5132        Self {
5133            prefix: prefix.into(),
5134        }
5135    }
5136
5137    pub fn prefix(&self) -> &str {
5138        &self.prefix
5139    }
5140
5141    pub fn set_prefix(&mut self, prefix: impl Into<String>) {
5142        self.prefix = prefix.into();
5143    }
5144}
5145#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
5146pub struct InventoryDestination {
5147    #[serde(rename = "TOSBucketDestination")]
5148    #[serde(skip_serializing_if = "Option::is_none")]
5149    #[serde(default)]
5150    pub(crate) tos_bucket_destination: Option<TOSBucketDestination>,
5151}
5152impl InventoryDestination {
5153    pub fn new() -> Self {
5154        Self::default()
5155    }
5156
5157    pub fn new_with_tos_bucket_destination(tos_bucket_destination: impl Into<TOSBucketDestination>) -> Self {
5158        Self {
5159            tos_bucket_destination: Some(tos_bucket_destination.into()),
5160        }
5161    }
5162
5163    pub fn tos_bucket_destination(&self) -> &Option<TOSBucketDestination> {
5164        &self.tos_bucket_destination
5165    }
5166
5167    pub fn set_tos_bucket_destination(&mut self, tos_bucket_destination: impl Into<TOSBucketDestination>) {
5168        self.tos_bucket_destination = Some(tos_bucket_destination.into());
5169    }
5170}
5171#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
5172pub struct TOSBucketDestination {
5173    #[serde(rename = "Format")]
5174    #[serde(default)]
5175    pub(crate) format: InventoryFormatType,
5176    #[serde(rename = "AccountId")]
5177    #[serde(skip_serializing_if = "String::is_empty")]
5178    #[serde(default)]
5179    pub(crate) account_id: String,
5180    #[serde(rename = "Role")]
5181    #[serde(skip_serializing_if = "String::is_empty")]
5182    #[serde(default)]
5183    pub(crate) role: String,
5184    #[serde(rename = "Bucket")]
5185    #[serde(skip_serializing_if = "String::is_empty")]
5186    #[serde(default)]
5187    pub(crate) bucket: String,
5188    #[serde(rename = "Prefix")]
5189    #[serde(skip_serializing_if = "String::is_empty")]
5190    #[serde(default)]
5191    pub(crate) prefix: String,
5192}
5193
5194impl TOSBucketDestination {
5195    pub fn new(format: impl Into<InventoryFormatType>) -> Self {
5196        Self {
5197            format: format.into(),
5198            account_id: "".to_string(),
5199            role: "".to_string(),
5200            bucket: "".to_string(),
5201            prefix: "".to_string(),
5202        }
5203    }
5204
5205    pub fn format(&self) -> &InventoryFormatType {
5206        &self.format
5207    }
5208
5209    pub fn account_id(&self) -> &str {
5210        &self.account_id
5211    }
5212
5213    pub fn role(&self) -> &str {
5214        &self.role
5215    }
5216
5217    pub fn bucket(&self) -> &str {
5218        &self.bucket
5219    }
5220
5221    pub fn prefix(&self) -> &str {
5222        &self.prefix
5223    }
5224
5225    pub fn set_format(&mut self, format: impl Into<InventoryFormatType>) {
5226        self.format = format.into();
5227    }
5228
5229    pub fn set_account_id(&mut self, account_id: impl Into<String>) {
5230        self.account_id = account_id.into();
5231    }
5232
5233    pub fn set_role(&mut self, role: impl Into<String>) {
5234        self.role = role.into();
5235    }
5236
5237    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5238        self.bucket = bucket.into();
5239    }
5240
5241    pub fn set_prefix(&mut self, prefix: impl Into<String>) {
5242        self.prefix = prefix.into();
5243    }
5244}
5245#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
5246pub struct InventorySchedule {
5247    #[serde(rename = "Frequency")]
5248    #[serde(default)]
5249    pub(crate) frequency: InventoryFrequencyType,
5250}
5251impl InventorySchedule {
5252    pub fn new(frequency: impl Into<InventoryFrequencyType>) -> Self {
5253        Self {
5254            frequency: frequency.into()
5255        }
5256    }
5257
5258    pub fn frequency(&self) -> &InventoryFrequencyType {
5259        &self.frequency
5260    }
5261
5262    pub fn set_frequency(&mut self, frequency: impl Into<InventoryFrequencyType>) {
5263        self.frequency = frequency.into();
5264    }
5265}
5266#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
5267pub struct InventoryOptionalFields {
5268    #[serde(rename = "Field")]
5269    #[serde(skip_serializing_if = "Vec::is_empty")]
5270    #[serde(default)]
5271    pub(crate) field: Vec<String>,
5272}
5273impl InventoryOptionalFields {
5274    pub fn new(field: impl Into<Vec<String>>) -> Self {
5275        Self {
5276            field: field.into(),
5277        }
5278    }
5279
5280    pub fn field(&self) -> &Vec<String> {
5281        &self.field
5282    }
5283
5284    pub fn set_field(&mut self, field: impl Into<Vec<String>>) {
5285        self.field = field.into();
5286    }
5287}
5288#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
5289pub struct PutBucketInventoryOutput {
5290    pub(crate) request_info: RequestInfo,
5291}
5292#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
5293pub struct GetBucketInventoryInput {
5294    pub(crate) generic_input: GenericInput,
5295    pub(crate) bucket: String,
5296    pub(crate) id: String,
5297}
5298impl GetBucketInventoryInput {
5299    pub fn new(bucket: impl Into<String>, id: impl Into<String>) -> Self {
5300        Self {
5301            generic_input: Default::default(),
5302            bucket: bucket.into(),
5303            id: id.into(),
5304        }
5305    }
5306
5307    pub fn bucket(&self) -> &str {
5308        &self.bucket
5309    }
5310
5311    pub fn id(&self) -> &str {
5312        &self.id
5313    }
5314
5315    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5316        self.bucket = bucket.into();
5317    }
5318
5319    pub fn set_id(&mut self, id: impl Into<String>) {
5320        self.id = id.into();
5321    }
5322}
5323
5324impl InputDescriptor for GetBucketInventoryInput {
5325    fn operation(&self) -> &str {
5326        "GetBucketInventory"
5327    }
5328
5329    fn bucket(&self) -> Result<&str, TosError> {
5330        Ok(&self.bucket)
5331    }
5332}
5333
5334impl<B> InputTranslator<B> for GetBucketInventoryInput {
5335    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5336        if self.id == "" {
5337            return Err(TosError::client_error("empty id"));
5338        }
5339
5340        let mut request = self.trans_bucket()?;
5341        request.method = HttpMethodGet;
5342        let mut query = HashMap::with_capacity(2);
5343        query.insert("inventory", "".to_string());
5344        query.insert("id", self.id.to_string());
5345        request.query = Some(query);
5346        Ok(request)
5347    }
5348}
5349#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
5350pub struct GetBucketInventoryOutput {
5351    #[serde(skip)]
5352    pub(crate) request_info: RequestInfo,
5353    #[serde(rename = "Id")]
5354    #[serde(default)]
5355    pub(crate) id: String,
5356    #[serde(rename = "IsEnabled")]
5357    #[serde(default)]
5358    pub(crate) is_enabled: bool,
5359    #[serde(rename = "Filter")]
5360    #[serde(default)]
5361    pub(crate) filter: Option<InventoryFilter>,
5362    #[serde(rename = "Destination")]
5363    #[serde(default)]
5364    pub(crate) destination: Option<InventoryDestination>,
5365    #[serde(rename = "Schedule")]
5366    #[serde(default)]
5367    pub(crate) schedule: Option<InventorySchedule>,
5368    #[serde(rename = "IncludedObjectVersions")]
5369    #[serde(default)]
5370    pub(crate) included_object_versions: InventoryIncludedObjType,
5371    #[serde(rename = "OptionalFields")]
5372    #[serde(default)]
5373    pub(crate) optional_fields: Option<InventoryOptionalFields>,
5374    #[serde(rename = "IsUnCompressed")]
5375    #[serde(default)]
5376    pub(crate) is_un_compressed: bool,
5377}
5378impl GetBucketInventoryOutput {
5379    pub fn id(&self) -> &str {
5380        &self.id
5381    }
5382
5383    pub fn is_enabled(&self) -> bool {
5384        self.is_enabled
5385    }
5386
5387    pub fn filter(&self) -> &Option<InventoryFilter> {
5388        &self.filter
5389    }
5390
5391    pub fn destination(&self) -> &Option<InventoryDestination> {
5392        &self.destination
5393    }
5394
5395    pub fn schedule(&self) -> &Option<InventorySchedule> {
5396        &self.schedule
5397    }
5398
5399    pub fn included_object_versions(&self) -> &InventoryIncludedObjType {
5400        &self.included_object_versions
5401    }
5402
5403    pub fn optional_fields(&self) -> &Option<InventoryOptionalFields> {
5404        &self.optional_fields
5405    }
5406
5407    pub fn is_un_compressed(&self) -> bool {
5408        self.is_un_compressed
5409    }
5410}
5411#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
5412pub struct ListBucketInventoryInput {
5413    pub(crate) generic_input: GenericInput,
5414    pub(crate) bucket: String,
5415    pub(crate) continuation_token: String,
5416}
5417impl ListBucketInventoryInput {
5418    pub fn new(bucket: impl Into<String>) -> Self {
5419        Self {
5420            generic_input: Default::default(),
5421            bucket: bucket.into(),
5422            continuation_token: "".to_string(),
5423        }
5424    }
5425    pub fn new_with_continuation_token(bucket: impl Into<String>, continuation_token: impl Into<String>) -> Self {
5426        Self {
5427            generic_input: Default::default(),
5428            bucket: bucket.into(),
5429            continuation_token: continuation_token.into(),
5430        }
5431    }
5432
5433    pub fn bucket(&self) -> &str {
5434        &self.bucket
5435    }
5436
5437    pub fn continuation_token(&self) -> &str {
5438        &self.continuation_token
5439    }
5440
5441    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5442        self.bucket = bucket.into();
5443    }
5444
5445    pub fn set_continuation_token(&mut self, continuation_token: impl Into<String>) {
5446        self.continuation_token = continuation_token.into();
5447    }
5448}
5449
5450impl InputDescriptor for ListBucketInventoryInput {
5451    fn operation(&self) -> &str {
5452        "ListBucketInventory"
5453    }
5454
5455    fn bucket(&self) -> Result<&str, TosError> {
5456        Ok(&self.bucket)
5457    }
5458}
5459
5460impl<B> InputTranslator<B> for ListBucketInventoryInput {
5461    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5462        let mut request = self.trans_bucket()?;
5463        request.method = HttpMethodGet;
5464        let mut query = HashMap::with_capacity(2);
5465        query.insert("inventory", "".to_string());
5466        if self.continuation_token != "" {
5467            query.insert("continuation-token", self.continuation_token.to_string());
5468        }
5469        request.query = Some(query);
5470        Ok(request)
5471    }
5472}
5473#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
5474pub struct ListBucketInventoryOutput {
5475    #[serde(skip)]
5476    pub(crate) request_info: RequestInfo,
5477    #[serde(rename = "IsTruncated")]
5478    #[serde(default)]
5479    pub(crate) is_truncated: bool,
5480    #[serde(rename = "InventoryConfigurations")]
5481    #[serde(default)]
5482    pub(crate) configurations: Vec<BucketInventoryConfiguration>,
5483    #[serde(rename = "NextContinuationToken")]
5484    #[serde(default)]
5485    pub(crate) next_continuation_token: String,
5486}
5487
5488impl ListBucketInventoryOutput {
5489    pub fn request_info(&self) -> &RequestInfo {
5490        &self.request_info
5491    }
5492
5493    pub fn is_truncated(&self) -> bool {
5494        self.is_truncated
5495    }
5496
5497    pub fn configurations(&self) -> &Vec<BucketInventoryConfiguration> {
5498        &self.configurations
5499    }
5500
5501    pub fn next_continuation_token(&self) -> &str {
5502        &self.next_continuation_token
5503    }
5504}
5505
5506#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
5507pub struct BucketInventoryConfiguration {
5508    #[serde(rename = "Id")]
5509    #[serde(default)]
5510    pub(crate) id: String,
5511    #[serde(rename = "IsEnabled")]
5512    #[serde(default)]
5513    pub(crate) is_enabled: bool,
5514    #[serde(rename = "Filter")]
5515    #[serde(default)]
5516    pub(crate) filter: Option<InventoryFilter>,
5517    #[serde(rename = "Destination")]
5518    #[serde(default)]
5519    pub(crate) destination: Option<InventoryDestination>,
5520    #[serde(rename = "Schedule")]
5521    #[serde(default)]
5522    pub(crate) schedule: Option<InventorySchedule>,
5523    #[serde(rename = "IncludedObjectVersions")]
5524    #[serde(default)]
5525    pub(crate) included_object_versions: InventoryIncludedObjType,
5526    #[serde(rename = "OptionalFields")]
5527    #[serde(default)]
5528    pub(crate) optional_fields: Option<InventoryOptionalFields>,
5529    #[serde(rename = "IsUnCompressed")]
5530    #[serde(default)]
5531    pub(crate) is_un_compressed: bool,
5532}
5533
5534impl BucketInventoryConfiguration {
5535    pub fn id(&self) -> &str {
5536        &self.id
5537    }
5538
5539    pub fn is_enabled(&self) -> bool {
5540        self.is_enabled
5541    }
5542
5543    pub fn filter(&self) -> &Option<InventoryFilter> {
5544        &self.filter
5545    }
5546
5547    pub fn destination(&self) -> &Option<InventoryDestination> {
5548        &self.destination
5549    }
5550
5551    pub fn schedule(&self) -> &Option<InventorySchedule> {
5552        &self.schedule
5553    }
5554
5555    pub fn included_object_versions(&self) -> &InventoryIncludedObjType {
5556        &self.included_object_versions
5557    }
5558
5559    pub fn optional_fields(&self) -> &Option<InventoryOptionalFields> {
5560        &self.optional_fields
5561    }
5562
5563    pub fn is_un_compressed(&self) -> bool {
5564        self.is_un_compressed
5565    }
5566}
5567
5568#[derive(Debug, Clone, PartialEq, Default, GenericInput)]
5569pub struct DeleteBucketInventoryInput {
5570    pub(crate) generic_input: GenericInput,
5571    pub(crate) bucket: String,
5572    pub(crate) id: String,
5573}
5574
5575impl DeleteBucketInventoryInput {
5576    pub fn new(bucket: impl Into<String>, id: impl Into<String>) -> Self {
5577        Self {
5578            generic_input: Default::default(),
5579            bucket: bucket.into(),
5580            id: id.into(),
5581        }
5582    }
5583
5584    pub fn bucket(&self) -> &str {
5585        &self.bucket
5586    }
5587
5588    pub fn id(&self) -> &str {
5589        &self.id
5590    }
5591
5592    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5593        self.bucket = bucket.into();
5594    }
5595
5596    pub fn set_id(&mut self, id: impl Into<String>) {
5597        self.id = id.into();
5598    }
5599}
5600
5601impl InputDescriptor for DeleteBucketInventoryInput {
5602    fn operation(&self) -> &str {
5603        "DeleteBucketInventory"
5604    }
5605
5606    fn bucket(&self) -> Result<&str, TosError> {
5607        Ok(&self.bucket)
5608    }
5609}
5610
5611impl<B> InputTranslator<B> for DeleteBucketInventoryInput {
5612    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5613        if self.id == "" {
5614            return Err(TosError::client_error("empty id"));
5615        }
5616
5617        let mut request = self.trans_bucket()?;
5618        request.method = HttpMethodDelete;
5619        let mut query = HashMap::with_capacity(2);
5620        query.insert("inventory", "".to_string());
5621        query.insert("id", self.id.to_string());
5622        request.query = Some(query);
5623        Ok(request)
5624    }
5625}
5626
5627#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
5628pub struct DeleteBucketInventoryOutput {
5629    pub(crate) request_info: RequestInfo,
5630}
5631
5632#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
5633pub struct GetBucketTypeInput {
5634    pub(crate) generic_input: GenericInput,
5635    pub(crate) bucket: String,
5636}
5637
5638#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
5639pub struct GetBucketTypeOutput {
5640    pub(crate) request_info: RequestInfo,
5641    pub(crate) region: String,
5642    pub(crate) storage_class: Option<StorageClassType>,
5643    pub(crate) az_redundancy: Option<AzRedundancyType>,
5644    pub(crate) project_name: String,
5645    pub(crate) bucket_type: Option<BucketType>,
5646    pub(crate) expire_at: DateTime<Utc>,
5647}
5648
5649impl GetBucketTypeOutput {
5650    pub fn region(&self) -> &str {
5651        &self.region
5652    }
5653
5654    pub fn storage_class(&self) -> &Option<StorageClassType> {
5655        &self.storage_class
5656    }
5657
5658    pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
5659        &self.az_redundancy
5660    }
5661
5662    pub fn project_name(&self) -> &str {
5663        &self.project_name
5664    }
5665
5666    pub fn bucket_type(&self) -> &Option<BucketType> {
5667        &self.bucket_type
5668    }
5669
5670    #[cfg(feature = "tokio-runtime")]
5671    pub fn expire_at(&self) -> DateTime<Utc> {
5672        self.expire_at
5673    }
5674}
5675
5676#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
5677pub struct DoesBucketExistInput {
5678    pub(crate) generic_input: GenericInput,
5679    pub(crate) bucket: String,
5680}
5681
5682#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
5683pub struct GetBucketInfoInput {
5684    pub(crate) generic_input: GenericInput,
5685    pub(crate) bucket: String,
5686}
5687
5688impl InputDescriptor for GetBucketInfoInput {
5689    fn operation(&self) -> &str {
5690        "GetBucketInfo"
5691    }
5692
5693    fn bucket(&self) -> Result<&str, TosError> {
5694        Ok(&self.bucket)
5695    }
5696}
5697
5698impl<B> InputTranslator<B> for GetBucketInfoInput {
5699    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5700        let mut request = self.trans_bucket()?;
5701        request.method = HttpMethodGet;
5702        let mut query = HashMap::with_capacity(1);
5703        query.insert("bucketInfo", "".to_string());
5704        request.query = Some(query);
5705        Ok(request)
5706    }
5707}
5708#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
5709pub struct GetBucketInfoOutput {
5710    #[serde(skip)]
5711    pub(crate) request_info: RequestInfo,
5712    #[serde(rename = "Bucket")]
5713    pub(crate) bucket: BucketInfo,
5714}
5715
5716impl GetBucketInfoOutput {
5717    pub fn bucket(&self) -> &BucketInfo {
5718        &self.bucket
5719    }
5720}
5721
5722#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
5723pub struct BucketInfo {
5724    #[serde(default)]
5725    #[serde(rename = "Name")]
5726    pub(crate) name: String,
5727    #[serde(default)]
5728    #[serde(rename = "Owner")]
5729    pub(crate) owner: Owner,
5730    #[serde(default)]
5731    #[serde(rename = "CreationDate")]
5732    pub(crate) creation_date_string: Option<String>,
5733    #[serde(skip)]
5734    pub(crate) creation_date: Option<DateTime<Utc>>,
5735    #[serde(default)]
5736    #[serde(rename = "StorageClass")]
5737    pub(crate) storage_class: Option<StorageClassType>,
5738    #[serde(default)]
5739    #[serde(rename = "ProjectName")]
5740    pub(crate) project_name: String,
5741    #[serde(default)]
5742    #[serde(rename = "Type")]
5743    pub(crate) bucket_type: Option<BucketType>,
5744    #[serde(default)]
5745    #[serde(rename = "Location")]
5746    pub(crate) location: String,
5747    #[serde(default)]
5748    #[serde(rename = "AzRedundancy")]
5749    pub(crate) az_redundancy: Option<AzRedundancyType>,
5750    #[serde(default)]
5751    #[serde(rename = "ExtranetEndpoint")]
5752    pub(crate) extranet_endpoint: String,
5753    #[serde(default)]
5754    #[serde(rename = "IntranetEndpoint")]
5755    pub(crate) intranet_endpoint: String,
5756    #[serde(default)]
5757    #[serde(rename = "ExtranetS3Endpoint")]
5758    pub(crate) extranet_s3_endpoint: String,
5759    #[serde(default)]
5760    #[serde(rename = "IntranetS3Endpoint")]
5761    pub(crate) intranet_s3_endpoint: String,
5762    #[serde(default)]
5763    #[serde(rename = "Versioning")]
5764    pub(crate) versioning: Option<VersioningStatusType>,
5765    #[serde(default)]
5766    #[serde(rename = "CrossRegionReplication")]
5767    pub(crate) cross_region_replication: Option<StatusType>,
5768    #[serde(default)]
5769    #[serde(rename = "TransferAcceleration")]
5770    pub(crate) transfer_acceleration: Option<StatusType>,
5771    #[serde(default)]
5772    #[serde(rename = "AccessMonitor")]
5773    pub(crate) access_monitor: Option<StatusType>,
5774    #[serde(default)]
5775    #[serde(rename = "ServerSideEncryptionConfiguration")]
5776    pub(crate) server_side_encryption_configuration: ServerSideEncryptionConfiguration,
5777}
5778
5779impl BucketInfo {
5780    pub fn name(&self) -> &str {
5781        &self.name
5782    }
5783
5784    pub fn owner(&self) -> &Owner {
5785        &self.owner
5786    }
5787
5788    pub fn creation_date(&self) -> Option<DateTime<Utc>> {
5789        self.creation_date
5790    }
5791
5792    pub fn storage_class(&self) -> &Option<StorageClassType> {
5793        &self.storage_class
5794    }
5795
5796    pub fn project_name(&self) -> &str {
5797        &self.project_name
5798    }
5799
5800    pub fn bucket_type(&self) -> &Option<BucketType> {
5801        &self.bucket_type
5802    }
5803
5804    pub fn location(&self) -> &str {
5805        &self.location
5806    }
5807
5808    pub fn az_redundancy(&self) -> &Option<AzRedundancyType> {
5809        &self.az_redundancy
5810    }
5811
5812    pub fn extranet_endpoint(&self) -> &str {
5813        &self.extranet_endpoint
5814    }
5815
5816    pub fn intranet_endpoint(&self) -> &str {
5817        &self.intranet_endpoint
5818    }
5819
5820    pub fn extranet_s3_endpoint(&self) -> &str {
5821        &self.extranet_s3_endpoint
5822    }
5823
5824    pub fn intranet_s3_endpoint(&self) -> &str {
5825        &self.intranet_s3_endpoint
5826    }
5827
5828    pub fn versioning(&self) -> &Option<VersioningStatusType> {
5829        &self.versioning
5830    }
5831
5832    pub fn cross_region_replication(&self) -> &Option<StatusType> {
5833        &self.cross_region_replication
5834    }
5835
5836    pub fn transfer_acceleration(&self) -> &Option<StatusType> {
5837        &self.transfer_acceleration
5838    }
5839
5840    pub fn access_monitor(&self) -> &Option<StatusType> {
5841        &self.access_monitor
5842    }
5843
5844    pub fn server_side_encryption_configuration(&self) -> &ServerSideEncryptionConfiguration {
5845        &self.server_side_encryption_configuration
5846    }
5847}
5848
5849#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
5850pub struct ServerSideEncryptionConfiguration {
5851    #[serde(default)]
5852    #[serde(rename = "Rule")]
5853    pub(crate) rule: BucketEncryptionRule,
5854}
5855
5856impl ServerSideEncryptionConfiguration {
5857    pub fn rule(&self) -> &BucketEncryptionRule {
5858        &self.rule
5859    }
5860}
5861
5862#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
5863pub struct PutBucketAccessMonitorInput {
5864    #[serde(skip)]
5865    pub(crate) generic_input: GenericInput,
5866    #[serde(skip)]
5867    pub(crate) bucket: String,
5868    #[serde(rename = "Status")]
5869    pub(crate) status: StatusType,
5870}
5871
5872impl PutBucketAccessMonitorInput {
5873    pub fn new(bucket: impl Into<String>, status: impl Into<StatusType>) -> PutBucketAccessMonitorInput {
5874        Self {
5875            generic_input: Default::default(),
5876            bucket: bucket.into(),
5877            status: status.into(),
5878        }
5879    }
5880
5881    pub fn bucket(&self) -> &str {
5882        &self.bucket
5883    }
5884
5885    pub fn status(&self) -> &StatusType {
5886        &self.status
5887    }
5888
5889    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
5890        self.bucket = bucket.into();
5891    }
5892
5893    pub fn set_status(&mut self, status: impl Into<StatusType>) {
5894        self.status = status.into();
5895    }
5896}
5897
5898impl InputDescriptor for PutBucketAccessMonitorInput {
5899    fn operation(&self) -> &str {
5900        "PutBucketAccessMonitor"
5901    }
5902
5903    fn bucket(&self) -> Result<&str, TosError> {
5904        Ok(&self.bucket)
5905    }
5906}
5907
5908impl<B> InputTranslator<B> for PutBucketAccessMonitorInput
5909where
5910    B: BuildBufferReader,
5911{
5912    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5913        match serde_json::to_string(self) {
5914            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
5915            Ok(json) => {
5916                let mut request = self.trans_bucket()?;
5917                request.method = HttpMethodPut;
5918                let mut query = HashMap::with_capacity(1);
5919                query.insert("accessmonitor", "".to_string());
5920                request.query = Some(query);
5921                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
5922                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
5923                request.body = Some(body);
5924                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
5925                Ok(request)
5926            }
5927        }
5928    }
5929}
5930
5931#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
5932pub struct PutBucketAccessMonitorOutput {
5933    pub(crate) request_info: RequestInfo,
5934}
5935
5936#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
5937pub struct GetBucketAccessMonitorInput {
5938    pub(crate) generic_input: GenericInput,
5939    pub(crate) bucket: String,
5940}
5941
5942impl InputDescriptor for GetBucketAccessMonitorInput {
5943    fn operation(&self) -> &str {
5944        "GetBucketAccessMonitor"
5945    }
5946
5947    fn bucket(&self) -> Result<&str, TosError> {
5948        Ok(&self.bucket)
5949    }
5950}
5951
5952impl<B> InputTranslator<B> for GetBucketAccessMonitorInput {
5953    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
5954        let mut request = self.trans_bucket()?;
5955        request.query = Some(HashMap::from([("accessmonitor", "".to_string())]));
5956        request.method = HttpMethodGet;
5957        Ok(request)
5958    }
5959}
5960
5961#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
5962pub struct GetBucketAccessMonitorOutput {
5963    #[serde(skip)]
5964    pub(crate) request_info: RequestInfo,
5965    #[serde(rename = "Status")]
5966    #[serde(default)]
5967    pub(crate) status: StatusType,
5968}
5969
5970impl GetBucketAccessMonitorOutput {
5971    pub fn status(&self) -> &StatusType {
5972        &self.status
5973    }
5974}
5975#[derive(Debug, Clone, PartialEq, Default, Serialize, GenericInput)]
5976pub struct PutBucketTrashInput {
5977    #[serde(skip)]
5978    pub(crate) generic_input: GenericInput,
5979    #[serde(skip)]
5980    pub(crate) bucket: String,
5981    #[serde(rename = "Trash")]
5982    pub(crate) trash: BucketTrash,
5983}
5984
5985impl PutBucketTrashInput {
5986    pub fn new(bucket: impl Into<String>, trash: impl Into<BucketTrash>) -> PutBucketTrashInput {
5987        Self {
5988            generic_input: Default::default(),
5989            bucket: bucket.into(),
5990            trash: trash.into(),
5991        }
5992    }
5993
5994    pub fn bucket(&self) -> &str {
5995        &self.bucket
5996    }
5997
5998    pub fn trash(&self) -> &BucketTrash {
5999        &self.trash
6000    }
6001
6002    pub fn set_bucket(&mut self, bucket: impl Into<String>) {
6003        self.bucket = bucket.into();
6004    }
6005
6006    pub fn set_trash(&mut self, trash: impl Into<BucketTrash>) {
6007        self.trash = trash.into();
6008    }
6009}
6010
6011impl InputDescriptor for PutBucketTrashInput {
6012    fn operation(&self) -> &str {
6013        "PutBucketTrash"
6014    }
6015
6016    fn bucket(&self) -> Result<&str, TosError> {
6017        Ok(&self.bucket)
6018    }
6019}
6020
6021impl<B> InputTranslator<B> for PutBucketTrashInput
6022where
6023    B: BuildBufferReader,
6024{
6025    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
6026        match serde_json::to_string(self) {
6027            Err(e) => Err(TosError::client_error_with_cause("trans json error", GenericError::JsonError(e.to_string()))),
6028            Ok(json) => {
6029                let mut request = self.trans_bucket()?;
6030                request.method = HttpMethodPut;
6031                let mut query = HashMap::with_capacity(1);
6032                query.insert("trash", "".to_string());
6033                request.query = Some(query);
6034                request.header.insert(HEADER_CONTENT_MD5, base64_md5(&json));
6035                let (body, len) = B::new(Bytes::from(json.into_bytes()))?;
6036                request.body = Some(body);
6037                request.header.insert(HEADER_CONTENT_LENGTH, len.to_string());
6038                Ok(request)
6039            }
6040        }
6041    }
6042}
6043
6044#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
6045pub struct BucketTrash {
6046    #[serde(rename = "TrashPath")]
6047    #[serde(skip_serializing_if = "String::is_empty")]
6048    #[serde(default)]
6049    pub(crate) trash_path: String,
6050    #[serde(rename = "CleanInterval")]
6051    #[serde(default)]
6052    pub(crate) clean_interval: isize,
6053    #[serde(rename = "Status")]
6054    #[serde(default)]
6055    pub(crate) status: StatusType,
6056    #[serde(rename = "PrefixMatchRules")]
6057    #[serde(skip_serializing_if = "Vec::is_empty")]
6058    #[serde(default)]
6059    pub(crate) prefix_match_rules: Vec<BucketTrashPrefixRule>,
6060}
6061
6062impl BucketTrash {
6063    pub fn new(trash_path: impl Into<String>, clean_interval: isize, status: impl Into<StatusType>) -> Self {
6064        Self {
6065            trash_path: trash_path.into(),
6066            clean_interval,
6067            status: status.into(),
6068            prefix_match_rules: vec![],
6069        }
6070    }
6071
6072    pub fn trash_path(&self) -> &str {
6073        &self.trash_path
6074    }
6075
6076    pub fn clean_interval(&self) -> isize {
6077        self.clean_interval
6078    }
6079
6080    pub fn status(&self) -> &StatusType {
6081        &self.status
6082    }
6083
6084    pub fn prefix_match_rules(&self) -> &Vec<BucketTrashPrefixRule> {
6085        &self.prefix_match_rules
6086    }
6087
6088    pub fn set_trash_path(&mut self, trash_path: impl Into<String>) {
6089        self.trash_path = trash_path.into();
6090    }
6091
6092    pub fn set_clean_interval(&mut self, clean_interval: isize) {
6093        self.clean_interval = clean_interval;
6094    }
6095
6096    pub fn set_status(&mut self, status: impl Into<StatusType>) {
6097        self.status = status.into();
6098    }
6099
6100    pub fn set_prefix_match_rules(&mut self, prefix_match_rules: impl Into<Vec<BucketTrashPrefixRule>>) {
6101        self.prefix_match_rules = prefix_match_rules.into();
6102    }
6103}
6104
6105#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
6106pub struct BucketTrashPrefixRule {
6107    #[serde(rename = "PrefixList")]
6108    #[serde(skip_serializing_if = "Vec::is_empty")]
6109    #[serde(default)]
6110    pub(crate) prefix_list: Vec<String>,
6111    #[serde(rename = "TrashPath")]
6112    #[serde(skip_serializing_if = "String::is_empty")]
6113    #[serde(default)]
6114    pub(crate) trash_path: String,
6115    #[serde(rename = "CleanInterval")]
6116    #[serde(default)]
6117    pub(crate) clean_interval: isize,
6118}
6119
6120impl BucketTrashPrefixRule {
6121    pub fn new(trash_path: impl Into<String>, clean_interval: isize, prefix_list: impl Into<Vec<String>>) -> Self {
6122        Self {
6123            prefix_list: prefix_list.into(),
6124            trash_path: trash_path.into(),
6125            clean_interval,
6126        }
6127    }
6128
6129    pub fn prefix_list(&self) -> &Vec<String> {
6130        &self.prefix_list
6131    }
6132
6133    pub fn trash_path(&self) -> &str {
6134        &self.trash_path
6135    }
6136
6137    pub fn clean_interval(&self) -> isize {
6138        self.clean_interval
6139    }
6140
6141    pub fn set_prefix_list(&mut self, prefix_list: impl Into<Vec<String>>) {
6142        self.prefix_list = prefix_list.into();
6143    }
6144
6145    pub fn set_trash_path(&mut self, trash_path: impl Into<String>) {
6146        self.trash_path = trash_path.into();
6147    }
6148
6149    pub fn set_clean_interval(&mut self, clean_interval: isize) {
6150        self.clean_interval = clean_interval;
6151    }
6152}
6153
6154#[derive(Debug, Clone, PartialEq, Default, RequestInfo)]
6155pub struct PutBucketTrashOutput {
6156    pub(crate) request_info: RequestInfo,
6157}
6158#[derive(Debug, Clone, PartialEq, Default, BucketSetter, GenericInput)]
6159pub struct GetBucketTrashInput {
6160    pub(crate) generic_input: GenericInput,
6161    pub(crate) bucket: String,
6162}
6163
6164impl InputDescriptor for GetBucketTrashInput {
6165    fn operation(&self) -> &str {
6166        "GetBucketTrash"
6167    }
6168
6169    fn bucket(&self) -> Result<&str, TosError> {
6170        Ok(&self.bucket)
6171    }
6172}
6173
6174impl<B> InputTranslator<B> for GetBucketTrashInput {
6175    fn trans(&self, _: Arc<ConfigHolder>) -> Result<HttpRequest<B>, TosError> {
6176        let mut request = self.trans_bucket()?;
6177        request.query = Some(HashMap::from([("trash", "".to_string())]));
6178        request.method = HttpMethodGet;
6179        Ok(request)
6180    }
6181}
6182
6183
6184#[derive(Debug, Clone, PartialEq, Default, RequestInfo, Deserialize)]
6185pub struct GetBucketTrashOutput {
6186    #[serde(skip)]
6187    pub(crate) request_info: RequestInfo,
6188    #[serde(rename = "Trash")]
6189    pub(crate) trash: BucketTrash,
6190}
6191
6192
6193impl GetBucketTrashOutput {
6194    pub fn trash(&self) -> &BucketTrash {
6195        &self.trash
6196    }
6197}