minio-rsc 0.2.5

rust for minio, api is compliant with the Amazon S3 protocol.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
//! Data types

mod select_object_content;

pub use select_object_content::*;

use serde::{Deserialize, Serialize};

use crate::time::UtcTime;

#[derive(Clone, Debug, PartialEq)]
pub struct Region(pub String);

trait XmlSelf {}

macro_rules! impl_xmlself {
    ($($name:tt )*) => {
        $(
            impl XmlSelf for $name{}
        )*
    };
}

impl_xmlself!(
    CommonPrefix
    LegalHold
    VersioningConfiguration
    Retention
    CompleteMultipartUpload
    CompleteMultipartUploadResult
    InitiateMultipartUploadResult
    ListMultipartUploadsResult
    CopyPartResult
    ListPartsResult
    ListAllMyBucketsResult
    ListBucketResult
    ListVersionsResult
    ServerSideEncryptionConfiguration
    CORSConfiguration
    LocationConstraint
    PublicAccessBlockConfiguration
    AccessControlPolicy
);

pub trait ToXml {
    /// try get xml string
    fn to_xml(&self) -> crate::error::Result<String>;
}

impl<T: Serialize + XmlSelf> ToXml for T {
    fn to_xml(&self) -> crate::error::Result<String> {
        crate::xml::ser::to_string(&self).map_err(Into::into)
    }
}

pub trait FromXml: Sized {
    /// try from xml string
    fn from_xml(v: String) -> crate::error::Result<Self>;
}

impl<'de, T: Deserialize<'de> + XmlSelf> FromXml for T {
    fn from_xml(v: String) -> crate::error::Result<Self> {
        crate::xml::de::from_string(v).map_err(Into::into)
    }
}

impl Region {
    pub fn from<S>(region: S) -> Self
    where
        S: Into<String>,
    {
        return Self(region.into());
    }

    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct AccessControlList {
    pub grant: Vec<Grant>,
}

/// Contains the elements that set the ACL permissions for an object per grantee.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct AccessControlPolicy {
    pub access_control_list: AccessControlList,
    pub owner: Option<Owner>,
}

/// In terms of implementation, a Bucket is a resource.
/// An Amazon S3 bucket name is globally unique, and the namespace is shared by all AWS accounts.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Bucket {
    /// The name of the bucket.
    pub name: String,
    /// Date the bucket was created. This date can change when making changes to your bucket, such as editing its bucket policy.
    pub creation_date: String,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Buckets {
    #[serde(default)]
    pub bucket: Vec<Bucket>,
}

/// Container for all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CommonPrefix {
    pub prefix: String,
}

/// The container for the completed multipart upload details.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CompleteMultipartUpload {
    #[serde(default, rename = "Part")]
    pub parts: Vec<Part>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CompleteMultipartUploadResult {
    pub bucket: String,
    pub key: String,
    pub e_tag: String,
    pub location: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CopyPartResult {
    pub e_tag: String,
}

/// Describes the cross-origin access configuration for objects in an Amazon S3 bucket.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CORSConfiguration {
    #[serde(rename = "CORSRule")]
    pub rules: Vec<CORSRule>,
}

/// Specifies a cross-origin access rule for an Amazon S3 bucket.
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct CORSRule {
    /// **Required**. Valid values are `GET`, `PUT`, `HEAD`, `POST`, and `DELETE`.
    #[serde(rename = "AllowedMethod", default)]
    pub allowed_methods: Vec<String>,
    /// **Required**
    #[serde(rename = "AllowedOrigin", default)]
    pub allowed_origins: Vec<String>,
    #[serde(rename = "AllowedHeader", default)]
    pub allowed_headers: Vec<String>,
    #[serde(rename = "ExposeHeader", default)]
    pub expose_headers: Vec<String>,
    #[serde(rename = "ID")]
    pub id: Option<String>,
    pub max_age_seconds: usize,
}

/// The container element for specifying the default Object Lock retention settings
/// for new objects placed in the specified bucket.
///
/// **Note**
/// - The DefaultRetention settings require **both** a `mode` and a `period`.
/// - The DefaultRetention period can be either Days or Years but you must select one.
///   You cannot specify Days and Years at the same time.
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct DefaultRetention {
    pub days: Option<usize>,
    pub mode: RetentionMode,
    pub years: Option<usize>,
}

/// Information about the delete marker.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteMarkerEntry {
    /// The object key.
    pub key: String,
    /// Date and time when the object was last modified.
    pub last_modified: String,
    /// Specifies whether the object is (true) or is not (false) the latest version of an object.
    pub is_latest: bool,
    /// The entity tag is an MD5 hash of that version of the object.
    pub owner: Option<Owner>,
    /// Version ID of an object.
    pub version_id: Option<String>,
}

/// Container for grant information.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Grant {
    pub grantee: Option<Grantee>,
    pub permission: Option<Permission>,
}

/// Container for the person being granted permissions.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Grantee {
    pub display_name: Option<String>,
    pub email_address: Option<String>,
    pub id: Option<String>,
    #[serde(alias = "Type", alias = "type")]
    pub r#type: GranteeType,
    pub uri: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct InitiateMultipartUploadResult {
    pub bucket: String,
    pub key: String,
    pub upload_id: String,
}

/// Container element that identifies who initiated the multipart upload.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Initiator {
    pub display_name: String,
    #[serde(rename = "ID")]
    pub id: String,
}

/// A legal hold configuration for an object.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct LegalHold {
    pub status: LegalHoldStatus,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListAllMyBucketsResult {
    #[serde(default)]
    pub buckets: Buckets,
    pub owner: Owner,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListBucketResult {
    pub name: String,
    pub prefix: String,
    pub key_count: usize,
    pub max_keys: usize,
    #[serde(default)]
    pub delimiter: String,
    pub is_truncated: bool,
    pub start_after: Option<String>,
    #[serde(default)]
    pub contents: Vec<Object>,
    #[serde(default)]
    pub common_prefixes: Vec<CommonPrefix>,
    #[serde(default)]
    pub next_continuation_token: String,
    #[serde(default)]
    pub continuation_token: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListMultipartUploadsResult {
    pub bucket: String,
    pub key_marker: String,
    pub upload_id_marker: String,
    pub next_key_marker: String,
    pub prefix: String,
    pub delimiter: String,
    pub next_upload_id_marker: String,
    pub max_uploads: usize,
    pub is_truncated: bool,
    #[serde(default, rename = "Upload")]
    pub uploads: Vec<MultipartUpload>,
    #[serde(default)]
    pub common_prefixes: Vec<CommonPrefix>,
    pub encoding_type: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListPartsResult {
    pub bucket: String,
    pub key: String,
    pub upload_id: String,
    pub part_number_marker: usize,
    pub max_parts: usize,
    pub next_part_number_marker: usize,
    pub is_truncated: bool,
    #[serde(default, rename = "Part")]
    pub parts: Vec<Part>,
    pub storage_class: String,
    pub checksum_algorithm: String,
    pub initiator: Initiator,
    pub owner: Owner,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListVersionsResult {
    /// A flag that indicates whether Amazon S3 returned all of the results
    /// that satisfied the search criteria. If your results were truncated,
    /// you can make a follow-up paginated request by using the `NextKeyMarker`
    /// and `NextVersionIdMarker` response parameters as a starting place in
    /// another request to return the rest of the results.
    pub is_truncated: bool,
    /// All of the keys rolled up into a common prefix count as a single return when calculating the number of returns.
    #[serde(default)]
    pub common_prefixes: Vec<CommonPrefix>,
    #[serde(default, rename = "Version")]
    pub versions: Vec<ObjectVersion>,
    /// Container for an object that is a delete marker.
    #[serde(default, rename = "DeleteMarker")]
    pub delete_markers: Vec<DeleteMarkerEntry>,
    pub name: String,
    pub prefix: String,
    pub max_keys: usize,
    #[serde(default)]
    pub delimiter: String,
    pub encoding_type: Option<String>,
    /// Marks the last key returned in a truncated response.
    #[serde(default)]
    pub key_marker: String,
    /// When the number of responses exceeds the value of `MaxKeys`,
    /// `NextKeyMarker` specifies the first key not returned that
    /// satisfies the search criteria. Use this value for the `key-marker`
    /// request parameter in a subsequent request.
    #[serde(default)]
    pub next_key_marker: String,
    /// Marks the last version of the key returned in a truncated response.
    #[serde(default)]
    pub version_id_marker: String,
    /// When the number of responses exceeds the value of `MaxKeys`,
    /// `NextVersionIdMarker` specifies the first object version not
    /// returned that satisfies the search criteria. Use this value
    /// for the `version-id-marker` request parameter in a subsequent request.
    #[serde(default)]
    pub next_version_id_marker: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct LocationConstraint {
    pub location_constraint: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MultipartUpload {
    pub checksum_algorithm: String,
    pub upload_id: String,
    pub storage_class: String,
    pub key: String,
    pub initiated: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Object {
    pub key: String,
    pub last_modified: String,
    pub e_tag: String,
    pub size: u64,
    pub storage_class: String,
    pub owner: Option<Owner>,
    pub checksum_algorithm: Option<String>,
}

/// The container element for an Object Lock rule.
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct ObjectLockRule {
    pub default_retention: DefaultRetention,
}

/// Object representation of
/// - request XML of `put_object_lock_configuration` API
/// - response XML of `get_object_lock_configuration` API.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ObjectLockConfiguration {
    /// Indicates whether this bucket has an Object Lock configuration enabled.
    /// Enable ObjectLockEnabled when you apply ObjectLockConfiguration to a bucket.
    ///
    /// Valid Values: `Enabled`
    /// Required: No
    pub object_lock_enabled: String,
    pub rule: Option<ObjectLockRule>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ObjectVersion {
    /// The object key.
    pub key: String,
    /// Date and time when the object was last modified.
    pub last_modified: String,
    /// Specifies whether the object is (true) or is not (false) the latest version of an object.
    pub is_latest: bool,
    /// The entity tag is an MD5 hash of that version of the object.
    pub e_tag: String,
    pub size: u64,
    pub storage_class: String,
    pub owner: Option<Owner>,
    /// Version ID of an object.
    pub version_id: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Owner {
    pub display_name: String,
    #[serde(rename = "ID")]
    pub id: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Part {
    pub e_tag: String,
    pub part_number: usize,
}

/// This data type contains information about progress of an operation.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Progress {
    pub bytes_processed: u64,
    pub bytes_returned: u64,
    pub bytes_scanned: u64,
}

/// PublicAccessBlockConfiguration parameters
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct PublicAccessBlockConfiguration {
    pub block_public_acls: bool,
    pub block_public_policy: bool,
    pub ignore_public_acls: bool,
    pub restrict_public_buckets: bool,
}

/// A container for replication rules. You can add up to 1,000 rules. The maximum size of a replication configuration is 2 MB.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ReplicationConfiguration {
    pub role: String,
    #[serde(rename = "Rule", default)]
    pub rules: Vec<ReplicationRule>,
}

/// Specifies which Amazon S3 objects to replicate and where to store the replicas.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ReplicationRule {
    pub role: String,
    pub id: Option<String>,
    pub priority: Option<i64>,
}

/// Object representation of request XML of `put_object_retention` API
/// and response XML of `get_object_retention` API.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Retention {
    /// Valid Values: GOVERNANCE | COMPLIANCE
    pub mode: RetentionMode,
    /// The date on which this Object Lock Retention will expire.
    #[serde(deserialize_with = "crate::time::deserialize_with_str")]
    pub retain_until_date: UtcTime,
}

/// Describes the default server-side encryption to apply to new objects in the bucket.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ServerSideEncryptionByDefault {
    #[serde(rename = "SSEAlgorithm")]
    pub ssealgorithm: String,
    #[serde(rename = " KMSMasterKeyID")]
    pub kmsmaster_key_id: Option<String>,
}

/// Root level tag for the ServerSideEncryptionConfiguration parameters
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ServerSideEncryptionConfiguration {
    #[serde(rename = "Rule")]
    pub rules: Vec<ServerSideEncryptionRule>,
}

/// Specifies the default server-side encryption configuration.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ServerSideEncryptionRule {
    pub apply_server_side_encryption_by_default: ServerSideEncryptionByDefault,
    #[serde(default)]
    pub bucket_key_enabled: bool,
}

/// Container for the stats details.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Stats {
    pub bytes_processed: u64,
    pub bytes_returned: u64,
    pub bytes_scanned: u64,
}

/// A container of a key value name pair.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Tag {
    pub key: String,
    pub value: String,
}

/// A collection for a set of tags
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct TagSet {
    #[serde(rename = "Tag", default)]
    pub tags: Vec<Tag>,
}

/// Container for TagSet elements.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Tagging {
    pub tag_set: TagSet,
}

/// Describes the versioning state of an Amazon S3 bucket.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct VersioningConfiguration {
    /// Specifies whether MFA delete is enabled in the bucket versioning configuration.
    /// This element is only returned if the bucket has been configured with MFA delete.
    /// If the bucket has never been so configured, this element is not returned.
    ///
    /// Valid Values: Enabled | Disabled
    pub mfa_delete: Option<MFADelete>,

    /// The versioning state of the bucket.
    ///
    /// Valid Values: Enabled | Suspended
    pub status: Option<VersioningStatus>,
}

//////////////////  Enum Type

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum ChecksumAlgorithm {
    CRC32,
    CRC32C,
    SHA1,
    SHA256,
}

/// Type of grantee
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum GranteeType {
    CanonicalUser,
    AmazonCustomerByEmail,
    Group,
}

/// Specifies whether MFA delete is enabled in the bucket versioning configuration.
/// This element is only returned if the bucket has been configured with MFA delete.
/// If the bucket has never been so configured, this element is not returned.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum MFADelete {
    Enabled,
    Disabled,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum LegalHoldStatus {
    ON,
    OFF,
}

/// Retention mode, Valid Values: `GOVERNANCE | COMPLIANCE`
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
pub enum RetentionMode {
    #[default]
    GOVERNANCE,
    COMPLIANCE,
}

/// The permission given to the grantee.. Valid Values: `FULL_CONTROL | WRITE | WRITE_ACP | READ | READ_ACP`
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum Permission {
    FULL_CONTROL,
    WRITE,
    WRITE_ACP,
    READ,
    READ_ACP,
}

/// Valid Values: `Enabled | Disabled`
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum Status {
    Enabled,
    Disabled,
}

/// The versioning state of the bucket.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum VersioningStatus {
    Enabled,
    Suspended,
}