MCPcopy
hub / github.com/opentrace/opentrace / _read_encrypted

Function _read_encrypted

agent/src/opentrace_agent/cli/credentials.py:187–199  ·  view source on GitHub ↗

Read and decrypt a Fernet-encrypted JSON file, returning *None* on failure.

(path: Path)

Source from the content-addressed store, hash-verified

185
186
187def _read_encrypted(path: Path) -> dict[str, Any] | None:
188 """Read and decrypt a Fernet-encrypted JSON file, returning *None* on failure."""
189 if not path.exists():
190 return None
191 try:
192 ciphertext = path.read_bytes()
193 plaintext = _get_fernet().decrypt(ciphertext)
194 data = json.loads(plaintext)
195 if isinstance(data, dict):
196 return data
197 except (InvalidToken, json.JSONDecodeError, OSError) as exc:
198 log.debug("Could not decrypt %s: %s", path, exc)
199 return None
200
201
202def _write_secure(path: Path, data: dict[str, Any]) -> None:

Callers 2

load_tokensFunction · 0.85
load_org_tokenFunction · 0.85

Calls 1

_get_fernetFunction · 0.85

Tested by

no test coverage detected