@@ -3,6 +3,18 @@ use std::path::PathBuf;
33
44use clap:: Parser ;
55
6+ #[ derive( clap:: ValueEnum , Debug , Clone , Copy , PartialEq , Eq ) ]
7+ pub enum CertMode {
8+ /// No certificates at all, we serve http.
9+ None ,
10+ /// Use a self-signed certificate in the cert_path directory.
11+ Manual ,
12+ /// Use a letsencrypt certificate, in staging mode.
13+ LetsEncryptStaging ,
14+ /// Use a letsencrypt certificate, in production mode.
15+ LetsEncrypt ,
16+ }
17+
618#[ derive( Parser , Debug ) ]
719pub struct Args {
820 /// Ticket for the default node.
@@ -15,19 +27,32 @@ pub struct Args {
1527 pub default_node : Option < String > ,
1628
1729 /// Http or https listen addr.
18- ///
30+ ///
1931 /// Will listen on http if cert_path is not specified, https otherwise.
2032 #[ clap( long, default_value = "0.0.0.0:8080" ) ]
2133 pub addr : String ,
2234
23- /// Https certificate path.
24- ///
25- /// If this is specified, the server will listen on https.
26- /// The path should be a directory containing `cert.pem` and `key.pem`.
27- #[ clap( long) ]
28- pub cert_path : Option < PathBuf > ,
29-
3035 /// Magic port for the node, random if not specified.
3136 #[ clap( long) ]
3237 pub magic_port : Option < u16 > ,
38+
39+ /// Certificate mode, default is none.
40+ #[ clap( long, default_value = "None" ) ]
41+ pub cert_mode : CertMode ,
42+
43+ /// Hostnames for letsencrypt.
44+ #[ clap( long, required_if_eq_any( [ ( "cert_mode" , "LetsEncryptStaging" ) , ( "cert_mode" , "LetsEncrypt" ) ] ) ) ]
45+ pub hostname : Vec < String > ,
46+
47+ /// Contact email for letsencrypt.
48+ #[ clap( long, required_if_eq_any( [ ( "cert_mode" , "LetsEncryptStaging" ) , ( "cert_mode" , "LetsEncrypt" ) ] ) ) ]
49+ pub contact : Option < String > ,
50+
51+ /// Certificate path.
52+ ///
53+ /// Not needed if cert_mode is None.
54+ /// In manual mode, this is the directory containing the cert.pem and key.pem files.
55+ /// In letsencrypt mode, this is the directory used by the acme acceptor.
56+ #[ clap( long, required_if_eq_any( [ ( "cert_mode" , "LetsEncryptStaging" ) , ( "cert_mode" , "LetsEncrypt" ) , ( "cert_mode" , "Manual" ) ] ) ) ]
57+ pub cert_path : Option < PathBuf > ,
3358}
0 commit comments