@@ -31,7 +31,7 @@ use kube::{
3131use mayastorpool:: client:: { check_crd, delete, list} ;
3232use openapi:: clients:: { self , tower:: Url } ;
3333use std:: { collections:: HashMap , sync:: Arc , time:: Duration } ;
34- use tracing:: { error, info, trace, warn} ;
34+ use tracing:: { debug , error, info, trace, warn} ;
3535use utils:: tracing_telemetry:: { FmtLayer , FmtStyle } ;
3636
3737const PAGINATION_LIMIT : u32 = 100 ;
@@ -129,14 +129,51 @@ 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| {
134- anyhow:: anyhow!(
135- "Failed to create openapi configuration, Error: '{:?}'" ,
136- 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) . expect ( "Failed to read certificate file" ) ;
139+ Some ( cert)
140+ }
141+ None => None ,
142+ } ;
143+ let cfg = match ( url. scheme ( ) , cert) {
144+ ( "https" , Some ( cert) ) => {
145+ debug ! ( "Attempting TLS connection to {}" , url) ;
146+
147+ clients:: tower:: Configuration :: new (
148+ url,
149+ timeout,
150+ None ,
151+ Some ( cert. as_slice ( ) ) ,
152+ true ,
153+ None ,
137154 )
138- } ,
139- ) ?;
155+ . map_err ( |error| {
156+ anyhow:: anyhow!(
157+ "Failed to create openapi configuration, Error: '{:?}'" ,
158+ error
159+ )
160+ } ) ?
161+ }
162+ ( "https" , None ) => {
163+ anyhow:: bail!( "HTTPS endpoint requires a CA certificate path" ) ;
164+ }
165+ ( _, Some ( _path) ) => {
166+ anyhow:: bail!( "CA certificate path is only supported for HTTPS endpoints" ) ;
167+ }
168+ _ => clients:: tower:: Configuration :: new ( url, timeout, None , None , true , None ) . map_err (
169+ |error| {
170+ anyhow:: anyhow!(
171+ "Failed to create openapi configuration, Error: '{:?}'" ,
172+ error
173+ )
174+ } ,
175+ ) ?,
176+ } ;
140177 let interval = args
141178 . get_one :: < String > ( "interval" )
142179 . unwrap ( )
@@ -243,6 +280,11 @@ async fn main() -> anyhow::Result<()> {
243280 . value_parser ( clap:: value_parser!( bool ) )
244281 . help ( "Enable ansi color for logs" ) ,
245282 )
283+ . arg (
284+ Arg :: new ( "tls-client-ca-path" )
285+ . long ( "tls-client-ca-path" )
286+ . help ( "path to the CA certificate file" ) ,
287+ )
246288 . get_matches ( ) ;
247289
248290 utils:: print_package_info!( ) ;
0 commit comments