pub struct DnsResolver;Expand description
DNS resolver for validating domain name resolution
Uses the system’s DNS resolver (std::net::ToSocketAddrs) to check if
domains resolve to expected IP addresses. This checks actual DNS configuration
including system DNS servers, /etc/hosts, and mDNS for .local domains.
§Examples
use std::net::IpAddr;
use torrust_tracker_deployer_lib::infrastructure::dns::DnsResolver;
use torrust_tracker_deployer_lib::shared::domain_name::DomainName;
let resolver = DnsResolver::new();
let domain = DomainName::new("tracker.local")?;
let expected_ip: IpAddr = "10.140.190.254".parse()?;
match resolver.resolve_and_verify(&domain, expected_ip) {
Ok(()) => println!("✓ Domain resolves correctly"),
Err(e) => eprintln!("⚠ DNS check failed: {}", e),
}Implementations§
Source§impl DnsResolver
impl DnsResolver
Sourcepub fn resolve(
&self,
domain: &DomainName,
) -> Result<Vec<IpAddr>, DnsResolutionError>
pub fn resolve( &self, domain: &DomainName, ) -> Result<Vec<IpAddr>, DnsResolutionError>
Sourcepub fn resolve_and_verify(
&self,
domain: &DomainName,
expected_ip: IpAddr,
) -> Result<(), DnsResolutionError>
pub fn resolve_and_verify( &self, domain: &DomainName, expected_ip: IpAddr, ) -> Result<(), DnsResolutionError>
Resolve a domain and verify it matches the expected IP address
This method resolves the domain and checks if any of the resolved IPs match the expected IP. It’s common for domains to resolve to multiple IPs (IPv4 and IPv6, or multiple servers).
§Arguments
domain- Domain name to resolve and verifyexpected_ip- Expected IP address
§Returns
Ok(()) if the domain resolves and matches the expected IP
§Errors
DnsResolutionError::ResolutionFailedif DNS resolution failsDnsResolutionError::IpMismatchif domain resolves but not to expected IP
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DnsResolver
impl RefUnwindSafe for DnsResolver
impl Send for DnsResolver
impl Sync for DnsResolver
impl Unpin for DnsResolver
impl UnsafeUnpin for DnsResolver
impl UnwindSafe for DnsResolver
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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>
Wrap the input message
T in a tonic::Request