11use std:: collections:: HashMap ;
22use std:: sync:: Arc ;
33
4- use object_store:: aws:: AmazonS3 ;
5- use object_store:: azure:: MicrosoftAzure ;
6- use object_store:: gcp:: GoogleCloudStorage ;
4+ use object_store:: aws:: { AmazonS3 , AmazonS3Builder } ;
5+ use object_store:: azure:: { MicrosoftAzure , MicrosoftAzureBuilder } ;
6+ use object_store:: gcp:: { GoogleCloudStorage , GoogleCloudStorageBuilder } ;
77use object_store:: local:: LocalFileSystem ;
88use object_store:: memory:: InMemory ;
99use object_store:: path:: Path ;
@@ -14,8 +14,6 @@ use object_store::{
1414} ;
1515use url:: Url ;
1616
17- use crate :: config:: { aws:: S3Config , azure:: AzureConfig , google:: GoogleConfig } ;
18-
1917enum ObjectStoreKind {
2018 Local ,
2119 InMemory ,
@@ -136,26 +134,65 @@ impl ObjectStoreBuilder {
136134 store : "Generic" ,
137135 source : Box :: new ( err) ,
138136 } ) ?;
139- let root_store = match ObjectStoreKind :: parse_url ( & url) . unwrap ( ) {
137+ let root_store = match ObjectStoreKind :: parse_url ( & url) ? {
140138 ObjectStoreKind :: Local => ObjectStoreImpl :: Local ( LocalFileSystem :: new ( ) ) ,
141139 ObjectStoreKind :: InMemory => ObjectStoreImpl :: InMemory ( InMemory :: new ( ) ) ,
142140 ObjectStoreKind :: Azure => {
143- let builder = AzureConfig :: get_builder ( & self . url , & self . options ) ?
144- . with_client_options ( self . client_options . unwrap_or_default ( ) )
145- . with_retry ( self . retry_config . unwrap_or_default ( ) ) ;
146- ObjectStoreImpl :: Azrue ( builder. build ( ) ?)
141+ let maybe_store = MicrosoftAzureBuilder :: new ( )
142+ . with_url ( url. clone ( ) )
143+ . with_options ( & self . options )
144+ . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
145+ . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
146+ . build ( ) ;
147+ if let Ok ( store) = maybe_store {
148+ ObjectStoreImpl :: Azrue ( store)
149+ } else {
150+ let store = MicrosoftAzureBuilder :: from_env ( )
151+ . with_url ( url. clone ( ) )
152+ . with_options ( & self . options )
153+ . with_client_options ( self . client_options . unwrap_or_default ( ) )
154+ . with_retry ( self . retry_config . unwrap_or_default ( ) )
155+ . build ( ) ?;
156+ ObjectStoreImpl :: Azrue ( store)
157+ }
147158 }
148159 ObjectStoreKind :: S3 => {
149- let builder = S3Config :: get_builder ( & self . url , & self . options ) ?
150- . with_client_options ( self . client_options . unwrap_or_default ( ) )
151- . with_retry ( self . retry_config . unwrap_or_default ( ) ) ;
152- ObjectStoreImpl :: S3 ( builder. build ( ) ?)
160+ let maybe_store = AmazonS3Builder :: new ( )
161+ . with_url ( url. clone ( ) )
162+ . with_options ( & self . options )
163+ . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
164+ . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
165+ . build ( ) ;
166+ if let Ok ( store) = maybe_store {
167+ ObjectStoreImpl :: S3 ( store)
168+ } else {
169+ let store = AmazonS3Builder :: from_env ( )
170+ . with_url ( url. clone ( ) )
171+ . with_options ( & self . options )
172+ . with_client_options ( self . client_options . unwrap_or_default ( ) )
173+ . with_retry ( self . retry_config . unwrap_or_default ( ) )
174+ . build ( ) ?;
175+ ObjectStoreImpl :: S3 ( store)
176+ }
153177 }
154178 ObjectStoreKind :: Google => {
155- let builder = GoogleConfig :: get_builder ( & self . url , & self . options ) ?
156- . with_client_options ( self . client_options . unwrap_or_default ( ) )
157- . with_retry ( self . retry_config . unwrap_or_default ( ) ) ;
158- ObjectStoreImpl :: Gcp ( builder. build ( ) ?)
179+ let maybe_store = GoogleCloudStorageBuilder :: new ( )
180+ . with_url ( url. clone ( ) )
181+ . with_options ( & self . options )
182+ . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
183+ . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
184+ . build ( ) ;
185+ if let Ok ( store) = maybe_store {
186+ ObjectStoreImpl :: Gcp ( store)
187+ } else {
188+ let store = GoogleCloudStorageBuilder :: from_env ( )
189+ . with_url ( url. clone ( ) )
190+ . with_options ( & self . options )
191+ . with_client_options ( self . client_options . unwrap_or_default ( ) )
192+ . with_retry ( self . retry_config . unwrap_or_default ( ) )
193+ . build ( ) ?;
194+ ObjectStoreImpl :: Gcp ( store)
195+ }
159196 }
160197 } ;
161198
0 commit comments