-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.rs
189 lines (176 loc) · 5.07 KB
/
common.rs
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
use crate::utils::errors::APIError;
use async_trait::async_trait;
use bytes::Bytes;
use core::num::NonZeroU32;
use futures_core::Stream;
use serde::Deserialize;
use serde::Serialize;
use std::pin::Pin;
use reqwest::Error as ReqwestError;
type BoxedReqwestStream = Pin<Box<dyn Stream<Item = Result<Bytes, ReqwestError>> + Send>>;
pub struct GetObjectResponse {
pub content_length: u64,
pub content_type: String,
pub last_modified: String,
pub etag: String,
pub body: BoxedReqwestStream,
}
pub struct HeadObjectResponse {
pub content_length: u64,
pub content_type: String,
pub last_modified: String,
pub etag: String,
}
#[derive(Debug, Serialize)]
pub struct CompleteMultipartUploadResponse {
#[serde(rename = "Location")]
pub location: String,
#[serde(rename = "Bucket")]
pub bucket: String,
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "ETag")]
pub etag: String,
}
#[async_trait]
pub trait Repository {
async fn delete_object(&self, key: String) -> Result<(), Box<dyn APIError>>;
async fn create_multipart_upload(
&self,
key: String,
content_type: Option<String>,
) -> Result<CreateMultipartUploadResponse, Box<dyn APIError>>;
async fn abort_multipart_upload(
&self,
key: String,
upload_id: String,
) -> Result<(), Box<dyn APIError>>;
async fn complete_multipart_upload(
&self,
key: String,
upload_id: String,
parts: Vec<MultipartPart>,
) -> Result<CompleteMultipartUploadResponse, Box<dyn APIError>>;
async fn upload_multipart_part(
&self,
key: String,
upload_id: String,
part_number: String,
bytes: Bytes,
) -> Result<UploadPartResponse, Box<dyn APIError>>;
async fn put_object(
&self,
key: String,
bytes: Bytes,
content_type: Option<String>,
) -> Result<(), Box<dyn APIError>>;
async fn get_object(
&self,
key: String,
range: Option<String>,
) -> Result<GetObjectResponse, Box<dyn APIError>>;
async fn head_object(&self, key: String) -> Result<HeadObjectResponse, Box<dyn APIError>>;
async fn list_objects_v2(
&self,
prefix: String,
continuation_token: Option<String>,
delimiter: Option<String>,
max_keys: NonZeroU32,
) -> Result<ListBucketResult, Box<dyn APIError>>;
async fn list_buckets_accounts(
&self,
prefix: String,
continuation_token: Option<String>,
delimiter: Option<String>,
max_keys: NonZeroU32,
) -> Result<ListAllBucketsResult, Box<dyn APIError>>;
}
#[derive(Debug, Serialize)]
pub struct ListBucketResult {
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "Prefix")]
pub prefix: String,
#[serde(rename = "KeyCount")]
pub key_count: i64,
#[serde(rename = "MaxKeys")]
pub max_keys: i64,
#[serde(rename = "IsTruncated")]
pub is_truncated: bool,
#[serde(rename = "Contents")]
pub contents: Vec<Content>,
#[serde(rename = "CommonPrefixes")]
pub common_prefixes: Vec<CommonPrefix>,
#[serde(rename = "NextContinuationToken")]
pub next_continuation_token: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct Content {
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "LastModified")]
pub last_modified: String,
#[serde(rename = "ETag")]
pub etag: String,
#[serde(rename = "Size")]
pub size: i64,
#[serde(rename = "StorageClass")]
pub storage_class: String,
}
#[derive(Debug, Serialize)]
pub struct CommonPrefix {
#[serde(rename = "Prefix")]
pub prefix: String,
}
#[derive(Debug, Serialize)]
pub struct ListAllBucketsResult {
#[serde(rename = "Buckets")]
pub buckets: ListBuckets,
}
#[derive(Debug, Serialize)]
pub struct ListBuckets {
#[serde(rename = "Bucket")]
pub bucket: Vec<ListBucket>,
}
#[derive(Debug, Serialize)]
pub struct ListBucket {
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "CreationDate")]
pub creation_date: String,
}
#[derive(Debug, Serialize)]
pub struct CreateMultipartUploadResponse {
#[serde(rename = "Bucket")]
pub bucket: String,
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "UploadId")]
pub upload_id: String,
}
#[derive(Debug, Serialize)]
pub struct UploadPartResponse {
#[serde(rename = "ETag")]
pub etag: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MultipartPart {
#[serde(rename = "PartNumber")]
pub part_number: i64,
#[serde(rename = "ETag")]
pub etag: String,
#[serde(rename = "ChecksumCRC32")]
pub checksum_crc32: Option<String>,
#[serde(rename = "ChecksumCRC32C")]
pub checksum_crc32c: Option<String>,
#[serde(rename = "ChecksumSHA1")]
pub checksum_sha1: Option<String>,
#[serde(rename = "ChecksumSHA256")]
pub checksum_sha256: Option<String>,
}
#[derive(Debug, Deserialize)]
#[serde(rename = "CompleteMultipartUpload")]
pub struct CompleteMultipartUpload {
#[serde(rename = "Part")]
pub parts: Vec<MultipartPart>,
}