From bc9834c45981d868ffb2984e9fd610e36b8fa568 Mon Sep 17 00:00:00 2001 From: jackstar12 Date: Tue, 13 Aug 2024 10:48:05 +0200 Subject: [PATCH] plugins/grpc: grpc-host option A port should not be opened by default on 0.0.0.0, so change the default to localhost Changelog-Added: `grpc-host` option for grpc plugin --- plugins/grpc-plugin/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/grpc-plugin/src/main.rs b/plugins/grpc-plugin/src/main.rs index 3156b0ee7..4839ae5b5 100644 --- a/plugins/grpc-plugin/src/main.rs +++ b/plugins/grpc-plugin/src/main.rs @@ -23,6 +23,12 @@ const OPTION_GRPC_PORT: options::DefaultIntegerConfigOption = options::ConfigOpt "Which port should the grpc plugin listen for incoming connections?" ); +const OPTION_GRPC_HOST: options::DefaultStringConfigOption = options::ConfigOption::new_str_with_default( + "grpc-host", + "127.0.0.1", + "Which host should the grpc listen for incomming connections?" +); + const OPTION_GRPC_MSG_BUFFER_SIZE : options::DefaultIntegerConfigOption = options::ConfigOption::new_i64_with_default( "grpc-msg-buffer-size", 1024, @@ -36,6 +42,7 @@ async fn main() -> Result<()> { let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout()) .option(OPTION_GRPC_PORT) + .option(OPTION_GRPC_HOST) .option(OPTION_GRPC_MSG_BUFFER_SIZE) // TODO: Use the catch-all subscribe method // However, doing this breaks the plugin at the time begin @@ -55,6 +62,7 @@ async fn main() -> Result<()> { }; let bind_port: i64 = plugin.option(&OPTION_GRPC_PORT).unwrap(); + let bind_host: String = plugin.option(&OPTION_GRPC_HOST).unwrap(); let buffer_size: i64 = plugin.option(&OPTION_GRPC_MSG_BUFFER_SIZE).unwrap(); let buffer_size = match usize::try_from(buffer_size) { Ok(b) => b, @@ -79,7 +87,7 @@ async fn main() -> Result<()> { let plugin = plugin.start(state.clone()).await?; - let bind_addr: SocketAddr = format!("0.0.0.0:{}", bind_port).parse().unwrap(); + let bind_addr: SocketAddr = format!("{}:{}", bind_host, bind_port).parse().unwrap(); tokio::select! { _ = plugin.join() => {