configure owner api listen address

This commit is contained in:
wiesche
2026-09-01 14:21:14 +02:00
parent 21d9508241
commit d13664574d
4 changed files with 31 additions and 22 deletions
+5
View File
@@ -53,6 +53,11 @@ fn comments() -> HashMap<String, String> {
retval.insert( retval.insert(
"owner_api_listen_port".to_string(), "owner_api_listen_port".to_string(),
" "
#owner api address, for example 0.0.0.0:3420 for docker
#overrides owner_api_listen_port when set
#do not expose the owner api to an untrusted network
#owner_api_listen_addr = \"127.0.0.1:3420\"
#port for wallet owner api #port for wallet owner api
" "
.to_string(), .to_string(),
+22 -21
View File
@@ -28,9 +28,9 @@ pub struct WalletConfig {
pub chain_type: Option<ChainTypes>, pub chain_type: Option<ChainTypes>,
/// The port this wallet will run on /// The port this wallet will run on
pub api_listen_port: u16, pub api_listen_port: u16,
/// Listen interface for the owner API, should be hidden from config by default /// Address this wallet's owner API will listen on
#[serde(skip_serializing)] #[serde(skip_serializing_if = "Option::is_none")]
pub owner_api_listen_interface: Option<String>, pub owner_api_listen_addr: Option<String>,
/// The port this wallet's owner API will run on /// The port this wallet's owner API will run on
pub owner_api_listen_port: Option<u16>, pub owner_api_listen_port: Option<u16>,
/// Location of the secret for basic auth on the Owner API /// Location of the secret for basic auth on the Owner API
@@ -66,7 +66,7 @@ impl Default for WalletConfig {
WalletConfig { WalletConfig {
chain_type: Some(ChainTypes::Mainnet), chain_type: Some(ChainTypes::Mainnet),
api_listen_port: 3415, api_listen_port: 3415,
owner_api_listen_interface: Some(WalletConfig::default_owner_api_listen_interface()), owner_api_listen_addr: None,
owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()), owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()),
api_secret_path: Some(".owner_api_secret".to_string()), api_secret_path: Some(".owner_api_secret".to_string()),
node_api_secret_path: Some(".foreign_api_secret".to_string()), node_api_secret_path: Some(".foreign_api_secret".to_string()),
@@ -92,11 +92,6 @@ impl WalletConfig {
format!("127.0.0.1:{}", self.api_listen_port) format!("127.0.0.1:{}", self.api_listen_port)
} }
/// Default listener port
pub fn default_owner_api_listen_interface() -> String {
"127.0.0.1".to_string()
}
/// Default listener port /// Default listener port
pub fn default_owner_api_listen_port() -> u16 { pub fn default_owner_api_listen_port() -> u16 {
3420 3420
@@ -107,13 +102,6 @@ impl WalletConfig {
500_000 500_000
} }
/// Use value from config file, defaulting to sensible value if missing.
pub fn owner_api_listen_interface(&self) -> String {
self.owner_api_listen_interface
.clone()
.unwrap_or_else(|| WalletConfig::default_owner_api_listen_interface())
}
/// Use value from config file, defaulting to sensible value if missing. /// Use value from config file, defaulting to sensible value if missing.
pub fn owner_api_listen_port(&self) -> u16 { pub fn owner_api_listen_port(&self) -> u16 {
self.owner_api_listen_port self.owner_api_listen_port
@@ -122,11 +110,9 @@ impl WalletConfig {
/// Owner API listen address /// Owner API listen address
pub fn owner_api_listen_addr(&self) -> String { pub fn owner_api_listen_addr(&self) -> String {
format!( self.owner_api_listen_addr
"{}:{}", .clone()
self.owner_api_listen_interface(), .unwrap_or_else(|| format!("127.0.0.1:{}", self.owner_api_listen_port()))
self.owner_api_listen_port()
)
} }
/// Accept fee base /// Accept fee base
@@ -144,6 +130,21 @@ impl WalletConfig {
) )
} }
} }
#[cfg(test)]
mod tests {
use super::WalletConfig;
#[test]
fn owner_api_address() {
let mut config = WalletConfig::default();
assert_eq!(config.owner_api_listen_addr(), "127.0.0.1:3420");
config.owner_api_listen_addr = Some("0.0.0.0:3420".to_string());
assert_eq!(config.owner_api_listen_addr(), "0.0.0.0:3420");
}
}
/// Error type wrapping config errors. /// Error type wrapping config errors.
#[derive(Debug)] #[derive(Debug)]
pub enum ConfigError { pub enum ConfigError {
+3 -1
View File
@@ -240,7 +240,9 @@ where
let mut apis = ApiServer::new(); let mut apis = ApiServer::new();
warn!("Starting HTTP Owner API server at {}.", addr); warn!("Starting HTTP Owner API server at {}.", addr);
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address"); let socket_addr: SocketAddr = addr
.parse()
.map_err(|_| Error::GenericError(format!("Invalid owner API address: {}", addr)))?;
let api_thread = apis let api_thread = apis
.start(socket_addr, router, tls_config, api_chan) .start(socket_addr, router, tls_config, api_chan)
.map_err(|_| Error::GenericError("API thread failed to start".to_string()))?; .map_err(|_| Error::GenericError("API thread failed to start".to_string()))?;
+1
View File
@@ -410,6 +410,7 @@ pub fn parse_owner_api_args(
args: &ArgMatches, args: &ArgMatches,
) -> Result<(), ParseError> { ) -> Result<(), ParseError> {
if let Some(port) = args.value_of("port") { if let Some(port) = args.value_of("port") {
config.owner_api_listen_addr = None;
config.owner_api_listen_port = Some(port.parse().unwrap()); config.owner_api_listen_port = Some(port.parse().unwrap());
} }
if args.is_present("run_foreign") { if args.is_present("run_foreign") {