feat(network): integrate NetBird clients, profiles and private backups
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"""Pinned vendor packages served locally; no runtime redirects to latest downloads."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import stat
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
LOCK = json.loads(Path(__file__).with_name("clients.lock.json").read_text())
|
||||
VERSION = LOCK["version"]
|
||||
|
||||
|
||||
def item(identifier: str) -> dict:
|
||||
for row in LOCK["items"]:
|
||||
if row["id"] == identifier:
|
||||
return row
|
||||
raise ValueError("Неизвестный установщик NetBird.")
|
||||
|
||||
|
||||
def directory(root: Path) -> Path:
|
||||
return root / "installers" / "netbird" / VERSION
|
||||
|
||||
|
||||
@contextmanager
|
||||
def open_verified(root: Path, identifier: str):
|
||||
row = item(identifier)
|
||||
folder = directory(root)
|
||||
path = folder / row["filename"]
|
||||
if any(p.is_symlink() for p in (folder, folder.parent, path)):
|
||||
raise ValueError("Установщик NetBird изменён.")
|
||||
fd = os.open(path, os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0))
|
||||
with os.fdopen(fd, "rb") as stream:
|
||||
info = os.fstat(stream.fileno())
|
||||
if not stat.S_ISREG(info.st_mode) or info.st_size != row["bytes"]:
|
||||
raise ValueError("Установщик NetBird изменён.")
|
||||
if hashlib.file_digest(stream, "sha256").hexdigest() != row["sha256"]:
|
||||
raise ValueError("Установщик NetBird изменён.")
|
||||
stream.seek(0)
|
||||
yield stream, path
|
||||
|
||||
|
||||
def verify(root: Path, identifier: str) -> Path:
|
||||
with open_verified(root, identifier) as (_, path):
|
||||
return path
|
||||
|
||||
|
||||
def catalog(root: Path) -> dict:
|
||||
entries = []
|
||||
for row in LOCK["items"]:
|
||||
try:
|
||||
verify(root, row["id"])
|
||||
available = True
|
||||
except (OSError, ValueError):
|
||||
available = False
|
||||
entries.append(
|
||||
{k: row[k] for k in ("id", "label", "filename", "bytes", "sha256")}
|
||||
| {
|
||||
"available": available,
|
||||
"download_url": f"/api/v1/fleet/netbird/clients/{row['id']}",
|
||||
}
|
||||
)
|
||||
return {"version": VERSION, "items": entries}
|
||||
Reference in New Issue
Block a user