From 94daf5ad5950bfed96f9622249505e9fc5bdff67 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 28 Aug 2023 15:48:00 +0000 Subject: [PATCH] zones: export Machine.LookupNetIP() and Machine.UpdatePublicAddresses() Signed-off-by: Alejandro Mery --- pkg/zones/machine_scan.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/zones/machine_scan.go b/pkg/zones/machine_scan.go index dca0c9d..52efe6e 100644 --- a/pkg/zones/machine_scan.go +++ b/pkg/zones/machine_scan.go @@ -7,8 +7,9 @@ import ( "time" ) -func (m *Machine) lookupNetIP() ([]netip.Addr, error) { - timeout := 2 * time.Second +// LookupNetIP uses the DNS Resolver to get the public addresses associated +// to a Machine +func (m *Machine) LookupNetIP(timeout time.Duration) ([]netip.Addr, error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -16,8 +17,9 @@ func (m *Machine) lookupNetIP() ([]netip.Addr, error) { return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName()) } -func (m *Machine) updatePublicAddresses() error { - addrs, err := m.lookupNetIP() +// UpdatePublicAddresses uses the DNS Resolver to set Machine.PublicAddresses +func (m *Machine) UpdatePublicAddresses() error { + addrs, err := m.LookupNetIP(2 * time.Second) if err != nil { return err } @@ -60,7 +62,7 @@ func (m *Machine) scan(opts *ScanOptions) error { } if !opts.DontResolvePublicAddresses { - return m.updatePublicAddresses() + return m.UpdatePublicAddresses() } return nil