mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-18 00:17:39 +01:00
refactor: Remove dead HandleTestExistingNode function
This function was superseded by HandleTestNode which is wired to the
router at /api/config/nodes/{id}/test. The old function was not
registered in the router and served no purpose.
Removes 121 lines of unused code.
This commit is contained in:
@@ -2329,129 +2329,6 @@ func (h *ConfigHandlers) triggerPVEHostCleanup(host string) {
|
||||
Msg("Queued PVE host cleanup via sensor proxy")
|
||||
}
|
||||
|
||||
// HandleTestExistingNode tests a connection for an existing node using stored credentials
|
||||
func (h *ConfigHandlers) HandleTestExistingNode(w http.ResponseWriter, r *http.Request) {
|
||||
nodeID := strings.TrimPrefix(r.URL.Path, "/api/config/nodes/")
|
||||
nodeID = strings.TrimSuffix(nodeID, "/test")
|
||||
if nodeID == "" {
|
||||
http.Error(w, "Node ID required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse node ID
|
||||
parts := strings.Split(nodeID, "-")
|
||||
if len(parts) != 2 {
|
||||
http.Error(w, "Invalid node ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
nodeType := parts[0]
|
||||
index := 0
|
||||
if _, err := fmt.Sscanf(parts[1], "%d", &index); err != nil {
|
||||
http.Error(w, "Invalid node ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get the node configuration
|
||||
var host, user, password, tokenName, tokenValue, fingerprint string
|
||||
var verifySSL bool
|
||||
|
||||
if nodeType == "pve" && index < len(h.config.PVEInstances) {
|
||||
pve := h.config.PVEInstances[index]
|
||||
host = pve.Host
|
||||
user = pve.User
|
||||
password = pve.Password
|
||||
tokenName = pve.TokenName
|
||||
tokenValue = pve.TokenValue
|
||||
fingerprint = pve.Fingerprint
|
||||
verifySSL = pve.VerifySSL
|
||||
} else if nodeType == "pbs" && index < len(h.config.PBSInstances) {
|
||||
pbs := h.config.PBSInstances[index]
|
||||
host = pbs.Host
|
||||
user = pbs.User
|
||||
password = pbs.Password
|
||||
tokenName = pbs.TokenName
|
||||
tokenValue = pbs.TokenValue
|
||||
fingerprint = pbs.Fingerprint
|
||||
verifySSL = pbs.VerifySSL
|
||||
} else {
|
||||
http.Error(w, "Node not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Test the connection based on type
|
||||
if nodeType == "pve" {
|
||||
clientConfig := proxmox.ClientConfig{
|
||||
Host: host,
|
||||
User: user,
|
||||
Password: password,
|
||||
TokenName: tokenName,
|
||||
TokenValue: tokenValue,
|
||||
VerifySSL: verifySSL,
|
||||
Fingerprint: fingerprint,
|
||||
}
|
||||
|
||||
tempClient, err := proxmox.NewClient(clientConfig)
|
||||
if err != nil {
|
||||
http.Error(w, sanitizeErrorMessage(err, "create_client"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
nodes, err := tempClient.GetNodes(ctx)
|
||||
if err != nil {
|
||||
http.Error(w, sanitizeErrorMessage(err, "connection"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"message": fmt.Sprintf("Successfully connected to %d node(s)", len(nodes)),
|
||||
"nodeCount": len(nodes),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
} else {
|
||||
// PBS test
|
||||
clientConfig := pbs.ClientConfig{
|
||||
Host: host,
|
||||
User: user,
|
||||
Password: password,
|
||||
TokenName: tokenName,
|
||||
TokenValue: tokenValue,
|
||||
VerifySSL: verifySSL,
|
||||
Fingerprint: fingerprint,
|
||||
}
|
||||
|
||||
tempClient, err := pbs.NewClient(clientConfig)
|
||||
if err != nil {
|
||||
http.Error(w, sanitizeErrorMessage(err, "create_client"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
datastores, err := tempClient.GetDatastores(ctx)
|
||||
if err != nil {
|
||||
http.Error(w, sanitizeErrorMessage(err, "connection"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"message": fmt.Sprintf("Successfully connected. Found %d datastore(s)", len(datastores)),
|
||||
"datastoreCount": len(datastores),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleTestNodeConfig tests a node connection from provided configuration
|
||||
func (h *ConfigHandlers) HandleTestNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
var req NodeConfigRequest
|
||||
|
||||
Reference in New Issue
Block a user