Spaces:
Running
Running
board: keep the newest scan per model (full ts), not a random id
Browse files- scanner/master.py +5 -2
scanner/master.py
CHANGED
|
@@ -144,7 +144,8 @@ def handle(path, token, host, version, body=None):
|
|
| 144 |
b = body or {}
|
| 145 |
bid = secrets.token_hex(6)
|
| 146 |
day = time.strftime("%Y-%m-%d", time.gmtime())
|
| 147 |
-
|
|
|
|
| 148 |
"grade": str(b.get("grade", "?"))[:1], "depth": b.get("depth"), "counts": b.get("counts"), "db_version": b.get("db_version"),
|
| 149 |
"domains": {k: (v or {}).get("grade") for k, v in (b.get("domains") or {}).items()},
|
| 150 |
"hit_checks": b.get("hit_checks"), "checks": b.get("checks"), "controls": b.get("controls"), "firewall": b.get("firewall"),
|
|
@@ -182,7 +183,9 @@ def board():
|
|
| 182 |
except Exception: # noqa: BLE001
|
| 183 |
pass
|
| 184 |
latest = {}
|
| 185 |
-
|
|
|
|
|
|
|
| 186 |
if r.get("model") and r.get("checks"):
|
| 187 |
latest[r["model"]] = r
|
| 188 |
keep = ("id", "model", "grade", "depth", "domains", "hit_checks", "checks", "controls", "date", "reference", "db_version", "firewall")
|
|
|
|
| 144 |
b = body or {}
|
| 145 |
bid = secrets.token_hex(6)
|
| 146 |
day = time.strftime("%Y-%m-%d", time.gmtime())
|
| 147 |
+
ts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) # full-second stamp so the board keeps the newest scan, not a random id
|
| 148 |
+
rec = {"id": bid, "user": idn["user"], "host": host, "client": version, "date": day, "ts": ts, "model": str(b.get("model", ""))[:120],
|
| 149 |
"grade": str(b.get("grade", "?"))[:1], "depth": b.get("depth"), "counts": b.get("counts"), "db_version": b.get("db_version"),
|
| 150 |
"domains": {k: (v or {}).get("grade") for k, v in (b.get("domains") or {}).items()},
|
| 151 |
"hit_checks": b.get("hit_checks"), "checks": b.get("checks"), "controls": b.get("controls"), "firewall": b.get("firewall"),
|
|
|
|
| 183 |
except Exception: # noqa: BLE001
|
| 184 |
pass
|
| 185 |
latest = {}
|
| 186 |
+
# Newest scan per model wins. Sort by the full timestamp; older records that predate the ts field
|
| 187 |
+
# carry only a day, which sorts before any same-day ts, so a newer stamped scan always supersedes them.
|
| 188 |
+
for r in sorted(recs, key=lambda r: (r.get("ts") or r.get("date", ""), r.get("id", ""))):
|
| 189 |
if r.get("model") and r.get("checks"):
|
| 190 |
latest[r["model"]] = r
|
| 191 |
keep = ("id", "model", "grade", "depth", "domains", "hit_checks", "checks", "controls", "date", "reference", "db_version", "firewall")
|