Add service status and usage dashboard, refresh externally published edits

This commit is contained in:
2026-10-09 20:20:44 +01:00
parent 67ac79765f
commit a50e8648f6
31 changed files with 1283 additions and 42 deletions
+63
View File
@@ -0,0 +1,63 @@
package statusview
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
"net/url"
)
func Offline(endpoint string) *protocol.SystemStatus {
s := &protocol.SystemStatus{Server: protocol.ServiceStatus{Health: "unreachable"}, Ntfy: protocol.ServiceStatus{Health: "unknown (server unavailable)"}, Note: "Server information and ntfy configuration cannot be retrieved while disconnected."}
if u, err := url.Parse(endpoint); err == nil {
u.User = nil
u.RawQuery = ""
u.Fragment = ""
s.Server.URL = u.String()
s.Server.Port = u.Port()
}
return s
}
// Lines is shared by the plain CLI and TUI popup. No credentials are included.
func Lines(s *protocol.SystemStatus) []string {
if s == nil {
return []string{"No status returned by server."}
}
lines := []string{"Pipelines server", " Health: " + s.Server.Health}
if s.Hostname != "" {
lines = append(lines, " Host: "+s.Hostname, " Started: "+s.StartedAt+" · uptime "+s.Uptime)
}
lines = append(lines, " Connection: "+s.Server.URL, " Port: "+s.Server.Port, "", "ntfy", " Publishing health: "+s.Ntfy.Health)
if s.Ntfy.URL != "" {
lines = append(lines, " Phone server: "+s.Ntfy.URL)
}
if s.Topic != "" {
lines = append(lines, " Topic: "+s.Topic)
}
if s.Ntfy.Port != "" {
lines = append(lines, " Port: "+s.Ntfy.Port)
}
if s.Topic != "" && s.Ntfy.URL == "" {
lines = append(lines, " Phone address not configured (PIPELINES_NTFY_PUBLIC_URL).")
}
lines = append(lines, "", "Server computer IPs")
for _, address := range s.Addresses {
lines = append(lines, fmt.Sprintf(" %s · %s", address.Interface, address.IP))
}
if len(s.Addresses) == 0 {
lines = append(lines, " No address information available.")
}
if len(s.Server.Candidates) > 0 {
lines = append(lines, "", "Candidate Pipelines URLs (not verified)")
for _, candidate := range s.Server.Candidates {
lines = append(lines, " "+candidate)
}
}
if len(s.Ntfy.Candidates) > 0 {
lines = append(lines, "", "Candidate ntfy topic URLs (not verified)")
for _, candidate := range s.Ntfy.Candidates {
lines = append(lines, " "+candidate)
}
}
return append(lines, "", s.Note)
}
+21
View File
@@ -0,0 +1,21 @@
package statusview
import (
"strings"
"testing"
)
func TestOfflineStatusIncludesBothServicesAndRedactsURLCredentials(t *testing.T) {
s := Offline("ws://user:password@localhost:8080/connect?token=secret#secret")
text := strings.Join(Lines(s), "\n")
for _, secret := range []string{"password", "token=", "secret", "user:"} {
if strings.Contains(text, secret) {
t.Fatal("credentials exposed", text)
}
}
for _, expected := range []string{"Pipelines server", "unreachable", "ntfy", "unknown (server unavailable)", "8080"} {
if !strings.Contains(text, expected) {
t.Fatal("missing offline information", expected, text)
}
}
}