@@ -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:: { error, info, trace, warn, debug } ;
3535use utils:: tracing_telemetry:: { FmtLayer , FmtStyle } ;
3636
3737const PAGINATION_LIMIT : u32 = 100 ;
@@ -129,14 +129,47 @@ 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
137- )
132+ let ca_certificate_path : Option < & str > = args . get_one :: < String > ( "tls-client-ca-path" ) . map ( |x| x . as_str ( ) ) ;
133+ // take in cert path and make pem file
134+ let cert = match ca_certificate_path {
135+ Some ( path ) => {
136+ let cert = std :: fs :: read ( path ) . expect ( "Failed to read certificate file" ) ;
137+ Some ( cert )
138138 } ,
139- ) ?;
139+ None => None ,
140+ } ;
141+ let cfg = match ( url. scheme ( ) , cert) {
142+ ( "https" , Some ( cert) ) => {
143+ debug ! ( "Attempting TLS connection to {}" , url) ;
144+
145+ clients:: tower:: Configuration :: new ( url, timeout, None , Some ( cert. as_slice ( ) ) , true , None )
146+ . map_err (
147+ |error| {
148+ anyhow:: anyhow!(
149+ "Failed to create openapi configuration, Error: '{:?}'" ,
150+ error
151+ )
152+ } ,
153+ ) ?
154+ } ,
155+ ( "https" , None ) => {
156+ anyhow:: bail!( "HTTPS endpoint requires a CA certificate path" ) ;
157+ } ,
158+ ( _, Some ( _path) ) => {
159+ anyhow:: bail!( "CA certificate path is only supported for HTTPS endpoints" ) ;
160+ } ,
161+ _ => {
162+ clients:: tower:: Configuration :: new ( url, timeout, None , None , true , None )
163+ . map_err (
164+ |error| {
165+ anyhow:: anyhow!(
166+ "Failed to create openapi configuration, Error: '{:?}'" ,
167+ error
168+ )
169+ } ,
170+ ) ?
171+ }
172+ } ;
140173 let interval = args
141174 . get_one :: < String > ( "interval" )
142175 . unwrap ( )
@@ -243,6 +276,11 @@ async fn main() -> anyhow::Result<()> {
243276 . value_parser ( clap:: value_parser!( bool ) )
244277 . help ( "Enable ansi color for logs" ) ,
245278 )
279+ . arg (
280+ Arg :: new ( "tls-client-ca-path" )
281+ . long ( "tls-client-ca-path" )
282+ . help ( "path to the CA certificate file" ) ,
283+ )
246284 . get_matches ( ) ;
247285
248286 utils:: print_package_info!( ) ;
0 commit comments