pub struct HealthCheckApiConfig { /* private fields */ }Expand description
Health Check API configuration with domain invariants enforced at construction
The Health Check API is a minimal HTTP endpoint used by Docker and container orchestration tools to verify service health. It’s separate from the main HTTP API.
This type guarantees that any instance is valid according to domain rules:
- Bind address has a non-zero port
- If TLS proxy is enabled, a domain is configured
- If TLS proxy is enabled, bind address is not localhost
§Construction
Use HealthCheckApiConfig::new() to create instances with validation:
use torrust_tracker_deployer_lib::domain::tracker::HealthCheckApiConfig;
use torrust_tracker_deployer_lib::shared::DomainName;
// Without TLS (typical for internal health checks)
let config = HealthCheckApiConfig::new(
"127.0.0.1:1313".parse().unwrap(),
None,
false,
)?;
// With TLS for external monitoring (requires domain)
let tls_config = HealthCheckApiConfig::new(
"0.0.0.0:1313".parse().unwrap(),
Some(DomainName::new("health.example.com")?),
true,
)?;§Invariants
The following invariants are enforced at construction time:
- No dynamic ports:
bind_address.port() != 0 - TLS requires domain:
use_tls_proxy == trueimpliesdomain.is_some() - No localhost with TLS:
use_tls_proxy == trueimplies!is_localhost(bind_address)
Implementations§
Source§impl HealthCheckApiConfig
impl HealthCheckApiConfig
Sourcepub fn new(
bind_address: SocketAddr,
domain: Option<DomainName>,
use_tls_proxy: bool,
) -> Result<Self, HealthCheckApiConfigError>
pub fn new( bind_address: SocketAddr, domain: Option<DomainName>, use_tls_proxy: bool, ) -> Result<Self, HealthCheckApiConfigError>
Creates a new Health Check API configuration with validation
This is the primary way to construct a HealthCheckApiConfig. All domain
invariants are validated before the instance is created.
§Arguments
bind_address- Socket address to bind to (e.g., “127.0.0.1:1313”)domain- Optional domain for TLS certificate (required ifuse_tls_proxyis true)use_tls_proxy- Whether to enable TLS via Caddy reverse proxy
§Errors
Returns HealthCheckApiConfigError if any invariant is violated:
DynamicPortNotSupported- if port is 0TlsProxyRequiresDomain- ifuse_tls_proxyis true butdomainis NoneLocalhostWithTls- ifuse_tls_proxyis true andbind_addressis localhost
§Examples
use torrust_tracker_deployer_lib::domain::tracker::HealthCheckApiConfig;
use torrust_tracker_deployer_lib::shared::DomainName;
// Basic configuration without TLS (typical)
let config = HealthCheckApiConfig::new(
"127.0.0.1:1313".parse().unwrap(),
None,
false,
)?;
// Configuration with TLS for external monitoring
let tls_config = HealthCheckApiConfig::new(
"0.0.0.0:1313".parse().unwrap(),
Some(DomainName::new("health.example.com")?),
true,
)?;Sourcepub fn bind_address(&self) -> SocketAddr
pub fn bind_address(&self) -> SocketAddr
Returns the bind address
Sourcepub fn domain(&self) -> Option<&DomainName>
pub fn domain(&self) -> Option<&DomainName>
Returns a reference to the domain, if configured
Sourcepub fn use_tls_proxy(&self) -> bool
pub fn use_tls_proxy(&self) -> bool
Returns whether TLS proxy is enabled
Sourcepub fn uses_tls_proxy(&self) -> bool
pub fn uses_tls_proxy(&self) -> bool
Returns true if this API uses the TLS proxy
Alias for use_tls_proxy() for semantic clarity.
Sourcepub fn tls_domain(&self) -> Option<&str>
pub fn tls_domain(&self) -> Option<&str>
Returns the TLS domain as a string if TLS proxy is configured
Returns None if TLS is disabled, even if a domain is configured.
This is useful for determining the effective TLS domain.
Trait Implementations§
Source§impl Clone for HealthCheckApiConfig
impl Clone for HealthCheckApiConfig
Source§impl Debug for HealthCheckApiConfig
impl Debug for HealthCheckApiConfig
Source§impl<'de> Deserialize<'de> for HealthCheckApiConfig
Enables deserialization with validation through the constructor
impl<'de> Deserialize<'de> for HealthCheckApiConfig
Enables deserialization with validation through the constructor
This ensures that JSON deserialization also validates the config, maintaining the “always valid” invariant even for loaded data.
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for HealthCheckApiConfig
impl Display for HealthCheckApiConfig
Source§impl PartialEq for HealthCheckApiConfig
impl PartialEq for HealthCheckApiConfig
Source§impl Serialize for HealthCheckApiConfig
impl Serialize for HealthCheckApiConfig
impl StructuralPartialEq for HealthCheckApiConfig
Source§impl TryFrom<HealthCheckApiSection> for HealthCheckApiConfig
Converts from application DTO to domain type using TryFrom trait
impl TryFrom<HealthCheckApiSection> for HealthCheckApiConfig
Converts from application DTO to domain type using TryFrom trait
This implementation follows the standard library convention for fallible
conversions, enabling use of .try_into() and TryFrom::try_from().
§Example
let section = HealthCheckApiSection {
bind_address: "127.0.0.1:1313".to_string(),
domain: None,
use_tls_proxy: None,
};
let config: HealthCheckApiConfig = section.try_into()?;Source§type Error = CreateConfigError
type Error = CreateConfigError
Auto Trait Implementations§
impl Freeze for HealthCheckApiConfig
impl RefUnwindSafe for HealthCheckApiConfig
impl Send for HealthCheckApiConfig
impl Sync for HealthCheckApiConfig
impl Unpin for HealthCheckApiConfig
impl UnsafeUnpin for HealthCheckApiConfig
impl UnwindSafe for HealthCheckApiConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = !
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.