Show protocol enable state and which nodes have each protocol installed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-29 04:18:09 +03:00
co-authored by Cursor
parent 6510de0214
commit 1ad5125bf4
12 changed files with 745 additions and 67 deletions
+41 -5
View File
@@ -1,6 +1,7 @@
package nodeclient
import (
"bytes"
"encoding/json"
"fmt"
"io"
@@ -11,11 +12,13 @@ import (
)
type HealthResponse struct {
OK bool `json:"ok"`
Name string `json:"name"`
Version string `json:"version"`
Uptime int64 `json:"uptime_sec"`
Protocols []string `json:"protocols"`
OK bool `json:"ok"`
Name string `json:"name"`
Version string `json:"version"`
Uptime int64 `json:"uptime_sec"`
Protocols []string `json:"protocols"`
ProtocolsInstalled []string `json:"protocols_installed"`
ProtocolsEnabled []string `json:"protocols_enabled"`
}
func Health(n *models.Node) (*HealthResponse, error) {
@@ -40,5 +43,38 @@ func Health(n *models.Node) (*HealthResponse, error) {
if err := json.Unmarshal(body, &hr); err != nil {
return nil, err
}
// Fallback: older agents only expose protocols as enabled list.
if len(hr.ProtocolsEnabled) == 0 && len(hr.Protocols) > 0 {
hr.ProtocolsEnabled = hr.Protocols
}
if len(hr.ProtocolsInstalled) == 0 && len(hr.ProtocolsEnabled) > 0 {
hr.ProtocolsInstalled = append([]string{}, hr.ProtocolsEnabled...)
}
return &hr, nil
}
func PushConfig(n *models.Node, cfg map[string]any) error {
payload, err := json.Marshal(cfg)
if err != nil {
return err
}
url := fmt.Sprintf("http://%s:%d/api/v1/config", n.Host, n.NodePort)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload))
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+n.SecretKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 12 * time.Second}
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
return fmt.Errorf("status %d: %s", res.StatusCode, string(body))
}
return nil
}