package store import ( "context" "database/sql" ) // AllocationBindingStillValidSQL cross-checks a signed workload token's // claims against the durable allocation record before trusting it. A // validly-signed, unexpired token alone is not proof the allocation it names // is still the live binding for that match/server pair -- this closes that // gap defense-in-depth. allocations rows are append-only and never leave // 'ALLOCATED' (see allocator_sql.go), so this is a simple existence check, // not a state-machine walk. const AllocationBindingStillValidSQL = `SELECT 1 FROM allocations WHERE allocation_id = $1 AND match_id = $2 AND server_id = $3 AND state = 'ALLOCATED'` // AllocationBindingStillValid reports whether the given (allocationID, // matchID, serverID) triple names a real, still-allocated row. db, and every // identifier, must be non-empty -- callers pass this an already-parsed and // signature-verified token's claims, so empty fields here indicate a caller // bug rather than a legitimate "not found". func AllocationBindingStillValid(ctx context.Context, db *sql.DB, allocationID, matchID, serverID string) (bool, error) { if db == nil || allocationID == "" || matchID == "" || serverID == "" { return false, sql.ErrNoRows } var one int err := db.QueryRowContext(ctx, AllocationBindingStillValidSQL, allocationID, matchID, serverID).Scan(&one) if err == sql.ErrNoRows { return false, nil } if err != nil { return false, err } return true, nil }