mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-17 01:45:27 +02:00
fix: include hostname hints in metadata for API-side fallback
Send all available hostname sources (ComputerName, LocalHostName, HostName, os.Hostname) in the metadata map when provisioning. This allows the API to detect and repair generic hostnames like 'Mac' by picking the best available source server-side. Belt and suspenders: preferredHostname() picks the right one client-side, but metadata gives the API a second chance.
This commit is contained in:
@@ -24,3 +24,21 @@ func preferredHostname() (string, error) {
|
||||
}
|
||||
return os.Hostname()
|
||||
}
|
||||
|
||||
// hostnameHints returns all available hostname sources on macOS for
|
||||
// diagnostic/fallback purposes. The API can use these to pick the
|
||||
// best hostname if the primary one looks generic (e.g., "Mac").
|
||||
func hostnameHints() map[string]string {
|
||||
hints := make(map[string]string)
|
||||
for _, key := range []string{"ComputerName", "LocalHostName", "HostName"} {
|
||||
if out, err := exec.Command("scutil", "--get", key).Output(); err == nil {
|
||||
if name := strings.TrimSpace(string(out)); name != "" {
|
||||
hints[key] = name
|
||||
}
|
||||
}
|
||||
}
|
||||
if h, err := os.Hostname(); err == nil {
|
||||
hints["os.Hostname"] = h
|
||||
}
|
||||
return hints
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user