Remove unused hostname_prefix from server types and add duplicate checking
The HostnamePrefix field on ServerType was loaded from YAML but never used — hostnames are user-provided. This removes the field and adds explicit duplicate checks (hostname + MAC) with clear per-field error messages in both the JSON API and web UI, backed by a new GetByHostname store method with case-insensitive matching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,14 @@ func (a *HostAPI) Create(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSONErr(w, http.StatusBadRequest, "unknown server_type")
|
||||
return
|
||||
}
|
||||
if existing, err := a.Hosts.GetByHostname(r.Context(), req.Hostname); err == nil && existing != nil {
|
||||
writeJSONErr(w, http.StatusConflict, "a host with this hostname already exists")
|
||||
return
|
||||
}
|
||||
if existing, err := a.Hosts.GetByMAC(r.Context(), req.MAC); err == nil && existing != nil {
|
||||
writeJSONErr(w, http.StatusConflict, "a host with this MAC address already exists")
|
||||
return
|
||||
}
|
||||
|
||||
id, err := a.Hosts.Create(r.Context(), model.Host{
|
||||
Hostname: req.Hostname,
|
||||
|
||||
Reference in New Issue
Block a user