hub (unreleased): the end dates of the hub's own public names are read once a day; 14 days before, the operator is told (D85, R-1379)

The names are the setting HUB_OWN_NAMES; with no setting the hub makes no call. The setting is NOT in the manifest yet.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 15:22:49 +01:00
1 parent c616727d84
commit c72ecf52b4
8 files changed
+616 -5

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
package main
import (
"os"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-hub/internal/monitor"
"gitea.dooplex.hu/admin/felhom-hub/internal/notify"
)
// D85 (R-1379): the own-names check is a component with a seam; unit-green and never called is the inert-seam defect.
// Read from main.go: the names come from the HUB_OWN_NAMES setting (never a literal list in code), the real dial is
// handed in, the job runs on the daily scheduler under the name the ledger watches, and no setting means no job.
func TestD85_MainWiresTheOwnNamesCheck(t *testing.T) {
b, err := os.ReadFile("main.go")
if err != nil {
t.Fatal(err)
}
src := string(b)
for _, want := range []string{
`monitor.ParseOwnNames(os.Getenv("HUB_OWN_NAMES"))`,
`monitor.NewOwnNameChecker(names, monitor.DialCertEnd, dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)`,
`go scheduleDaily(ctx, ownNamesJob, "06:40", ownNames.CheckOnce, logger)`,
`"deadline-check", "offsite-key-audit", ownNamesJob)`,
} {
if strings.Count(src, want) != 1 {
t.Errorf("main.go: want exactly one %q, found %d", want, strings.Count(src, want))
}
}
// the list is configuration, not code: no public name of the hub is written in main.go
for _, name := range []string{"hub.felhom.eu", "iso.felhom.eu", "files.felhom.eu"} {
if strings.Contains(src, name) {
t.Errorf("main.go names %s in code — the list of own names must come from the setting", name)
}
}
// the job is started only inside the „names were given” branch
at, job := strings.Index(src, `if len(names) > 0 {`+"\n\t\t\townNames :="), strings.Index(src, `go scheduleDaily(ctx, ownNamesJob`)
if at < 0 || job < at {
t.Error("the own-names job is not started inside the branch that has names — an empty setting would start it")
}
}
// The three events are the operator's only, and each NAME has its own mail (not one per type per hour).
func TestD85_TheEventsAreOperatorOnlyAndPerName(t *testing.T) {
for _, typ := range []string{monitor.EventHubNameEndsSoon, monitor.EventHubNameUnreachable, monitor.EventHubNameReachable} {
if !notify.IsOperatorOnly(typ) {
t.Errorf("%s is not operator-only: a household could get a mail about the hub's own names", typ)
}
if !notify.HasPerSubjectCooldown(typ) {
t.Errorf("%s has no per-name cooldown: the second name of the same day would be suppressed and never told again", typ)
}
}
}
+20 -1
View File
@@ -372,7 +372,7 @@ func main() {
}
// (1) a daily check whose slot passed while the hub was down — told at this start.
dailyLedger = monitor.NewDailyLedger(dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger,
"deadline-check", "offsite-key-audit")
"deadline-check", "offsite-key-audit", ownNamesJob)
// MAIL-HOLD (internal/mailhold): while <data_dir>/MAIL-HOLD exists the hub sends NO e-mail on any path —
// dispatcher, /notify, app-mail relay. A hub started on a restored database mailed households within a minute
@@ -1049,6 +1049,22 @@ func main() {
go scheduleDaily(ctx, "db-snapshot "+at, at, runSnapshot, logger)
}
// R-1379 (D85, `09` §3 decision 310): the end dates of the hub's OWN public names, once a day. The names are the
// operator's setting (HUB_OWN_NAMES in the manifest), never code: this is a call from the hub to outside names.
// No setting → no call. A skipped run is told by the daily ledger.
if names, bad := monitor.ParseOwnNames(os.Getenv("HUB_OWN_NAMES")); len(names) > 0 || len(bad) > 0 {
if len(bad) > 0 {
logger.Printf("[WARN] own-names check: %d entr(y/ies) of HUB_OWN_NAMES are not host names and are not read: %q", len(bad), bad)
}
if len(names) > 0 {
ownNames := monitor.NewOwnNameChecker(names, monitor.DialCertEnd, dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)
logger.Printf("[INFO] own-names check: %d name(s) are read daily at 06:40 Budapest: %s", len(names), strings.Join(ownNames.Names(), ", "))
go scheduleDaily(ctx, ownNamesJob, "06:40", ownNames.CheckOnce, logger)
}
} else {
logger.Printf("[INFO] own-names check: HUB_OWN_NAMES is not set — the hub reads no certificate of its own names")
}
// Backup deadline checker — runs daily at 05:00 Budapest
go scheduleDaily(ctx, "deadline-check", "05:00", func() {
monitor.CheckBackupDeadlines(dataStore, stalenessChecker, dispatcher.ProcessEvent, logger)
@@ -1141,6 +1157,9 @@ var processStart = time.Now()
// ledger is safe to call.
var dailyLedger *monitor.DailyLedger
// ownNamesJob is the daily job that reads the hub's own names' end dates (D85); the ledger watches it by this name.
const ownNamesJob = "own-names-check"
// scheduleDaily runs fn once daily at the given "HH:MM" time in Europe/Budapest.
// It blocks until ctx is cancelled.
func scheduleDaily(ctx context.Context, name, timeStr string, fn func(), logger *log.Logger) {