rustfs_rsc/datatype/
mod.rs

1//! Data types
2
3mod select_object_content;
4
5pub use select_object_content::*;
6
7use serde::{Deserialize, Serialize};
8
9use crate::time::UtcTime;
10
11#[derive(Clone, Debug, PartialEq)]
12pub struct Region(pub String);
13
14trait XmlSelf {}
15
16macro_rules! impl_xmlself {
17    ($($name:tt )*) => {
18        $(
19            impl XmlSelf for $name{}
20        )*
21    };
22}
23
24impl_xmlself!(
25    CommonPrefix
26    LegalHold
27    VersioningConfiguration
28    Retention
29    CompleteMultipartUpload
30    CompleteMultipartUploadResult
31    InitiateMultipartUploadResult
32    ListMultipartUploadsResult
33    CopyPartResult
34    ListPartsResult
35    ListAllMyBucketsResult
36    ListBucketResult
37    ListVersionsResult
38    ServerSideEncryptionConfiguration
39    CORSConfiguration
40    LocationConstraint
41    PublicAccessBlockConfiguration
42    AccessControlPolicy
43);
44
45pub trait ToXml {
46    /// try get xml string
47    fn to_xml(&self) -> crate::error::Result<String>;
48}
49
50impl<T: Serialize + XmlSelf> ToXml for T {
51    fn to_xml(&self) -> crate::error::Result<String> {
52        crate::xml::ser::to_string(&self).map_err(Into::into)
53    }
54}
55
56pub trait FromXml: Sized {
57    /// try from xml string
58    fn from_xml(v: String) -> crate::error::Result<Self>;
59}
60
61impl<'de, T: Deserialize<'de> + XmlSelf> FromXml for T {
62    fn from_xml(v: String) -> crate::error::Result<Self> {
63        crate::xml::de::from_string(v).map_err(Into::into)
64    }
65}
66
67impl Region {
68    pub fn from<S>(region: S) -> Self
69    where
70        S: Into<String>,
71    {
72        return Self(region.into());
73    }
74
75    pub fn as_str(&self) -> &str {
76        self.0.as_str()
77    }
78}
79
80#[derive(Debug, Clone, Deserialize, Serialize)]
81#[serde(rename_all = "PascalCase")]
82pub struct AccessControlList {
83    pub grant: Vec<Grant>,
84}
85
86/// Contains the elements that set the ACL permissions for an object per grantee.
87#[derive(Debug, Clone, Deserialize, Serialize)]
88#[serde(rename_all = "PascalCase")]
89pub struct AccessControlPolicy {
90    pub access_control_list: AccessControlList,
91    pub owner: Option<Owner>,
92}
93
94/// In terms of implementation, a Bucket is a resource.
95/// An Amazon S3 bucket name is globally unique, and the namespace is shared by all AWS accounts.
96#[derive(Debug, Clone, Deserialize, Serialize)]
97#[serde(rename_all = "PascalCase")]
98pub struct Bucket {
99    /// The name of the bucket.
100    pub name: String,
101    /// Date the bucket was created. This date can change when making changes to your bucket, such as editing its bucket policy.
102    pub creation_date: String,
103}
104
105#[derive(Clone, Debug, Default, Deserialize, Serialize)]
106#[serde(rename_all = "PascalCase")]
107pub struct Buckets {
108    #[serde(default)]
109    pub bucket: Vec<Bucket>,
110}
111
112/// Container for all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter.
113#[derive(Debug, Clone, Deserialize, Serialize)]
114#[serde(rename_all = "PascalCase")]
115pub struct CommonPrefix {
116    pub prefix: String,
117}
118
119/// The container for the completed multipart upload details.
120#[derive(Debug, Clone, Deserialize, Serialize)]
121#[serde(rename_all = "PascalCase")]
122pub struct CompleteMultipartUpload {
123    #[serde(default, rename = "Part")]
124    pub parts: Vec<Part>,
125}
126
127#[derive(Debug, Clone, Deserialize, Serialize)]
128#[serde(rename_all = "PascalCase")]
129pub struct CompleteMultipartUploadResult {
130    pub bucket: String,
131    pub key: String,
132    pub e_tag: String,
133    pub location: String,
134}
135
136#[derive(Debug, Clone, Deserialize, Serialize)]
137#[serde(rename_all = "PascalCase")]
138pub struct CopyPartResult {
139    pub e_tag: String,
140}
141
142/// Describes the cross-origin access configuration for objects in an Amazon S3 bucket.
143#[derive(Debug, Clone, Deserialize, Serialize)]
144#[serde(rename_all = "PascalCase")]
145pub struct CORSConfiguration {
146    #[serde(rename = "CORSRule")]
147    pub rules: Vec<CORSRule>,
148}
149
150/// Specifies a cross-origin access rule for an Amazon S3 bucket.
151#[derive(Debug, Clone, Deserialize, Serialize, Default)]
152#[serde(rename_all = "PascalCase")]
153pub struct CORSRule {
154    /// **Required**. Valid values are `GET`, `PUT`, `HEAD`, `POST`, and `DELETE`.
155    #[serde(rename = "AllowedMethod", default)]
156    pub allowed_methods: Vec<String>,
157    /// **Required**
158    #[serde(rename = "AllowedOrigin", default)]
159    pub allowed_origins: Vec<String>,
160    #[serde(rename = "AllowedHeader", default)]
161    pub allowed_headers: Vec<String>,
162    #[serde(rename = "ExposeHeader", default)]
163    pub expose_headers: Vec<String>,
164    #[serde(rename = "ID")]
165    pub id: Option<String>,
166    pub max_age_seconds: usize,
167}
168
169/// The container element for specifying the default Object Lock retention settings
170/// for new objects placed in the specified bucket.
171///
172/// **Note**
173/// - The DefaultRetention settings require **both** a `mode` and a `period`.
174/// - The DefaultRetention period can be either Days or Years but you must select one.
175///   You cannot specify Days and Years at the same time.
176#[derive(Debug, Clone, Deserialize, Serialize, Default)]
177#[serde(rename_all = "PascalCase")]
178pub struct DefaultRetention {
179    pub days: Option<usize>,
180    pub mode: RetentionMode,
181    pub years: Option<usize>,
182}
183
184/// Information about the delete marker.
185#[derive(Clone, Debug, Deserialize, Serialize)]
186#[serde(rename_all = "PascalCase")]
187pub struct DeleteMarkerEntry {
188    /// The object key.
189    pub key: String,
190    /// Date and time when the object was last modified.
191    pub last_modified: String,
192    /// Specifies whether the object is (true) or is not (false) the latest version of an object.
193    pub is_latest: bool,
194    /// The entity tag is an MD5 hash of that version of the object.
195    pub owner: Option<Owner>,
196    /// Version ID of an object.
197    pub version_id: Option<String>,
198}
199
200/// Container for grant information.
201#[derive(Debug, Clone, Deserialize, Serialize)]
202#[serde(rename_all = "PascalCase")]
203pub struct Grant {
204    pub grantee: Option<Grantee>,
205    pub permission: Option<Permission>,
206}
207
208/// Container for the person being granted permissions.
209#[derive(Debug, Clone, Deserialize, Serialize)]
210#[serde(rename_all = "PascalCase")]
211pub struct Grantee {
212    pub display_name: Option<String>,
213    pub email_address: Option<String>,
214    pub id: Option<String>,
215    #[serde(alias = "Type", alias = "type")]
216    pub r#type: GranteeType,
217    pub uri: Option<String>,
218}
219
220#[derive(Debug, Clone, Deserialize, Serialize)]
221#[serde(rename_all = "PascalCase")]
222pub(crate) struct InitiateMultipartUploadResult {
223    pub bucket: String,
224    pub key: String,
225    pub upload_id: String,
226}
227
228/// Container element that identifies who initiated the multipart upload.
229#[derive(Clone, Debug, Deserialize, Serialize)]
230#[serde(rename_all = "PascalCase")]
231pub struct Initiator {
232    pub display_name: String,
233    #[serde(rename = "ID")]
234    pub id: String,
235}
236
237/// A legal hold configuration for an object.
238#[derive(Debug, Clone, Deserialize, Serialize)]
239#[serde(rename_all = "PascalCase")]
240pub struct LegalHold {
241    pub status: LegalHoldStatus,
242}
243
244#[derive(Debug, Clone, Deserialize, Serialize)]
245#[serde(rename_all = "PascalCase")]
246pub struct ListAllMyBucketsResult {
247    #[serde(default)]
248    pub buckets: Buckets,
249    pub owner: Owner,
250}
251
252#[derive(Debug, Clone, Deserialize, Serialize)]
253#[serde(rename_all = "PascalCase")]
254pub struct ListBucketResult {
255    pub name: String,
256    pub prefix: String,
257    pub key_count: usize,
258    pub max_keys: usize,
259    #[serde(default)]
260    pub delimiter: String,
261    pub is_truncated: bool,
262    pub start_after: Option<String>,
263    #[serde(default)]
264    pub contents: Vec<Object>,
265    #[serde(default)]
266    pub common_prefixes: Vec<CommonPrefix>,
267    #[serde(default)]
268    pub next_continuation_token: String,
269    #[serde(default)]
270    pub continuation_token: String,
271}
272
273#[derive(Debug, Clone, Deserialize, Serialize)]
274#[serde(rename_all = "PascalCase")]
275pub struct ListMultipartUploadsResult {
276    pub bucket: String,
277    pub key_marker: String,
278    pub upload_id_marker: String,
279    pub next_key_marker: String,
280    pub prefix: String,
281    pub delimiter: String,
282    pub next_upload_id_marker: String,
283    pub max_uploads: usize,
284    pub is_truncated: bool,
285    #[serde(default, rename = "Upload")]
286    pub uploads: Vec<MultipartUpload>,
287    #[serde(default)]
288    pub common_prefixes: Vec<CommonPrefix>,
289    pub encoding_type: Option<String>,
290}
291
292#[derive(Debug, Clone, Deserialize, Serialize)]
293#[serde(rename_all = "PascalCase")]
294pub struct ListPartsResult {
295    pub bucket: String,
296    pub key: String,
297    pub upload_id: String,
298    pub part_number_marker: usize,
299    pub max_parts: usize,
300    pub next_part_number_marker: usize,
301    pub is_truncated: bool,
302    #[serde(default, rename = "Part")]
303    pub parts: Vec<Part>,
304    pub storage_class: String,
305    pub checksum_algorithm: String,
306    pub initiator: Initiator,
307    pub owner: Owner,
308}
309
310#[derive(Debug, Clone, Deserialize, Serialize)]
311#[serde(rename_all = "PascalCase")]
312pub struct ListVersionsResult {
313    /// A flag that indicates whether Amazon S3 returned all of the results
314    /// that satisfied the search criteria. If your results were truncated,
315    /// you can make a follow-up paginated request by using the `NextKeyMarker`
316    /// and `NextVersionIdMarker` response parameters as a starting place in
317    /// another request to return the rest of the results.
318    pub is_truncated: bool,
319    /// All of the keys rolled up into a common prefix count as a single return when calculating the number of returns.
320    #[serde(default)]
321    pub common_prefixes: Vec<CommonPrefix>,
322    #[serde(default, rename = "Version")]
323    pub versions: Vec<ObjectVersion>,
324    /// Container for an object that is a delete marker.
325    #[serde(default, rename = "DeleteMarker")]
326    pub delete_markers: Vec<DeleteMarkerEntry>,
327    pub name: String,
328    pub prefix: String,
329    pub max_keys: usize,
330    #[serde(default)]
331    pub delimiter: String,
332    pub encoding_type: Option<String>,
333    /// Marks the last key returned in a truncated response.
334    #[serde(default)]
335    pub key_marker: String,
336    /// When the number of responses exceeds the value of `MaxKeys`,
337    /// `NextKeyMarker` specifies the first key not returned that
338    /// satisfies the search criteria. Use this value for the `key-marker`
339    /// request parameter in a subsequent request.
340    #[serde(default)]
341    pub next_key_marker: String,
342    /// Marks the last version of the key returned in a truncated response.
343    #[serde(default)]
344    pub version_id_marker: String,
345    /// When the number of responses exceeds the value of `MaxKeys`,
346    /// `NextVersionIdMarker` specifies the first object version not
347    /// returned that satisfies the search criteria. Use this value
348    /// for the `version-id-marker` request parameter in a subsequent request.
349    #[serde(default)]
350    pub next_version_id_marker: String,
351}
352
353#[derive(Clone, Debug, Deserialize, Serialize)]
354#[serde(rename_all = "PascalCase")]
355pub struct LocationConstraint {
356    pub location_constraint: String,
357}
358
359#[derive(Clone, Debug, Deserialize, Serialize)]
360#[serde(rename_all = "PascalCase")]
361pub struct MultipartUpload {
362    pub checksum_algorithm: String,
363    pub upload_id: String,
364    pub storage_class: String,
365    pub key: String,
366    pub initiated: String,
367}
368
369#[derive(Clone, Debug, Deserialize, Serialize)]
370#[serde(rename_all = "PascalCase")]
371pub struct Object {
372    pub key: String,
373    pub last_modified: String,
374    pub e_tag: String,
375    pub size: u64,
376    pub storage_class: String,
377    pub owner: Option<Owner>,
378    pub checksum_algorithm: Option<String>,
379}
380
381/// The container element for an Object Lock rule.
382#[derive(Debug, Clone, Deserialize, Serialize, Default)]
383#[serde(rename_all = "PascalCase")]
384pub struct ObjectLockRule {
385    pub default_retention: DefaultRetention,
386}
387
388/// Object representation of
389/// - request XML of `put_object_lock_configuration` API
390/// - response XML of `get_object_lock_configuration` API.
391#[derive(Debug, Clone, Deserialize, Serialize)]
392#[serde(rename_all = "PascalCase")]
393pub struct ObjectLockConfiguration {
394    /// Indicates whether this bucket has an Object Lock configuration enabled.
395    /// Enable ObjectLockEnabled when you apply ObjectLockConfiguration to a bucket.
396    ///
397    /// Valid Values: `Enabled`
398    /// Required: No
399    pub object_lock_enabled: String,
400    pub rule: Option<ObjectLockRule>,
401}
402
403#[derive(Clone, Debug, Deserialize, Serialize)]
404#[serde(rename_all = "PascalCase")]
405pub struct ObjectVersion {
406    /// The object key.
407    pub key: String,
408    /// Date and time when the object was last modified.
409    pub last_modified: String,
410    /// Specifies whether the object is (true) or is not (false) the latest version of an object.
411    pub is_latest: bool,
412    /// The entity tag is an MD5 hash of that version of the object.
413    pub e_tag: String,
414    pub size: u64,
415    pub storage_class: String,
416    pub owner: Option<Owner>,
417    /// Version ID of an object.
418    pub version_id: Option<String>,
419}
420
421#[derive(Debug, Clone, Deserialize, Serialize)]
422#[serde(rename_all = "PascalCase")]
423pub struct Owner {
424    pub display_name: String,
425    #[serde(rename = "ID")]
426    pub id: String,
427}
428
429#[derive(Debug, Clone, Deserialize, Serialize)]
430#[serde(rename_all = "PascalCase")]
431pub struct Part {
432    pub e_tag: String,
433    pub part_number: usize,
434}
435
436/// This data type contains information about progress of an operation.
437#[derive(Debug, Clone, Deserialize, Serialize)]
438#[serde(rename_all = "PascalCase")]
439pub struct Progress {
440    pub bytes_processed: u64,
441    pub bytes_returned: u64,
442    pub bytes_scanned: u64,
443}
444
445/// PublicAccessBlockConfiguration parameters
446#[derive(Debug, Clone, Deserialize, Serialize)]
447#[serde(rename_all = "PascalCase")]
448pub struct PublicAccessBlockConfiguration {
449    pub block_public_acls: bool,
450    pub block_public_policy: bool,
451    pub ignore_public_acls: bool,
452    pub restrict_public_buckets: bool,
453}
454
455/// A container for replication rules. You can add up to 1,000 rules. The maximum size of a replication configuration is 2 MB.
456#[derive(Debug, Clone, Deserialize, Serialize)]
457#[serde(rename_all = "PascalCase")]
458pub struct ReplicationConfiguration {
459    pub role: String,
460    #[serde(rename = "Rule", default)]
461    pub rules: Vec<ReplicationRule>,
462}
463
464/// Specifies which Amazon S3 objects to replicate and where to store the replicas.
465#[derive(Debug, Clone, Deserialize, Serialize)]
466#[serde(rename_all = "PascalCase")]
467pub struct ReplicationRule {
468    pub role: String,
469    pub id: Option<String>,
470    pub priority: Option<i64>,
471}
472
473/// Object representation of request XML of `put_object_retention` API
474/// and response XML of `get_object_retention` API.
475#[derive(Debug, Clone, Deserialize, Serialize)]
476#[serde(rename_all = "PascalCase")]
477pub struct Retention {
478    /// Valid Values: GOVERNANCE | COMPLIANCE
479    pub mode: RetentionMode,
480    /// The date on which this Object Lock Retention will expire.
481    #[serde(deserialize_with = "crate::time::deserialize_with_str")]
482    pub retain_until_date: UtcTime,
483}
484
485/// Describes the default server-side encryption to apply to new objects in the bucket.
486#[derive(Debug, Clone, Deserialize, Serialize)]
487#[serde(rename_all = "PascalCase")]
488pub struct ServerSideEncryptionByDefault {
489    #[serde(rename = "SSEAlgorithm")]
490    pub ssealgorithm: String,
491    #[serde(rename = " KMSMasterKeyID")]
492    pub kmsmaster_key_id: Option<String>,
493}
494
495/// Root level tag for the ServerSideEncryptionConfiguration parameters
496#[derive(Debug, Clone, Deserialize, Serialize)]
497#[serde(rename_all = "PascalCase")]
498pub struct ServerSideEncryptionConfiguration {
499    #[serde(rename = "Rule")]
500    pub rules: Vec<ServerSideEncryptionRule>,
501}
502
503/// Specifies the default server-side encryption configuration.
504#[derive(Debug, Clone, Deserialize, Serialize)]
505#[serde(rename_all = "PascalCase")]
506pub struct ServerSideEncryptionRule {
507    pub apply_server_side_encryption_by_default: ServerSideEncryptionByDefault,
508    #[serde(default)]
509    pub bucket_key_enabled: bool,
510}
511
512/// Container for the stats details.
513#[derive(Debug, Clone, Deserialize, Serialize)]
514#[serde(rename_all = "PascalCase")]
515pub struct Stats {
516    pub bytes_processed: u64,
517    pub bytes_returned: u64,
518    pub bytes_scanned: u64,
519}
520
521/// A container of a key value name pair.
522#[derive(Debug, Clone, Deserialize, Serialize)]
523#[serde(rename_all = "PascalCase")]
524pub struct Tag {
525    pub key: String,
526    pub value: String,
527}
528
529/// A collection for a set of tags
530#[derive(Debug, Clone, Deserialize, Serialize)]
531#[serde(rename_all = "PascalCase")]
532pub struct TagSet {
533    #[serde(rename = "Tag", default)]
534    pub tags: Vec<Tag>,
535}
536
537/// Container for TagSet elements.
538#[derive(Debug, Clone, Deserialize, Serialize)]
539#[serde(rename_all = "PascalCase")]
540pub struct Tagging {
541    pub tag_set: TagSet,
542}
543
544/// Describes the versioning state of an Amazon S3 bucket.
545#[derive(Debug, Clone, Deserialize, Serialize)]
546#[serde(rename_all = "PascalCase")]
547pub struct VersioningConfiguration {
548    /// Specifies whether MFA delete is enabled in the bucket versioning configuration.
549    /// This element is only returned if the bucket has been configured with MFA delete.
550    /// If the bucket has never been so configured, this element is not returned.
551    ///
552    /// Valid Values: Enabled | Disabled
553    pub mfa_delete: Option<MFADelete>,
554
555    /// The versioning state of the bucket.
556    ///
557    /// Valid Values: Enabled | Suspended
558    pub status: Option<VersioningStatus>,
559}
560
561//////////////////  Enum Type
562
563#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
564pub enum ChecksumAlgorithm {
565    CRC32,
566    CRC32C,
567    SHA1,
568    SHA256,
569}
570
571/// Type of grantee
572#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
573pub enum GranteeType {
574    CanonicalUser,
575    AmazonCustomerByEmail,
576    Group,
577}
578
579/// Specifies whether MFA delete is enabled in the bucket versioning configuration.
580/// This element is only returned if the bucket has been configured with MFA delete.
581/// If the bucket has never been so configured, this element is not returned.
582#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
583pub enum MFADelete {
584    Enabled,
585    Disabled,
586}
587
588#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
589pub enum LegalHoldStatus {
590    ON,
591    OFF,
592}
593
594/// Retention mode, Valid Values: `GOVERNANCE | COMPLIANCE`
595#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
596pub enum RetentionMode {
597    #[default]
598    GOVERNANCE,
599    COMPLIANCE,
600}
601
602/// The permission given to the grantee.. Valid Values: `FULL_CONTROL | WRITE | WRITE_ACP | READ | READ_ACP`
603#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
604pub enum Permission {
605    FULL_CONTROL,
606    WRITE,
607    WRITE_ACP,
608    READ,
609    READ_ACP,
610}
611
612/// Valid Values: `Enabled | Disabled`
613#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
614pub enum Status {
615    Enabled,
616    Disabled,
617}
618
619/// The versioning state of the bucket.
620#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
621pub enum VersioningStatus {
622    Enabled,
623    Suspended,
624}