Fix host resolution and concurrent cache updates

This commit is contained in:
Sebastian Unterschütz committed 2026-10-27 22:23:59 +01:00
1 parent 92b1c40cb8
commit fa7446e5f7
11 files changed
+648 -113

No files matched your search

+6
View File
@@ -351,6 +351,9 @@ func stripPrefix(cidr string) string {
return cidr
}
// ErrHostNotFound distinguishes a missing exact match from API failures or ambiguity.
var ErrHostNotFound = errors.New("host not found")
// FindHost refuses ambiguous names so writes cannot target an arbitrary server.
func (c *Client) FindHost(ctx context.Context, name, kind string) (HostEntry, error) {
if kind != "" && kind != "device" && kind != "vm" {
@@ -366,6 +369,9 @@ func (c *Client) FindHost(ctx context.Context, name, kind string) (HostEntry, er
matches = append(matches, e)
}
}
if len(matches) == 0 {
return HostEntry{}, fmt.Errorf("%w: %q", ErrHostNotFound, name)
}
if len(matches) != 1 {
return HostEntry{}, fmt.Errorf("host %q: found %d exact matches; use --kind or a unique hostname", name, len(matches))
}