@@ -28,7 +28,7 @@ pub mod registry;
2828#[ derive( Debug , Clone , Serialize , Deserialize ) ]
2929pub struct BlobStorageConfig {
3030 pub path : String ,
31- pub region : String ,
31+ pub region : Option < String > ,
3232}
3333
3434impl Default for BlobStorageConfig {
@@ -43,7 +43,7 @@ impl Default for BlobStorageConfig {
4343 ) ;
4444 BlobStorageConfig {
4545 path : blob_store_path,
46- region : "" . to_string ( ) ,
46+ region : None ,
4747 }
4848 }
4949}
@@ -67,7 +67,7 @@ impl BlobStorage {
6767 pub fn new ( config : BlobStorageConfig ) -> Result < Self > {
6868 let url = & config. path . clone ( ) ;
6969 debug ! ( "using blob store path: {}" , url) ;
70- let ( object_store, path) = Self :: build_object_store ( url, & config. region ) ?;
70+ let ( object_store, path) = Self :: build_object_store ( url, config. region . clone ( ) ) ?;
7171 Ok ( Self {
7272 object_store : Arc :: new ( object_store) ,
7373 url_scheme : url. parse :: < Url > ( ) ?. scheme ( ) . to_string ( ) ,
@@ -77,22 +77,28 @@ impl BlobStorage {
7777 } )
7878 }
7979
80- pub fn build_object_store ( url_str : & str , region : & str ) -> Result < ( Box < dyn ObjectStore > , Path ) > {
80+ pub fn build_object_store (
81+ url_str : & str ,
82+ region : Option < String > ,
83+ ) -> Result < ( Box < dyn ObjectStore > , Path ) > {
8184 let url = & url_str. parse :: < Url > ( ) ?;
8285 let ( scheme, _) = ObjectStoreScheme :: parse ( url) ?;
8386 match scheme {
8487 ObjectStoreScheme :: AmazonS3 => {
8588 // inject AWS environment variables to prioritize keys over instance metadata
8689 // credentials.
87- let s3_builder = AmazonS3Builder :: from_env ( )
90+ let mut s3_builder = AmazonS3Builder :: from_env ( )
8891 . with_url ( url_str)
8992 . with_allow_http ( true )
90- . with_conditional_put ( S3ConditionalPut :: ETagMatch )
91- . with_region ( region)
92- . build ( )
93- . expect ( "failed to create object store" ) ;
93+ . with_conditional_put ( S3ConditionalPut :: ETagMatch ) ;
94+
95+ if let Some ( region) = region {
96+ s3_builder = s3_builder. with_region ( region) ;
97+ }
98+
99+ let obj_store = s3_builder. build ( ) . expect ( "failed to create object store" ) ;
94100 let ( _, path) = parse_url ( url) ?;
95- Ok ( ( Box :: new ( s3_builder ) , path) )
101+ Ok ( ( Box :: new ( obj_store ) , path) )
96102 }
97103 _ => Ok ( parse_url ( url) ?) ,
98104 }
0 commit comments