@@ -56,6 +56,8 @@ pub enum ObjectStoreKind {
5656 client_secret : Option < String > ,
5757 region_name : String ,
5858 endpoint : Option < String > ,
59+ #[ serde( default , deserialize_with = "deserialize_bool" ) ]
60+ allow_invalid_certificates : Option < bool > ,
5961 } ,
6062 Azure {
6163 container_url : String ,
@@ -70,6 +72,12 @@ fn deserialize_u64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Option<
7072 ) )
7173}
7274
75+ fn deserialize_bool < ' de , D : Deserializer < ' de > > ( deserializer : D ) -> Result < Option < bool > , D :: Error > {
76+ Ok ( Some (
77+ String :: deserialize ( deserializer) ?. parse ( ) . expect ( "Expected a bool" ) ,
78+ ) )
79+ }
80+
7381#[ derive( Clone , Deserialize , Debug ) ]
7482pub struct ObjectStoreConfig {
7583 #[ serde( flatten) ]
@@ -115,6 +123,7 @@ impl ObjectStoreConfig {
115123 client_secret,
116124 region_name,
117125 endpoint,
126+ allow_invalid_certificates,
118127 } => {
119128 let mut builder = AmazonS3Builder :: from_env ( )
120129 . with_region ( region_name. clone ( ) )
@@ -130,8 +139,15 @@ impl ObjectStoreConfig {
130139 // This is needed for minio compatibility
131140 builder = builder. with_endpoint ( endpoint. clone ( ) . unwrap ( ) ) . with_allow_http ( true ) ;
132141 }
133- if let Some ( t) = self . timeout {
134- builder = builder. with_client_options ( ClientOptions :: new ( ) . with_timeout ( Duration :: from_secs ( t) ) ) ;
142+ if self . timeout . is_some ( ) || allow_invalid_certificates. is_some ( ) {
143+ let mut options = ClientOptions :: new ( ) ;
144+ if let Some ( t) = self . timeout {
145+ options = options. with_timeout ( Duration :: from_secs ( t) ) ;
146+ }
147+ if let Some ( allow_invalid_certificates) = allow_invalid_certificates {
148+ options = options. with_allow_invalid_certificates ( * allow_invalid_certificates) ;
149+ }
150+ builder = builder. with_client_options ( options) ;
135151 }
136152 Box :: new ( builder. build ( ) . unwrap ( ) )
137153 }
@@ -422,6 +438,8 @@ impl Settings {
422438mod tests {
423439 use std:: collections:: HashMap ;
424440
441+ use serde_json:: json;
442+
425443 use super :: * ;
426444
427445 #[ test]
@@ -442,4 +460,45 @@ mod tests {
442460 LogMergeSettings :: default ( ) . min_number_of_segments
443461 ) ;
444462 }
463+
464+ #[ test]
465+ fn test_s3_allow_invalid_certificates_default_is_none ( ) {
466+ let raw = json ! ( {
467+ "object_store" : "s3" ,
468+ "bucket" : "bucket" ,
469+ "region_name" : "us-east-1"
470+ } ) ;
471+ let config: ObjectStoreConfig = serde_json:: from_value ( raw) . unwrap ( ) ;
472+
473+ match config. kind {
474+ ObjectStoreKind :: S3 {
475+ allow_invalid_certificates,
476+ ..
477+ } => {
478+ assert_eq ! ( allow_invalid_certificates, None ) ;
479+ }
480+ _ => panic ! ( "Expected s3 object store kind" ) ,
481+ }
482+ }
483+
484+ #[ test]
485+ fn test_s3_allow_invalid_certificates_enabled ( ) {
486+ let raw = json ! ( {
487+ "object_store" : "s3" ,
488+ "bucket" : "bucket" ,
489+ "region_name" : "us-east-1" ,
490+ "allow_invalid_certificates" : "true"
491+ } ) ;
492+ let config: ObjectStoreConfig = serde_json:: from_value ( raw) . unwrap ( ) ;
493+
494+ match config. kind {
495+ ObjectStoreKind :: S3 {
496+ allow_invalid_certificates,
497+ ..
498+ } => {
499+ assert_eq ! ( allow_invalid_certificates, Some ( true ) ) ;
500+ }
501+ _ => panic ! ( "Expected s3 object store kind" ) ,
502+ }
503+ }
445504}
0 commit comments