hub v0.15.0: Phase 2 managed updates — per-customer controller-version floor
Operator sets a minimum controller version (FLOOR), per-customer defaulting to a
global floor; the report ACK returns the effective floor + latest_version so the
controller auto-updates to the floor when below it (latest stays the opt-in button).
- store: min_controller_version column + hub_settings global floor + Effective/
Get/SetGlobal/SetMin resolution + config/env DEFAULT_MIN_CONTROLLER_VERSION
- handler: report ACK {min_controller_version, latest_version}; LatestVersionProvider
- web: global floor editor + per-customer override form + Floor column (English)
- tests: floor resolution + ACK + render; override-precedence red-proof verified
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FSZmmSFVzGwEzhYmxbkgBK
This commit is contained in:
+119
-8
@@ -19,6 +19,24 @@ import (
|
||||
|
||||
var validCustomerID = regexp.MustCompile(`^[a-zA-Z0-9.\-]+$`)
|
||||
|
||||
// validSemver matches a bare X.Y.Z controller version (the floor format). Empty is also accepted by
|
||||
// the floor handlers (clears the override).
|
||||
var validSemver = regexp.MustCompile(`^\d+\.\d+\.\d+$`)
|
||||
|
||||
// normalizeFloorInput trims, strips a leading "v", and validates a floor version submitted from the
|
||||
// operator UI. Returns (value, true) on a valid bare semver or empty string; (_, false) otherwise.
|
||||
func normalizeFloorInput(raw string) (string, bool) {
|
||||
v := strings.TrimSpace(raw)
|
||||
v = strings.TrimPrefix(v, "v")
|
||||
if v == "" {
|
||||
return "", true
|
||||
}
|
||||
if !validSemver.MatchString(v) {
|
||||
return "", false
|
||||
}
|
||||
return v, true
|
||||
}
|
||||
|
||||
// customerListEntry is a merged view of a customer from both configs and reports.
|
||||
type customerListEntry struct {
|
||||
CustomerID string
|
||||
@@ -30,6 +48,11 @@ type customerListEntry struct {
|
||||
ControllerVersion string
|
||||
TimeSinceReport time.Duration
|
||||
ConfigCreatedAt time.Time
|
||||
|
||||
// Phase 2 managed-update floor
|
||||
FloorOverride string // per-customer override ("" = none)
|
||||
EffectiveFloor string // override else global ("" = no floor)
|
||||
BelowFloor bool // current < effective floor (would auto-update)
|
||||
}
|
||||
|
||||
// handleConfigList shows all customers (merged from configs + reports).
|
||||
@@ -59,6 +82,7 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
|
||||
HasConfig: true,
|
||||
IsBlocked: cfg.Status == "blocked",
|
||||
ConfigCreatedAt: cfg.CreatedAt,
|
||||
FloorOverride: cfg.MinControllerVersion,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +118,18 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2 floor: resolve each customer's effective floor (override else global) + below-floor flag.
|
||||
globalFloor := s.store.GetGlobalMinControllerVersion()
|
||||
for _, e := range merged {
|
||||
e.EffectiveFloor = e.FloorOverride
|
||||
if e.EffectiveFloor == "" {
|
||||
e.EffectiveFloor = globalFloor
|
||||
}
|
||||
if e.EffectiveFloor != "" && e.ControllerVersion != "" {
|
||||
e.BelowFloor = compareVersions(e.EffectiveFloor, e.ControllerVersion) > 0
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by customer_id
|
||||
entries := make([]customerListEntry, 0, len(merged))
|
||||
for _, e := range merged {
|
||||
@@ -104,15 +140,19 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
|
||||
data := struct {
|
||||
Customers []customerListEntry
|
||||
ActiveNav string
|
||||
Flash string
|
||||
CSRFToken string
|
||||
Customers []customerListEntry
|
||||
GlobalFloor string
|
||||
ActiveNav string
|
||||
Flash string
|
||||
CSRFToken string
|
||||
CSRFField template.HTML
|
||||
}{
|
||||
Customers: entries,
|
||||
ActiveNav: "configs",
|
||||
Flash: r.URL.Query().Get("flash"),
|
||||
CSRFToken: s.csrfToken(r),
|
||||
Customers: entries,
|
||||
GlobalFloor: globalFloor,
|
||||
ActiveNav: "configs",
|
||||
Flash: r.URL.Query().Get("flash"),
|
||||
CSRFToken: s.csrfToken(r),
|
||||
CSRFField: s.csrfField(r),
|
||||
}
|
||||
s.templates.ExecuteTemplate(w, "configs.html", data)
|
||||
}
|
||||
@@ -203,6 +243,19 @@ func (s *Server) handleCustomerUnified(w http.ResponseWriter, r *http.Request, c
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2 managed-update floor: per-customer override, the global default, the effective floor, and
|
||||
// whether the box is currently below it (i.e. would auto-update on its next report).
|
||||
floorOverride := ""
|
||||
if cfg != nil {
|
||||
floorOverride = cfg.MinControllerVersion
|
||||
}
|
||||
globalFloor := s.store.GetGlobalMinControllerVersion()
|
||||
effectiveFloor := s.store.EffectiveMinControllerVersion(customerID)
|
||||
belowFloor := false
|
||||
if effectiveFloor != "" && customer != nil && customer.ControllerVersion != "" {
|
||||
belowFloor = compareVersions(effectiveFloor, customer.ControllerVersion) > 0
|
||||
}
|
||||
|
||||
// History, notifications, events
|
||||
var history []store.CustomerSummary
|
||||
var notifPrefs *store.NotificationPrefs
|
||||
@@ -241,6 +294,12 @@ func (s *Server) handleCustomerUnified(w http.ResponseWriter, r *http.Request, c
|
||||
UpdateAvailable bool
|
||||
ControllerURL string
|
||||
|
||||
// Phase 2 managed-update floor controls
|
||||
FloorOverride string // per-customer override ("" = none)
|
||||
GlobalFloor string // global default (hub_settings → config/env)
|
||||
EffectiveFloor string // override else global ("" = no floor)
|
||||
BelowFloor bool // current < effective floor (would auto-update)
|
||||
|
||||
ConfigSyncStatus string // "in_sync", "mismatch", "unknown"
|
||||
ConfigDiffCount int
|
||||
|
||||
@@ -296,6 +355,11 @@ func (s *Server) handleCustomerUnified(w http.ResponseWriter, r *http.Request, c
|
||||
UpdateAvailable: updateAvailable,
|
||||
ControllerURL: controllerURL,
|
||||
|
||||
FloorOverride: floorOverride,
|
||||
GlobalFloor: globalFloor,
|
||||
EffectiveFloor: effectiveFloor,
|
||||
BelowFloor: belowFloor,
|
||||
|
||||
ConfigSyncStatus: configSyncStatus,
|
||||
ConfigDiffCount: configDiffCount,
|
||||
|
||||
@@ -551,6 +615,53 @@ func (s *Server) handleUnblockCustomer(w http.ResponseWriter, r *http.Request, c
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=unblocked", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleSetGlobalFloor sets (or clears) the global controller-version floor (Phase 2 managed
|
||||
// updates). Empty clears the hub_settings override, falling back to the config/env default.
|
||||
func (s *Server) handleSetGlobalFloor(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
v, ok := normalizeFloorInput(r.FormValue("min_controller_version"))
|
||||
if !ok {
|
||||
http.Redirect(w, r, "/configs?flash=floor_invalid", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
if err := s.store.SetGlobalMinControllerVersion(v); err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to set global floor: %v", err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] Global controller-version floor set to %q", v)
|
||||
http.Redirect(w, r, "/configs?flash=floor_set", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleSetCustomerFloor sets (or clears) a customer's per-customer controller-version floor
|
||||
// override. Empty clears the override (the customer then uses the global floor).
|
||||
func (s *Server) handleSetCustomerFloor(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, err := s.store.GetCustomerConfig(customerID)
|
||||
if err != nil || cfg == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
v, ok := normalizeFloorInput(r.FormValue("min_controller_version"))
|
||||
if !ok {
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=floor_invalid", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
if err := s.store.SetMinControllerVersion(customerID, v); err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to set floor for %s: %v", customerID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] Customer %s controller-version floor override set to %q", customerID, v)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=floor_set", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handlePushConfig sends the generated YAML config to the controller.
|
||||
func (s *Server) handlePushConfig(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, err := s.store.GetCustomerConfig(customerID)
|
||||
|
||||
Reference in New Issue
Block a user