feat: instance lock and purge fields for HQ disputes

This commit is contained in:
2026-09-10 13:17:33 +00:00
parent e1ad2467d2
commit 5c87505820
2 changed files with 48 additions and 0 deletions
+8
View File
@@ -31,4 +31,12 @@ type Instance struct {
LicenseBlob string `bson:"license_blob,omitempty" json:"-"`
LicenseTier string `bson:"license_tier,omitempty" json:"license_tier,omitempty"`
LicenseExpiry *time.Time `bson:"license_expiry,omitempty" json:"license_expiry,omitempty"`
// LockedAt and PurgeAfter are written by vantage-admin's cloudprov when the
// account that owns this instance is under a dispute. LockedAt makes the
// control plane refuse the instance everywhere; PurgeAfter, set only once a
// dispute has failed, authorises the reaper to delete it. Both absent is the
// normal state, and nothing but admin ever sets them.
LockedAt *time.Time `bson:"locked_at,omitempty" json:"locked_at,omitempty"`
PurgeAfter *time.Time `bson:"purge_after,omitempty" json:"purge_after,omitempty"`
}
+40
View File
@@ -0,0 +1,40 @@
package models
import (
"testing"
"time"
"go.mongodb.org/mongo-driver/v2/bson"
)
func TestInstanceLockFieldsBSON(t *testing.T) {
at := time.Date(2026, 9, 10, 10, 0, 0, 0, time.UTC)
raw, err := bson.Marshal(Instance{InstanceID: "i1", LockedAt: &at, PurgeAfter: &at})
if err != nil {
t.Fatalf("marshal: %v", err)
}
var set bson.M
if err := bson.Unmarshal(raw, &set); err != nil {
t.Fatalf("unmarshal: %v", err)
}
for _, k := range []string{"locked_at", "purge_after"} {
if _, ok := set[k]; !ok {
t.Errorf("%s missing from %v", k, set)
}
}
raw, err = bson.Marshal(Instance{InstanceID: "i1"})
if err != nil {
t.Fatalf("marshal: %v", err)
}
var unset bson.M
if err := bson.Unmarshal(raw, &unset); err != nil {
t.Fatalf("unmarshal: %v", err)
}
for _, k := range []string{"locked_at", "purge_after"} {
if _, ok := unset[k]; ok {
t.Errorf("%s written for an unlocked instance: %v", k, unset)
}
}
}