mirror of
https://github.com/hansjone/netx.git
synced 2026-10-10 13:50:44 +08:00
feat(ops): add managed NE management and batch CLI collection
Introduce workbench operations for multi-vendor NE CRUD/connect-test and Netmiko batch collection with job lifecycle controls, log downloads, and paginated run filters. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
282dbe75af
commit
042c015045
36 changed files with 3695 additions and 17 deletions
40
netx_api/ne_crypto.py
Normal file
40
netx_api/ne_crypto.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from cryptography.fernet import Fernet, InvalidToken
|
||||
|
||||
from .config import settings
|
||||
|
||||
|
||||
class CredentialCryptoError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _fernet() -> Fernet:
|
||||
key = str(settings.credential_secret_key or "").strip()
|
||||
if not key:
|
||||
raise CredentialCryptoError("credential_secret_key_not_configured")
|
||||
try:
|
||||
return Fernet(key.encode("ascii"))
|
||||
except Exception as exc:
|
||||
raise CredentialCryptoError("credential_secret_key_invalid") from exc
|
||||
|
||||
|
||||
def encrypt_secret(value: str) -> str:
|
||||
plain = str(value or "")
|
||||
if not plain:
|
||||
return ""
|
||||
return _fernet().encrypt(plain.encode("utf-8")).decode("ascii")
|
||||
|
||||
|
||||
def decrypt_secret(value: str) -> str:
|
||||
enc = str(value or "").strip()
|
||||
if not enc:
|
||||
return ""
|
||||
try:
|
||||
return _fernet().decrypt(enc.encode("ascii")).decode("utf-8")
|
||||
except InvalidToken as exc:
|
||||
raise CredentialCryptoError("credential_decrypt_failed") from exc
|
||||
|
||||
|
||||
def credentials_configured() -> bool:
|
||||
return bool(str(settings.credential_secret_key or "").strip())
|
||||
Loading…
Add table
Add a link
Reference in a new issue