package provision import ( "context" "errors" "github.com/carlosframework/platform/internal/registry" "time" ) var ErrClaimAdmission = errors.New("provision: claim admission unavailable") type ClaimRecord struct { Host, Key, Family, Account, App string CreatedAt time.Time Value any Route registry.Route DryRun bool } func (cfg ReconcileConfig) claimInstall(ctx context.Context, selected ClaimRecord, existing *registry.Route, write func(registry.ClaimOwnership) error) error { if !cfg.ClaimEnabled { return write(registry.ClaimOwnership{}) } if cfg.ClaimInstall == nil { return ErrClaimAdmission } // An existing row without a valid claim owner can never be kept: the // write below would refuse it. Decide that before the hook, whose guard // and inventory effects a refused row must not cause. if existing != nil && !existing.ClaimOwnership.Valid() { return registry.ErrClaimOwnership } return cfg.ClaimInstall(ctx, selected, func(owner registry.ClaimOwnership) error { if !owner.Valid() || (existing != nil && existing.ClaimOwnership != owner) { return registry.ErrClaimOwnership } return write(owner) }) } func (cfg ReconcileConfig) claimRetire(ctx context.Context, reg *registry.Registry, route registry.Route) error { if !cfg.ClaimEnabled { return reg.Delete(route.Host) } if cfg.ClaimRetire == nil { return ErrClaimAdmission } return cfg.ClaimRetire(ctx, route) }