74 lines
2.3 KiB
Python
Executable File
74 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""CLI pour la gestion et l'audit de la validation humaine Treblo MCP (Ticket nyora-2026-10-216-b/c)."""
|
|
import os
|
|
import sys
|
|
import json
|
|
import datetime
|
|
from zoneinfo import ZoneInfo
|
|
|
|
TUNIS_TZ = ZoneInfo("Africa/Tunis")
|
|
|
|
def get_path():
|
|
p = "/app/data/validations.json"
|
|
if not os.path.exists(os.path.dirname(p)):
|
|
p = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "validations.json")
|
|
return p
|
|
|
|
def load():
|
|
p = get_path()
|
|
if not os.path.exists(p):
|
|
return {"validations": []}
|
|
try:
|
|
with open(p, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
except Exception:
|
|
return {"validations": []}
|
|
|
|
def save(data):
|
|
p = get_path()
|
|
os.makedirs(os.path.dirname(p), exist_ok=True)
|
|
with open(p, "w", encoding="utf-8") as f:
|
|
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
|
|
def list_validations():
|
|
data = load()
|
|
vals = data.get("validations", [])
|
|
if not vals:
|
|
print("Aucune demande de validation enregistrée.")
|
|
return
|
|
print(f"{'ID':<10} {'SPHÈRE':<8} {'STATUT':<10} {'EXPIRATION':<20} {'TAGS'}")
|
|
print("-" * 65)
|
|
for v in vals:
|
|
tags = ", ".join(v.get("details", {}).get("tags", []))[:30]
|
|
print(f"{v.get('id'):<10} {v.get('sphere'):<8} {v.get('status'):<10} {v.get('expires_at')[:19]:<20} {tags}")
|
|
|
|
def update_status(val_id: str, new_status: str):
|
|
data = load()
|
|
found = False
|
|
clean_id = val_id.strip().lstrip("#")
|
|
for v in data.get("validations", []):
|
|
if v.get("id") == clean_id:
|
|
v["status"] = new_status
|
|
v["updated_at"] = datetime.datetime.now(TUNIS_TZ).isoformat()
|
|
found = True
|
|
break
|
|
if found:
|
|
save(data)
|
|
print(f"Demande #{clean_id} mise à jour avec le statut {new_status}.")
|
|
else:
|
|
print(f"Demande #{clean_id} introuvable.")
|
|
|
|
def main():
|
|
if len(sys.argv) < 2 or sys.argv[1] == "list":
|
|
list_validations()
|
|
elif sys.argv[1] == "approve" and len(sys.argv) > 2:
|
|
update_status(sys.argv[2], "APPROVED")
|
|
elif sys.argv[1] == "reject" and len(sys.argv) > 2:
|
|
update_status(sys.argv[2], "REJECTED")
|
|
else:
|
|
print("Usage: python validation_cli.py [list | approve <id> | reject <id>]")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|