s3/serde_types.rs
1#[derive(Deserialize, Debug)]
2pub struct InitiateMultipartUploadResponse {
3 #[serde(rename = "Bucket")]
4 _bucket: String,
5 #[serde(rename = "Key")]
6 pub key: String,
7 #[serde(rename = "UploadId")]
8 pub upload_id: String,
9}
10
11/// Owner information for the object
12#[derive(Deserialize, Debug, Clone)]
13pub struct Owner {
14 #[serde(rename = "DisplayName")]
15 /// Object owner's name.
16 pub display_name: Option<String>,
17 #[serde(rename = "ID")]
18 /// Object owner's ID.
19 pub id: String,
20}
21
22/// An individual object in a `ListBucketResult`
23#[derive(Deserialize, Debug, Clone)]
24pub struct Object {
25 #[serde(rename = "LastModified")]
26 /// Date and time the object was last modified.
27 pub last_modified: String,
28 #[serde(rename = "ETag")]
29 /// The entity tag is an MD5 hash of the object. The ETag only reflects changes to the
30 /// contents of an object, not its metadata.
31 pub e_tag: Option<String>,
32 #[serde(rename = "StorageClass")]
33 /// STANDARD | STANDARD_IA | REDUCED_REDUNDANCY | GLACIER
34 pub storage_class: Option<String>,
35 #[serde(rename = "Key")]
36 /// The object's key
37 pub key: String,
38 #[serde(rename = "Owner")]
39 /// Bucket owner
40 pub owner: Option<Owner>,
41 #[serde(rename = "Size")]
42 /// Size in bytes of the object.
43 pub size: u64,
44}
45
46/// An individual upload in a `ListMultipartUploadsResult`
47#[derive(Deserialize, Debug, Clone)]
48pub struct MultipartUpload {
49 #[serde(rename = "Initiated")]
50 /// Date and time the multipart upload was initiated
51 pub initiated: String,
52 #[serde(rename = "StorageClass")]
53 /// STANDARD | STANDARD_IA | REDUCED_REDUNDANCY | GLACIER
54 pub storage_class: String,
55 #[serde(rename = "Key")]
56 /// The object's key
57 pub key: String,
58 #[serde(rename = "Owner")]
59 /// Bucket owner
60 pub owner: Option<Owner>,
61 #[serde(rename = "UploadId")]
62 /// The identifier of the upload
63 pub id: String,
64}
65
66use std::fmt;
67
68impl fmt::Display for CompleteMultipartUploadData {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 let mut parts = String::new();
71 for part in self.parts.clone() {
72 parts.push_str(&part.to_string())
73 }
74 write!(
75 f,
76 "<CompleteMultipartUpload>{}</CompleteMultipartUpload>",
77 parts
78 )
79 }
80}
81
82impl CompleteMultipartUploadData {
83 pub fn len(&self) -> usize {
84 self.to_string().as_bytes().len()
85 }
86
87 pub fn is_empty(&self) -> bool {
88 self.to_string().as_bytes().len() == 0
89 }
90}
91
92#[derive(Debug, Clone)]
93pub struct CompleteMultipartUploadData {
94 pub parts: Vec<Part>,
95}
96
97#[derive(Debug, Clone, Serialize)]
98pub struct Part {
99 #[serde(rename = "PartNumber")]
100 pub part_number: u32,
101 #[serde(rename = "ETag")]
102 pub etag: String,
103}
104
105impl fmt::Display for Part {
106 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107 write!(f, "<Part>").expect("Can't fail");
108 write!(f, "<PartNumber>{}</PartNumber>", self.part_number).expect("Can't fail");
109 write!(f, "<ETag>{}</ETag>", self.etag).expect("Can't fail");
110 write!(f, "</Part>")
111 }
112}
113
114#[derive(Deserialize, Debug, Clone)]
115pub struct BucketLocationResult {
116 #[serde(rename = "$value")]
117 pub region: String,
118}
119
120/// The parsed result of a s3 bucket listing
121///
122/// This accepts the ListBucketResult format returned for both ListObjects and ListObjectsV2
123#[derive(Deserialize, Debug, Clone)]
124pub struct ListBucketResult {
125 #[serde(rename = "Name")]
126 /// Name of the bucket.
127 pub name: String,
128 #[serde(rename = "Delimiter")]
129 /// A delimiter is a character you use to group keys.
130 pub delimiter: Option<String>,
131 #[serde(rename = "MaxKeys")]
132 /// Sets the maximum number of keys returned in the response body.
133 pub max_keys: Option<i32>,
134 #[serde(rename = "Prefix")]
135 /// Limits the response to keys that begin with the specified prefix.
136 pub prefix: Option<String>,
137 #[serde(rename = "ContinuationToken")] // for ListObjectsV2 request
138 #[serde(alias = "Marker")] // for ListObjects request
139 /// Indicates where in the bucket listing begins. It is included in the response if
140 /// it was sent with the request.
141 pub continuation_token: Option<String>,
142 #[serde(rename = "EncodingType")]
143 /// Specifies the encoding method to used
144 pub encoding_type: Option<String>,
145 #[serde(
146 default,
147 rename = "IsTruncated",
148 deserialize_with = "super::deserializer::bool_deserializer"
149 )]
150 /// Specifies whether (true) or not (false) all of the results were returned.
151 /// If the number of results exceeds that specified by MaxKeys, all of the results
152 /// might not be returned.
153
154 /// When the response is truncated (that is, the IsTruncated element value in the response
155 /// is true), you can use the key name in in 'next_continuation_token' as a marker in the
156 /// subsequent request to get next set of objects. Amazon S3 lists objects in UTF-8 character
157 /// encoding in lexicographical order.
158 pub is_truncated: bool,
159 #[serde(rename = "NextContinuationToken", default)] // for ListObjectsV2 request
160 #[serde(alias = "NextMarker")] // for ListObjects request
161 pub next_continuation_token: Option<String>,
162 #[serde(rename = "Contents", default)]
163 /// Metadata about each object returned.
164 pub contents: Vec<Object>,
165 #[serde(rename = "CommonPrefixes", default)]
166 /// All of the keys rolled up into a common prefix count as a single return when
167 /// calculating the number of returns.
168 pub common_prefixes: Option<Vec<CommonPrefix>>,
169}
170
171/// The parsed result of a s3 bucket listing of uploads
172#[derive(Deserialize, Debug, Clone)]
173pub struct ListMultipartUploadsResult {
174 #[serde(rename = "Bucket")]
175 /// Name of the bucket.
176 pub name: String,
177 #[serde(rename = "NextKeyMarker")]
178 /// When the response is truncated (that is, the IsTruncated element value in the response
179 /// is true), you can use the key name in this field as a marker in the subsequent request
180 /// to get next set of objects. Amazon S3 lists objects in UTF-8 character encoding in
181 /// lexicographical order.
182 pub next_marker: Option<String>,
183 #[serde(rename = "Prefix")]
184 /// The prefix, present if the request contained a prefix too, shows the search root for the
185 /// uploads listed in this structure.
186 pub prefix: Option<String>,
187 #[serde(rename = "KeyMarker")]
188 /// Indicates where in the bucket listing begins.
189 pub marker: Option<String>,
190 #[serde(rename = "EncodingType")]
191 /// Specifies the encoding method to used
192 pub encoding_type: Option<String>,
193 #[serde(
194 rename = "IsTruncated",
195 deserialize_with = "super::deserializer::bool_deserializer"
196 )]
197 /// Specifies whether (true) or not (false) all of the results were returned.
198 /// If the number of results exceeds that specified by MaxKeys, all of the results
199 /// might not be returned.
200 pub is_truncated: bool,
201 #[serde(rename = "Upload", default)]
202 /// Metadata about each upload returned.
203 pub uploads: Vec<MultipartUpload>,
204 #[serde(rename = "CommonPrefixes", default)]
205 /// All of the keys rolled up into a common prefix count as a single return when
206 /// calculating the number of returns.
207 pub common_prefixes: Option<Vec<CommonPrefix>>,
208}
209
210/// `CommonPrefix` is used to group keys
211#[derive(Deserialize, Debug, Clone)]
212pub struct CommonPrefix {
213 #[serde(rename = "Prefix")]
214 /// Keys that begin with the indicated prefix.
215 pub prefix: String,
216}
217
218// Taken from https://github.com/rusoto/rusoto
219#[derive(Deserialize, Debug, Default, Clone)]
220pub struct HeadObjectResult {
221 #[serde(rename = "AcceptRanges")]
222 /// Indicates that a range of bytes was specified.
223 pub accept_ranges: Option<String>,
224 #[serde(rename = "CacheControl")]
225 /// Specifies caching behavior along the request/reply chain.
226 pub cache_control: Option<String>,
227 #[serde(rename = "ContentDisposition")]
228 /// Specifies presentational information for the object.
229 pub content_disposition: Option<String>,
230 #[serde(rename = "ContentEncoding")]
231 /// Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field.
232 pub content_encoding: Option<String>,
233 #[serde(rename = "ContentLanguage")]
234 /// The language the content is in.
235 pub content_language: Option<String>,
236 #[serde(rename = "ContentLength")]
237 /// Size of the body in bytes.
238 pub content_length: Option<i64>,
239 #[serde(rename = "ContentType")]
240 /// A standard MIME type describing the format of the object data.
241 pub content_type: Option<String>,
242 #[serde(rename = "DeleteMarker")]
243 /// Specifies whether the object retrieved was (true) or was not (false) a Delete Marker.
244 pub delete_marker: Option<bool>,
245 #[serde(rename = "ETag")]
246 /// An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL.
247 pub e_tag: Option<String>,
248 #[serde(rename = "Expiration")]
249 /// If the object expiration is configured, the response includes this header. It includes the expiry-date and rule-id key-value pairs providing object expiration information.
250 /// The value of the rule-id is URL encoded.
251 pub expiration: Option<String>,
252 #[serde(rename = "Expires")]
253 /// The date and time at which the object is no longer cacheable.
254 pub expires: Option<String>,
255 #[serde(rename = "LastModified")]
256 /// Last modified date of the object
257 pub last_modified: Option<String>,
258 #[serde(rename = "Metadata", default)]
259 /// A map of metadata to store with the object in S3.
260 pub metadata: Option<::std::collections::HashMap<String, String>>,
261 #[serde(rename = "MissingMeta")]
262 /// This is set to the number of metadata entries not returned in x-amz-meta headers. This can happen if you create metadata using an API like SOAP that supports more flexible metadata than
263 /// the REST API. For example, using SOAP, you can create metadata whose values are not legal HTTP headers.
264 pub missing_meta: Option<i64>,
265 #[serde(rename = "ObjectLockLegalHoldStatus")]
266 /// Specifies whether a legal hold is in effect for this object. This header is only returned if the requester has the s3:GetObjectLegalHold permission.
267 /// This header is not returned if the specified version of this object has never had a legal hold applied.
268 pub object_lock_legal_hold_status: Option<String>,
269 #[serde(rename = "ObjectLockMode")]
270 /// The Object Lock mode, if any, that's in effect for this object.
271 pub object_lock_mode: Option<String>,
272 #[serde(rename = "ObjectLockRetainUntilDate")]
273 /// The date and time when the Object Lock retention period expires.
274 /// This header is only returned if the requester has the s3:GetObjectRetention permission.
275 pub object_lock_retain_until_date: Option<String>,
276 #[serde(rename = "PartsCount")]
277 /// The count of parts this object has.
278 pub parts_count: Option<i64>,
279 #[serde(rename = "ReplicationStatus")]
280 /// If your request involves a bucket that is either a source or destination in a replication rule.
281 pub replication_status: Option<String>,
282 #[serde(rename = "RequestCharged")]
283 pub request_charged: Option<String>,
284 #[serde(rename = "Restore")]
285 /// If the object is an archived object (an object whose storage class is GLACIER), the response includes this header if either the archive restoration is in progress or an archive copy is already restored.
286 /// If an archive copy is already restored, the header value indicates when Amazon S3 is scheduled to delete the object copy.
287 pub restore: Option<String>,
288 #[serde(rename = "SseCustomerAlgorithm")]
289 /// If server-side encryption with a customer-provided encryption key was requested, the response will include this header confirming the encryption algorithm used.
290 pub sse_customer_algorithm: Option<String>,
291 #[serde(rename = "SseCustomerKeyMd5")]
292 /// If server-side encryption with a customer-provided encryption key was requested, the response will include this header to provide round-trip message integrity verification of the customer-provided encryption key.
293 pub sse_customer_key_md5: Option<String>,
294 #[serde(rename = "SsekmsKeyId")]
295 /// If present, specifies the ID of the AWS Key Management Service (AWS KMS) symmetric customer managed customer master key (CMK) that was used for the object.
296 pub ssekms_key_id: Option<String>,
297 #[serde(rename = "ServerSideEncryption")]
298 /// If the object is stored using server-side encryption either with an AWS KMS customer master key (CMK) or an Amazon S3-managed encryption key,
299 /// The response includes this header with the value of the server-side encryption algorithm used when storing this object in Amazon S3 (for example, AES256, aws:kms).
300 pub server_side_encryption: Option<String>,
301 #[serde(rename = "StorageClass")]
302 /// Provides storage class information of the object. Amazon S3 returns this header for all objects except for S3 Standard storage class objects.
303 pub storage_class: Option<String>,
304 #[serde(rename = "VersionId")]
305 /// Version of the object.
306 pub version_id: Option<String>,
307 #[serde(rename = "WebsiteRedirectLocation")]
308 /// If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL. Amazon S3 stores the value of this header in the object metadata.
309 pub website_redirect_location: Option<String>,
310}
311
312#[derive(Deserialize, Debug)]
313pub struct AwsError {
314 #[serde(rename = "Code")]
315 pub code: String,
316 #[serde(rename = "Message")]
317 pub message: String,
318 #[serde(rename = "RequestId")]
319 pub request_id: String,
320}