@@ -3,7 +3,7 @@ use std::{fs::read_to_string, sync::Arc};
33use defguard_proxy:: {
44 config:: get_env_config,
55 grpc:: Configuration ,
6- http:: { run_server, run_setup , GRPC_CERT_NAME , GRPC_KEY_NAME } ,
6+ http:: { run_server, GRPC_CERT_NAME , GRPC_KEY_NAME } ,
77 logging:: init_tracing,
88 VERSION ,
99} ;
@@ -24,7 +24,16 @@ async fn main() -> anyhow::Result<()> {
2424 read_to_string ( cert_dir. join ( GRPC_KEY_NAME ) ) . ok ( ) ,
2525 ) ;
2626
27- let needs_setup = grpc_cert. is_none ( ) || grpc_key. is_none ( ) ;
27+ let proxy_configuration = if let ( Some ( grpc_cert) , Some ( grpc_key) ) = ( grpc_cert, grpc_key) {
28+ Some ( Configuration {
29+ grpc_cert_pem : grpc_cert,
30+ grpc_key_pem : grpc_key,
31+ } )
32+ } else {
33+ None
34+ } ;
35+
36+ let needs_setup = proxy_configuration. is_none ( ) ;
2837
2938 // TODO: The channel size may need to be adjusted or some other approach should be used
3039 // to avoid dropping log messages.
@@ -39,28 +48,13 @@ async fn main() -> anyhow::Result<()> {
3948 // read config from env
4049 tracing:: info!( "Starting ... version v{}" , VERSION ) ;
4150
42- let proxy_configuration = if needs_setup {
43- if let Some ( logs_rx) = logs_rx {
44- tracing:: info!( "gRPC certificates not found, running setup process" ) ;
45- let proxy_configuration = run_setup ( & env_config, Arc :: new ( Mutex :: new ( logs_rx) ) ) . await ?;
46- tracing:: info!( "Setup process completed successfully" ) ;
47- proxy_configuration
48- } else {
49- anyhow:: bail!(
50- "gRPC certificates not found and logs receiver not available for setup process"
51- ) ;
52- }
53- } else if let ( Some ( grpc_cert) , Some ( grpc_key) ) = ( grpc_cert, grpc_key) {
54- Configuration {
55- grpc_cert_pem : grpc_cert,
56- grpc_key_pem : grpc_key,
57- }
58- } else {
59- anyhow:: bail!( "Failed to load gRPC certificates" ) ;
60- } ;
61-
6251 // run API web server
63- run_server ( env_config, proxy_configuration) . await ?;
52+ run_server (
53+ env_config,
54+ proxy_configuration,
55+ logs_rx. map ( |r| Arc :: new ( Mutex :: new ( r) ) ) ,
56+ )
57+ . await ?;
6458
6559 Ok ( ( ) )
6660}
0 commit comments