Skip to content

Commit b5c7950

Browse files
committed
refactor: [#852] eenrich field types in HealthCheckApi config struct
1 parent a20c9d7 commit b5c7950

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

packages/configuration/src/v1/health_check_api.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
2+
13
use serde::{Deserialize, Serialize};
24
use serde_with::serde_as;
35

@@ -9,13 +11,13 @@ pub struct HealthCheckApi {
911
/// The format is `ip:port`, for example `127.0.0.1:1313`. If you want to
1012
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
1113
/// system to choose a random port, use port `0`.
12-
pub bind_address: String,
14+
pub bind_address: SocketAddr,
1315
}
1416

1517
impl Default for HealthCheckApi {
1618
fn default() -> Self {
1719
Self {
18-
bind_address: String::from("127.0.0.1:1313"),
20+
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1313),
1921
}
2022
}
2123
}

packages/test-helpers/src/configuration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tracker configuration factories for testing.
22
use std::env;
3-
use std::net::IpAddr;
3+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
44

55
use torrust_tracker_configuration::Configuration;
66
use torrust_tracker_primitives::TrackerMode;
@@ -39,7 +39,7 @@ pub fn ephemeral() -> Configuration {
3939

4040
// Ephemeral socket address for Health Check API
4141
let health_check_api_port = 0u16;
42-
config.health_check_api.bind_address = format!("127.0.0.1:{}", &health_check_api_port);
42+
config.health_check_api.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), health_check_api_port);
4343

4444
// Ephemeral socket address for UDP tracker
4545
let udp_port = 0u16;

src/bootstrap/jobs/health_check_api.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ use crate::servers::signals::Halted;
3535
///
3636
/// It would panic if unable to send the `ApiServerJobStarted` notice.
3737
pub async fn start_job(config: &HealthCheckApi, register: ServiceRegistry) -> JoinHandle<()> {
38-
let bind_addr = config
39-
.bind_address
40-
.parse::<std::net::SocketAddr>()
41-
.expect("it should have a valid health check bind address");
38+
let bind_addr = config.bind_address;
4239

4340
let (tx_start, rx_start) = oneshot::channel::<Started>();
4441
let (tx_halt, rx_halt) = tokio::sync::oneshot::channel::<Halted>();

tests/servers/health_check_api/environment.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ pub struct Environment<S> {
3333

3434
impl Environment<Stopped> {
3535
pub fn new(config: &Arc<HealthCheckApi>, registar: Registar) -> Self {
36-
let bind_to = config
37-
.bind_address
38-
.parse::<std::net::SocketAddr>()
39-
.expect("Tracker API bind_address invalid.");
36+
let bind_to = config.bind_address;
4037

4138
Self {
4239
registar,

0 commit comments

Comments
 (0)