@@ -127,7 +127,7 @@ fn get_region(s3_storage_config: &S3StorageConfig) -> Option<Region> {
127
127
} )
128
128
}
129
129
130
- async fn create_s3_client ( s3_storage_config : & S3StorageConfig ) -> S3Client {
130
+ pub async fn create_s3_client ( s3_storage_config : & S3StorageConfig ) -> S3Client {
131
131
let aws_config = get_aws_config ( ) . await ;
132
132
let credentials_provider =
133
133
get_credentials_provider ( s3_storage_config) . or ( aws_config. credentials_provider ( ) ) ;
@@ -155,41 +155,40 @@ async fn create_s3_client(s3_storage_config: &S3StorageConfig) -> S3Client {
155
155
}
156
156
157
157
impl S3CompatibleObjectStorage {
158
- /// Creates an object storage given a region and a bucket name .
159
- pub async fn new (
158
+ /// Creates an object storage given a region and an uri .
159
+ pub async fn from_uri (
160
160
s3_storage_config : & S3StorageConfig ,
161
- uri : Uri ,
162
- bucket : String ,
161
+ uri : & Uri ,
163
162
) -> Result < Self , StorageResolverError > {
164
163
let s3_client = create_s3_client ( s3_storage_config) . await ;
164
+ Self :: from_uri_and_client ( s3_storage_config, uri, s3_client) . await
165
+ }
166
+
167
+ /// Creates an object storage given a region, an uri and an S3 client.
168
+ pub async fn from_uri_and_client (
169
+ s3_storage_config : & S3StorageConfig ,
170
+ uri : & Uri ,
171
+ s3_client : S3Client ,
172
+ ) -> Result < Self , StorageResolverError > {
173
+ let ( bucket, prefix) = parse_s3_uri ( uri) . ok_or_else ( || {
174
+ let message = format ! ( "failed to extract bucket name from S3 URI: {uri}" ) ;
175
+ StorageResolverError :: InvalidUri ( message)
176
+ } ) ?;
165
177
let retry_params = RetryParams :: aggressive ( ) ;
166
178
let disable_multi_object_delete = s3_storage_config. disable_multi_object_delete ;
167
179
let disable_multipart_upload = s3_storage_config. disable_multipart_upload ;
168
180
Ok ( Self {
169
181
s3_client,
170
- uri,
182
+ uri : uri . clone ( ) ,
171
183
bucket,
172
- prefix : PathBuf :: new ( ) ,
184
+ prefix,
173
185
multipart_policy : MultiPartPolicy :: default ( ) ,
174
186
retry_params,
175
187
disable_multi_object_delete,
176
188
disable_multipart_upload,
177
189
} )
178
190
}
179
191
180
- /// Creates an object storage given a region and an uri.
181
- pub async fn from_uri (
182
- s3_storage_config : & S3StorageConfig ,
183
- uri : & Uri ,
184
- ) -> Result < Self , StorageResolverError > {
185
- let ( bucket, prefix) = parse_s3_uri ( uri) . ok_or_else ( || {
186
- let message = format ! ( "failed to extract bucket name from S3 URI: {uri}" ) ;
187
- StorageResolverError :: InvalidUri ( message)
188
- } ) ?;
189
- let storage = Self :: new ( s3_storage_config, uri. clone ( ) , bucket) . await ?;
190
- Ok ( storage. with_prefix ( prefix) )
191
- }
192
-
193
192
/// Sets a specific for all buckets.
194
193
///
195
194
/// This method overrides any existing prefix. (It does NOT
0 commit comments