hub + installer (unreleased): fixes after an independent review of the night's code — per-thing mail cooldown, a box's input bounded and checked, both off-site account types on a reset, a quiet first run, strict-mode installer
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
a044eb8c16
commit
f618c591eb
31 files changed
+796
-88
No files matched your search
@@ -44,6 +44,16 @@ func offsiteChoice(configJSON string) (enabled bool, typ string) {
|
||||
return o.Offsite.Enabled, o.Offsite.Type
|
||||
}
|
||||
|
||||
// offsiteAccountTypes lists the provider account types a RESET must take down: `first` (what offsiteChoice returned)
|
||||
// and the kept record's type when it is another one. Each once.
|
||||
func offsiteAccountTypes(configJSON, first string) []string {
|
||||
types := []string{first}
|
||||
if rec := offsite.ReadAccountRecord(configJSON); rec != nil && rec.Type != first {
|
||||
types = append(types, rec.Type)
|
||||
}
|
||||
return types
|
||||
}
|
||||
|
||||
// handleCustomerResetPreview — GET /configs/{id}/reset. Returns the live inventory the confirm surface
|
||||
// renders (ruling 4): what a RESET would destroy right now. Read-only — no writes, no external calls
|
||||
// beyond the label lookups needed to name the offsite resource. `refused` is true when a host row still
|
||||
@@ -216,6 +226,7 @@ func (s *Server) commitCustomerReset(ctx context.Context, cfg *store.CustomerCon
|
||||
}
|
||||
|
||||
// Leg: Hetzner offsite (repo DATA destroyed). Only when the customer chose an offsite tier.
|
||||
hetznerDone := false // the provider leg really ran to its end (not skipped) — only then the account's record may go
|
||||
offsiteEnabled, offsiteType := false, ""
|
||||
if cfg != nil {
|
||||
offsiteEnabled, offsiteType = offsiteChoice(cfg.ConfigJSON)
|
||||
@@ -225,12 +236,17 @@ func (s *Server) commitCustomerReset(ctx context.Context, cfg *store.CustomerCon
|
||||
s.logger.Printf("[WARN] %s: no config row — the offsite (Hetzner) teardown CANNOT be determined and is SKIPPED; verify the Hetzner side by hand", customerID)
|
||||
_ = s.store.UpdateResetLeg(resetID, "hetzner", "skipped_no_config")
|
||||
} else if offsiteEnabled && s.offsite != nil {
|
||||
if derr := s.offsite.Deprovision(ctx, customerID, offsiteType); derr != nil {
|
||||
_ = s.store.UpdateResetLeg(resetID, "hetzner", "failed")
|
||||
s.logger.Printf("[ERROR] reset %s: hetzner deprovision FAILED (journal #%d retained; re-run to resume): %v", customerID, resetID, derr)
|
||||
return &resetLegError{Leg: "hetzner", Status: http.StatusBadGateway, Err: derr,
|
||||
Msg: "Reset incomplete: the offsite (Hetzner) teardown failed — nothing was purged; re-run to resume. (" + derr.Error() + ")"}
|
||||
// Every account the config knows: the ticked tier's, and — when the tier was unticked, or ticked again with
|
||||
// the other type — the one in the kept record. Each type once.
|
||||
for _, typ := range offsiteAccountTypes(cfg.ConfigJSON, offsiteType) {
|
||||
if derr := s.offsite.Deprovision(ctx, customerID, typ); derr != nil {
|
||||
_ = s.store.UpdateResetLeg(resetID, "hetzner", "failed")
|
||||
s.logger.Printf("[ERROR] reset %s: hetzner deprovision (%s) FAILED (journal #%d retained; re-run to resume): %v", customerID, typ, resetID, derr)
|
||||
return &resetLegError{Leg: "hetzner", Status: http.StatusBadGateway, Err: derr,
|
||||
Msg: "Reset incomplete: the offsite (Hetzner) teardown failed — nothing was purged; re-run to resume. (" + derr.Error() + ")"}
|
||||
}
|
||||
}
|
||||
hetznerDone = true
|
||||
_ = s.store.UpdateResetLeg(resetID, "hetzner", "ok")
|
||||
s.logger.Printf("[INFO] reset %s: offsite deprovisioned (repo data destroyed)", customerID)
|
||||
} else {
|
||||
@@ -275,6 +291,9 @@ func (s *Server) commitCustomerReset(ctx context.Context, cfg *store.CustomerCon
|
||||
if cfg == nil {
|
||||
_ = s.store.UpdateResetLeg(resetID, "descriptor", "skipped_no_config")
|
||||
} else {
|
||||
if hetznerDone {
|
||||
cfg.ConfigJSON = offsite.DropAccountRecord(cfg.ConfigJSON) // D71: the record goes with the account
|
||||
}
|
||||
newConfigJSON, cerr := offsite.ClearProvisionedDescriptor(cfg.ConfigJSON)
|
||||
if cerr != nil {
|
||||
_ = s.store.UpdateResetLeg(resetID, "descriptor", "failed")
|
||||
|
||||
@@ -172,3 +172,34 @@ func TestD71_NeverTickedMakesNoRecord(t *testing.T) {
|
||||
}
|
||||
_ = http.StatusOK
|
||||
}
|
||||
|
||||
// Review of 2026-11-14: (1) a RESET on a hub with NO provider configured skips the provider leg — the account still
|
||||
// exists, so its record must stay (it was dropped with the descriptor). (2) Unticked as shared and ticked again as
|
||||
// dedicated: two accounts exist; the RESET takes BOTH down.
|
||||
func TestD71_RecordSurvivesASkippedLeg_AndBothTypesGo(t *testing.T) {
|
||||
s, st, _, _ := d71Server(t)
|
||||
d71Save(t, s, d71Tick)
|
||||
d71Save(t, s, "")
|
||||
s.offsite = nil // this hub has no provider token
|
||||
if rr := postReset(t, s, "acme", url.Values{"confirm_id": {"acme"}}); rr.Code != http.StatusSeeOther {
|
||||
t.Fatalf("reset: %d %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
cfg, _ := st.GetCustomerConfig("acme")
|
||||
cr, _ := st.LatestCustomerReset("acme")
|
||||
if cr == nil || cr.Legs["hetzner"] != "skipped" {
|
||||
t.Fatalf("journal: %+v", cr)
|
||||
}
|
||||
if offsite.ReadAccountRecord(cfg.ConfigJSON) == nil {
|
||||
t.Fatalf("the provider leg was SKIPPED and the account's record is gone: %s", cfg.ConfigJSON)
|
||||
}
|
||||
|
||||
if got := offsiteAccountTypes(`{"offsite":{"enabled":true,"type":"dedicated"},"offsite_account":{"type":"shared","user":"u1"}}`, "dedicated"); len(got) != 2 || got[0] != "dedicated" || got[1] != "shared" {
|
||||
t.Fatalf("a household with a dedicated tier AND a kept shared record: the RESET would take down %v, want both", got)
|
||||
}
|
||||
if got := offsiteAccountTypes(`{"offsite":{"enabled":true,"type":"shared"}}`, "shared"); len(got) != 1 {
|
||||
t.Fatalf("one account: %v", got)
|
||||
}
|
||||
if got := offsiteAccountTypes(`{"offsite_account":{"type":"shared","user":"u1"}}`, "shared"); len(got) != 1 {
|
||||
t.Fatalf("an unticked tier with its record is ONE account, not two: %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user