17
17
18
18
use super :: credential:: { AzureCredential , CredentialProvider } ;
19
19
use crate :: azure:: credential:: * ;
20
+ use crate :: azure:: STORE ;
20
21
use crate :: client:: pagination:: stream_paginated;
21
22
use crate :: client:: retry:: RetryExt ;
23
+ use crate :: client:: GetOptionsExt ;
22
24
use crate :: path:: DELIMITER ;
23
- use crate :: util:: { deserialize_rfc1123, format_http_range , format_prefix} ;
25
+ use crate :: util:: { deserialize_rfc1123, format_prefix} ;
24
26
use crate :: {
25
- BoxStream , ClientOptions , ListResult , ObjectMeta , Path , Result , RetryConfig ,
26
- StreamExt ,
27
+ BoxStream , ClientOptions , GetOptions , ListResult , ObjectMeta , Path , Result ,
28
+ RetryConfig , StreamExt ,
27
29
} ;
28
30
use base64:: prelude:: BASE64_STANDARD ;
29
31
use base64:: Engine ;
@@ -32,13 +34,12 @@ use chrono::{DateTime, Utc};
32
34
use itertools:: Itertools ;
33
35
use reqwest:: header:: CONTENT_TYPE ;
34
36
use reqwest:: {
35
- header:: { HeaderValue , CONTENT_LENGTH , IF_NONE_MATCH , RANGE } ,
37
+ header:: { HeaderValue , CONTENT_LENGTH , IF_NONE_MATCH } ,
36
38
Client as ReqwestClient , Method , Response , StatusCode ,
37
39
} ;
38
40
use serde:: { Deserialize , Serialize } ;
39
41
use snafu:: { ResultExt , Snafu } ;
40
42
use std:: collections:: HashMap ;
41
- use std:: ops:: Range ;
42
43
use url:: Url ;
43
44
44
45
/// A specialized `Error` for object store-related errors
@@ -69,12 +70,6 @@ pub(crate) enum Error {
69
70
path : String ,
70
71
} ,
71
72
72
- #[ snafu( display( "Error performing copy request {}: {}" , path, source) ) ]
73
- CopyRequest {
74
- source : crate :: client:: retry:: Error ,
75
- path : String ,
76
- } ,
77
-
78
73
#[ snafu( display( "Error performing list request: {}" , source) ) ]
79
74
ListRequest { source : crate :: client:: retry:: Error } ,
80
75
@@ -95,25 +90,9 @@ impl From<Error> for crate::Error {
95
90
match err {
96
91
Error :: GetRequest { source, path }
97
92
| Error :: DeleteRequest { source, path }
98
- | Error :: CopyRequest { source, path }
99
- | Error :: PutRequest { source, path }
100
- if matches ! ( source. status( ) , Some ( StatusCode :: NOT_FOUND ) ) =>
101
- {
102
- Self :: NotFound {
103
- path,
104
- source : Box :: new ( source) ,
105
- }
106
- }
107
- Error :: CopyRequest { source, path }
108
- if matches ! ( source. status( ) , Some ( StatusCode :: CONFLICT ) ) =>
109
- {
110
- Self :: AlreadyExists {
111
- path,
112
- source : Box :: new ( source) ,
113
- }
114
- }
93
+ | Error :: PutRequest { source, path } => source. error ( STORE , path) ,
115
94
_ => Self :: Generic {
116
- store : "MicrosoftAzure" ,
95
+ store : STORE ,
117
96
source : Box :: new ( err) ,
118
97
} ,
119
98
}
@@ -175,7 +154,7 @@ impl AzureClient {
175
154
// and we want to use it in an infallible function
176
155
HeaderValue :: from_str ( & format ! ( "Bearer {token}" ) ) . map_err ( |err| {
177
156
crate :: Error :: Generic {
178
- store : "MicrosoftAzure" ,
157
+ store : STORE ,
179
158
source : Box :: new ( err) ,
180
159
}
181
160
} ) ?,
@@ -193,7 +172,7 @@ impl AzureClient {
193
172
// and we want to use it in an infallible function
194
173
HeaderValue :: from_str ( & format ! ( "Bearer {token}" ) ) . map_err ( |err| {
195
174
crate :: Error :: Generic {
196
- store : "MicrosoftAzure" ,
175
+ store : STORE ,
197
176
source : Box :: new ( err) ,
198
177
}
199
178
} ) ?,
@@ -253,7 +232,7 @@ impl AzureClient {
253
232
pub async fn get_request (
254
233
& self ,
255
234
path : & Path ,
256
- range : Option < Range < usize > > ,
235
+ options : GetOptions ,
257
236
head : bool ,
258
237
) -> Result < Response > {
259
238
let credential = self . get_credential ( ) . await ?;
@@ -263,17 +242,14 @@ impl AzureClient {
263
242
false => Method :: GET ,
264
243
} ;
265
244
266
- let mut builder = self
245
+ let builder = self
267
246
. client
268
247
. request ( method, url)
269
248
. header ( CONTENT_LENGTH , HeaderValue :: from_static ( "0" ) )
270
249
. body ( Bytes :: new ( ) ) ;
271
250
272
- if let Some ( range) = range {
273
- builder = builder. header ( RANGE , format_http_range ( range) ) ;
274
- }
275
-
276
251
let response = builder
252
+ . with_get_options ( options)
277
253
. with_azure_authorization ( & credential, & self . config . account )
278
254
. send_retry ( & self . config . retry_config )
279
255
. await
@@ -338,8 +314,12 @@ impl AzureClient {
338
314
. with_azure_authorization ( & credential, & self . config . account )
339
315
. send_retry ( & self . config . retry_config )
340
316
. await
341
- . context ( CopyRequestSnafu {
342
- path : from. as_ref ( ) ,
317
+ . map_err ( |err| match err. status ( ) {
318
+ Some ( StatusCode :: CONFLICT ) => crate :: Error :: AlreadyExists {
319
+ source : Box :: new ( err) ,
320
+ path : to. to_string ( ) ,
321
+ } ,
322
+ _ => err. error ( STORE , from. to_string ( ) ) ,
343
323
} ) ?;
344
324
345
325
Ok ( ( ) )
0 commit comments