File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use std:: { fs:: read_to_string, path:: PathBuf } ;
1+ use std:: { fs:: read_to_string, net :: IpAddr , path:: PathBuf } ;
22
33use clap:: Parser ;
44use log:: LevelFilter ;
@@ -53,6 +53,12 @@ pub struct Config {
5353 #[ arg( long = "config" , short) ]
5454 #[ serde( skip) ]
5555 config_path : Option < PathBuf > ,
56+
57+ #[ arg( long, env = "DEFGUARD_HTTP_BIND_ADDRESS" ) ]
58+ pub http_bind_address : Option < IpAddr > ,
59+
60+ #[ arg( long, env = "DEFGUARD_GRPC_BIND_ADDRESS" ) ]
61+ pub grpc_bind_address : Option < IpAddr > ,
5662}
5763
5864#[ derive( thiserror:: Error , Debug ) ]
Original file line number Diff line number Diff line change @@ -149,7 +149,12 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
149149 // Start gRPC server.
150150 debug ! ( "Spawning gRPC server" ) ;
151151 tasks. spawn ( async move {
152- let addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , config. grpc_port ) ;
152+ let addr = SocketAddr :: new (
153+ config
154+ . grpc_bind_address
155+ . unwrap_or ( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ) ,
156+ config. grpc_port ,
157+ ) ;
153158 info ! ( "gRPC server is listening on {addr}" ) ;
154159 let mut builder = if let ( Some ( cert) , Some ( key) ) = ( grpc_cert, grpc_key) {
155160 let identity = Identity :: from_pem ( cert, key) ;
@@ -244,7 +249,12 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
244249 // Start web server.
245250 debug ! ( "Spawning API web server" ) ;
246251 tasks. spawn ( async move {
247- let addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , config. http_port ) ;
252+ let addr = SocketAddr :: new (
253+ config
254+ . http_bind_address
255+ . unwrap_or ( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ) ,
256+ config. http_port ,
257+ ) ;
248258 let listener = TcpListener :: bind ( & addr) . await ?;
249259 info ! ( "API web server is listening on {addr}" ) ;
250260 serve (
You can’t perform that action at this time.
0 commit comments