@@ -129,14 +129,49 @@ async fn pool_controller(args: ArgMatches) -> anyhow::Result<()> {
129129 . expect ( "timeout value is invalid" )
130130 . into ( ) ;
131131
132- let cfg = clients:: tower:: Configuration :: new ( url, timeout, None , None , true , None ) . map_err (
133- |error| {
132+ let ca_certificate_path: Option < & str > = args
133+ . get_one :: < String > ( "tls-client-ca-path" )
134+ . map ( |x| x. as_str ( ) ) ;
135+ // take in cert path and make pem file
136+ let cert = match ca_certificate_path {
137+ Some ( path) => {
138+ let cert = std:: fs:: read ( path) . map_err ( |error| {
139+ anyhow:: anyhow!( "Failed to read certificate file, Error: '{:?}'" , error)
140+ } ) ?;
141+ Some ( cert)
142+ }
143+ None => None ,
144+ } ;
145+ let cfg = match ( url. scheme ( ) , cert) {
146+ ( "https" , Some ( cert) ) => clients:: tower:: Configuration :: new (
147+ url,
148+ timeout,
149+ None ,
150+ Some ( cert. as_slice ( ) ) ,
151+ true ,
152+ None ,
153+ )
154+ . map_err ( |error| {
134155 anyhow:: anyhow!(
135156 "Failed to create openapi configuration, Error: '{:?}'" ,
136157 error
137158 )
138- } ,
139- ) ?;
159+ } ) ?,
160+ ( "https" , None ) => {
161+ anyhow:: bail!( "HTTPS endpoint requires a CA certificate path" ) ;
162+ }
163+ ( _, Some ( _path) ) => {
164+ anyhow:: bail!( "CA certificate path is only supported for HTTPS endpoints" ) ;
165+ }
166+ _ => clients:: tower:: Configuration :: new ( url, timeout, None , None , true , None ) . map_err (
167+ |error| {
168+ anyhow:: anyhow!(
169+ "Failed to create openapi configuration, Error: '{:?}'" ,
170+ error
171+ )
172+ } ,
173+ ) ?,
174+ } ;
140175 let interval = args
141176 . get_one :: < String > ( "interval" )
142177 . unwrap ( )
@@ -243,6 +278,11 @@ async fn main() -> anyhow::Result<()> {
243278 . value_parser ( clap:: value_parser!( bool ) )
244279 . help ( "Enable ansi color for logs" ) ,
245280 )
281+ . arg (
282+ Arg :: new ( "tls-client-ca-path" )
283+ . long ( "tls-client-ca-path" )
284+ . help ( "path to the CA certificate file" ) ,
285+ )
246286 . get_matches ( ) ;
247287
248288 utils:: print_package_info!( ) ;
0 commit comments