mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 04:20:45 +08:00
Add industrial config sync separate from collection tasks.
Periodic vendor-aware CLI sync stores zlib snapshots in Postgres with dashboard, retry, and config viewer under Network Management. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2fc47e5135
commit
0eead0e662
23 changed files with 2993 additions and 9 deletions
20
netx_api/config_sync_codec.py
Normal file
20
netx_api/config_sync_codec.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""zlib + sha256 helpers for config blobs."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import zlib
|
||||
|
||||
|
||||
def compress_text(text: str) -> tuple[bytes, str, int, int]:
|
||||
"""Return (zlib_bytes, sha256_hex, plain_size, zlib_size)."""
|
||||
raw = str(text or "").encode("utf-8", errors="replace")
|
||||
digest = hashlib.sha256(raw).hexdigest()
|
||||
blob = zlib.compress(raw, level=6)
|
||||
return blob, digest, len(raw), len(blob)
|
||||
|
||||
|
||||
def decompress_text(blob: bytes | None) -> str:
|
||||
if not blob:
|
||||
return ""
|
||||
return zlib.decompress(bytes(blob)).decode("utf-8", errors="replace")
|
||||
Loading…
Add table
Add a link
Reference in a new issue