@@ -41,47 +41,7 @@ async fn main() -> Result<(), ()> {
4141 . with ( EnvFilter :: from_default_env ( ) )
4242 . init ( ) ;
4343
44- // Ensure rustls has a single crypto provider selected at process start.
45- // When multiple crypto backends (ring, aws-lc-rs) are present the crate
46- // requires an explicit choice. Install the default provider now.
47- // Prefer the `ring` provider explicitly to avoid runtime ambiguity
48- // when multiple crypto backends are present in the dependency graph.
49- // Construct the provider from the `ring` module and install it.
50- let provider = rustls:: crypto:: ring:: default_provider ( ) ;
51- let _ = provider. install_default ( ) ;
52-
53- let mut config;
54- if args. config . exists ( ) {
55- config = Config :: read_from_file ( args. config ) . unwrap_or_else ( |( ) | std:: process:: exit ( 1 ) ) ;
56- } else {
57- tracing:: info!(
58- "No config file found at {}, creating a default config file." ,
59- args. config. display( )
60- ) ;
61- config = Config :: default ( ) ;
62-
63- let serialized_config =
64- toml:: to_string_pretty ( & config) . map_err ( |e| tracing:: error!( "Failed to serialize config: {e}" ) ) ?;
65-
66- let config_dir = args
67- . config
68- . parent ( )
69- . ok_or_else ( || tracing:: error!( "Failed to get parent directory of config file." ) ) ?;
70- std:: fs:: create_dir_all ( config_dir) . map_err ( |e| tracing:: error!( "Failed to create config directory: {e}" ) ) ?;
71- std:: fs:: write ( args. config , serialized_config)
72- . map_err ( |e| tracing:: error!( "Failed to save config file: {e}" ) ) ?;
73- }
74-
75- // Resolve these paths so that the rest of the code doesn't need to.
76- let cert_path = config. webserver . certificate . to_string_lossy ( ) . to_string ( ) ;
77- let cert_path =
78- shellexpand:: full ( & cert_path) . map_err ( |e| tracing:: error!( "Failed to expand certificate path: {e}" ) ) ?;
79- config. webserver . certificate = cert_path. to_string ( ) . into ( ) ;
80-
81- let private_key_path = config. webserver . private_key . to_string_lossy ( ) . to_string ( ) ;
82- let private_key_path =
83- shellexpand:: full ( & private_key_path) . map_err ( |e| tracing:: error!( "Failed to expand private key path: {e}" ) ) ?;
84- config. webserver . private_key = private_key_path. to_string ( ) . into ( ) ;
44+ let mut config = Config :: load_or_create ( & args. config ) . await ?;
8545
8646 tracing:: debug!( "Using configuration:\n {:#?}" , config) ;
8747
0 commit comments