Skip to main content

s3_wire/operation/multipart/
listing.rs

1use http::HeaderMap;
2
3use super::{PartNumber, UploadId};
4use crate::operation::{Checksum, ChecksumType, ObjectKey, PageSize, RequestIds};
5
6/// Request for one page of in-progress multipart uploads.
7#[derive(Clone, Default, derive_more::Debug, Eq, PartialEq)]
8pub struct ListMultipartUploadsRequest {
9    /// Only uploads with keys beginning with this prefix are returned.
10    pub prefix: Option<String>,
11    /// Groups upload keys using this delimiter.
12    pub delimiter: Option<String>,
13    /// Key marker from a preceding response.
14    pub key_marker: Option<String>,
15    /// Upload-ID marker from a preceding response.
16    pub upload_id_marker: Option<UploadId>,
17    /// Maximum uploads requested from the service.
18    pub max_uploads: PageSize,
19    /// Additional request headers. Values are signed and repeated values are preserved.
20    /// Generated-name collisions are errors; signing- and transport-owned headers are rejected.
21    #[debug("{:?}", "<redacted>")]
22    pub headers: HeaderMap,
23}
24
25impl ListMultipartUploadsRequest {
26    /// Replaces the request's additional headers.
27    pub fn with_headers(mut self, headers: HeaderMap) -> Self {
28        self.headers = headers;
29        self
30    }
31}
32
33/// One in-progress multipart upload returned by the service.
34#[derive(Clone, Debug, Eq, PartialEq)]
35pub struct MultipartUploadEntry {
36    /// Destination object key.
37    pub key: ObjectKey,
38    /// Opaque upload identifier.
39    upload_id: UploadId,
40    /// Initiation time.
41    pub initiated: Option<time::OffsetDateTime>,
42    /// Storage class, when supplied.
43    pub storage_class: Option<String>,
44}
45
46impl MultipartUploadEntry {
47    pub(crate) fn new(
48        key: ObjectKey,
49        upload_id: UploadId,
50        initiated: Option<time::OffsetDateTime>,
51        storage_class: Option<String>,
52    ) -> Self {
53        Self {
54            key,
55            upload_id,
56            initiated,
57            storage_class,
58        }
59    }
60
61    /// Returns the validated upload identifier.
62    pub const fn upload_id(&self) -> &UploadId {
63        &self.upload_id
64    }
65}
66
67/// One page of in-progress multipart uploads.
68#[derive(Clone, Debug, Default, Eq, PartialEq)]
69pub struct ListMultipartUploadsOutput {
70    /// Upload entries.
71    pub uploads: Vec<MultipartUploadEntry>,
72    /// Grouped key prefixes.
73    pub common_prefixes: Vec<String>,
74    /// Whether another page exists.
75    pub is_truncated: bool,
76    /// Key marker for the next page.
77    pub next_key_marker: Option<String>,
78    /// Upload-ID marker for the next page.
79    pub next_upload_id_marker: Option<UploadId>,
80    /// Service request identifiers.
81    pub request_ids: RequestIds,
82}
83
84/// Request for one page of parts belonging to an in-progress upload.
85#[derive(Clone, derive_more::Debug, Eq, PartialEq)]
86pub struct ListPartsRequest {
87    key: ObjectKey,
88    upload_id: UploadId,
89    /// Lists only parts after this part number.
90    pub part_number_marker: Option<PartNumber>,
91    /// Maximum parts requested from the service.
92    pub max_parts: PageSize,
93    /// Additional request headers. Values are signed and repeated values are preserved.
94    /// Generated-name collisions are errors; signing- and transport-owned headers are rejected.
95    #[debug("{:?}", "<redacted>")]
96    pub headers: HeaderMap,
97}
98
99impl ListPartsRequest {
100    /// Constructs a request for the first page of an upload's parts.
101    pub fn new(key: ObjectKey, upload_id: UploadId) -> Self {
102        Self {
103            key,
104            upload_id,
105            part_number_marker: None,
106            max_parts: PageSize::default(),
107            headers: HeaderMap::new(),
108        }
109    }
110
111    /// Replaces the request's additional headers.
112    pub fn with_headers(mut self, headers: HeaderMap) -> Self {
113        self.headers = headers;
114        self
115    }
116
117    /// Returns the destination object key.
118    pub const fn key(&self) -> &ObjectKey {
119        &self.key
120    }
121
122    /// Returns the service-issued upload identifier.
123    pub const fn upload_id(&self) -> &UploadId {
124        &self.upload_id
125    }
126}
127
128/// One uploaded part returned by `ListParts`.
129#[derive(Clone, Debug, Eq, PartialEq)]
130pub struct ListedPart {
131    part_number: PartNumber,
132    /// Entity tag used when completing the upload.
133    pub e_tag: String,
134    /// Time at which S3 accepted the part.
135    pub last_modified: Option<time::OffsetDateTime>,
136    /// Part size in bytes.
137    pub size: u64,
138    /// Checksums recorded for this part.
139    pub checksum: Checksum,
140}
141
142impl ListedPart {
143    pub(crate) fn new(
144        part_number: PartNumber,
145        e_tag: String,
146        last_modified: Option<time::OffsetDateTime>,
147        size: u64,
148        checksum: Checksum,
149    ) -> Self {
150        Self {
151            part_number,
152            e_tag,
153            last_modified,
154            size,
155            checksum,
156        }
157    }
158
159    /// Returns the validated part number.
160    pub const fn part_number(&self) -> PartNumber {
161        self.part_number
162    }
163
164    /// Converts this service entry into a completion descriptor.
165    pub fn completed_part(&self) -> Result<super::CompletedPart, super::MultipartError> {
166        super::CompletedPart::new(self.part_number.get(), self.e_tag.clone())
167            .map(|part| part.with_checksum(self.checksum.clone()))
168    }
169}
170
171/// One bounded page returned by `ListParts`.
172#[derive(Clone, Debug, Default, Eq, PartialEq)]
173pub struct ListPartsOutput {
174    /// Parts in ascending part-number order.
175    pub parts: Vec<ListedPart>,
176    /// Whether another page exists.
177    pub is_truncated: bool,
178    /// Marker to use for the next page.
179    pub next_part_number_marker: Option<PartNumber>,
180    /// Checksum algorithm selected when the upload was created.
181    pub checksum_algorithm: Option<String>,
182    /// Object-level checksum aggregation selected for the upload.
183    pub checksum_type: Option<ChecksumType>,
184    /// Service request identifiers.
185    pub request_ids: RequestIds,
186}