@@ -2,6 +2,7 @@ use std::pin::Pin;
22
33use async_stream:: stream;
44use clp_rust_utils:: {
5+ aws:: AWS_DEFAULT_REGION ,
56 clp_config:: {
67 AwsAuthentication ,
78 package:: {
@@ -161,6 +162,7 @@ impl Client {
161162 /// * Forwards [`Client::get_status`]'s return values on failure.
162163 /// * Forwards [`Client::get_job_config`]'s return values on failure.
163164 /// * Forwards [`Client::fetch_results_from_mongo`]'s return values on failure.
165+ /// * Forwards [`Client::fetch_results_from_s3`]'s return values on failure.
164166 pub async fn fetch_results (
165167 & self ,
166168 search_job_id : u64 ,
@@ -197,7 +199,7 @@ impl Client {
197199 inner : self . fetch_results_from_file ( search_job_id) ,
198200 } ,
199201 StreamOutputStorage :: S3 { .. } => SearchResultStream :: S3 {
200- inner : self . fetch_results_from_s3 ( search_job_id) . await ,
202+ inner : self . fetch_results_from_s3 ( search_job_id) . await ? ,
201203 } ,
202204 } ;
203205 return Ok ( stream) ;
@@ -311,13 +313,20 @@ impl Client {
311313 /// * Forwards [`aws_smithy_types::byte_stream::ByteStream::collect`]'s return values on
312314 /// failure.
313315 ///
316+ /// # Errors
317+ ///
318+ /// Return an error if:
319+ ///
320+ /// * [`ClientError::Aws`] if a region code is not provided when using the default AWS S3
321+ /// endpoint.
322+ ///
314323 /// # Panics
315324 ///
316325 /// Panics if the stream output storage is not S3.
317326 async fn fetch_results_from_s3(
318327 & self ,
319328 search_job_id : u64 ,
320- ) -> impl Stream < Item = Result < String , ClientError > > + use <> {
329+ ) -> Result < impl Stream < Item = Result < String , ClientError > > + use <> , ClientError > {
321330 tracing:: info!( "Streaming results from S3" ) ;
322331 let StreamOutputStorage :: S3 { s3_config, .. } = & self . config . stream_output . storage else {
323332 unreachable ! ( ) ;
@@ -326,13 +335,22 @@ impl Client {
326335 let AwsAuthentication :: Credentials { credentials } = & s3_config. aws_authentication ;
327336
328337 let s3_config = s3_config. clone ( ) ;
329- let credentials = credentials. clone ( ) ;
338+ if s3_config. region_code . is_none ( ) && s3_config. endpoint_url . is_none ( ) {
339+ return Err ( ClientError :: Aws {
340+ description : "a region code must be given when using the default AWS S3 endpoint"
341+ . to_owned ( ) ,
342+ } ) ;
343+ }
330344
345+ let credentials = credentials. clone ( ) ;
331346 let s3_client = clp_rust_utils:: s3:: create_new_client (
332- s3_config. region_code . as_str ( ) ,
333347 credentials. access_key_id . as_str ( ) ,
334348 credentials. secret_access_key . as_str ( ) ,
335- None ,
349+ s3_config
350+ . region_code
351+ . as_ref ( )
352+ . map_or ( AWS_DEFAULT_REGION , non_empty_string:: NonEmptyString :: as_str) ,
353+ s3_config. endpoint_url . as_ref ( ) ,
336354 )
337355 . await ;
338356
@@ -345,7 +363,7 @@ impl Client {
345363 . into_paginator ( )
346364 . send ( ) ;
347365
348- stream ! {
366+ Ok ( stream ! {
349367 while let Some ( object_page) = object_pages. next( ) . await {
350368 tracing:: debug!( "Received S3 object page: {:?}" , object_page) ;
351369 for object in object_page?. contents( ) {
@@ -372,7 +390,7 @@ impl Client {
372390 }
373391 }
374392 }
375- }
393+ } )
376394 }
377395
378396 /// Asynchronously fetches results of a completed search job from `MongoDB`.
0 commit comments