Add hostname editing feature to agent detail page
- Create enhanced agent detail template with all stats and hostname edit form
- Add UpdateHostname method to store for agent hostname updates
- Add UpdateAgentHostname handler in UI for web form submissions
- Add UpdateHostname endpoint in API handler for JSON requests
- Register new POST /agents/{id}/hostname route for hostname updates
- Improve agent detail page layout with Settings and Danger Zone sections
- Add error handling for missing agents and empty hostname values
This commit is contained in:
@@ -73,3 +73,32 @@ func (h *Handler) DeleteAgent(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "deleted"})
|
||||
}
|
||||
|
||||
// UpdateHostname updates the hostname for an agent.
|
||||
func (h *Handler) UpdateHostname(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
agentID := r.PathValue("id")
|
||||
if agentID == "" {
|
||||
http.Error(w, "missing agent id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
hostname := r.FormValue("hostname")
|
||||
if hostname == "" {
|
||||
http.Error(w, "missing hostname", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err := h.store.UpdateHostname(agentID, hostname)
|
||||
if err != nil {
|
||||
http.Error(w, "agent not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "updated"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user