network-ai 5.4.5 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env python3
2
2
  # SECURITY: This script makes NO network calls and spawns NO subprocesses.
3
3
  # All I/O is local file operations only:
4
- # READS: data/active_grants.json, data/audit_log.jsonl
5
- # WRITES: data/active_grants.json, data/audit_log.jsonl
6
- # Imports used: argparse, json, sys, datetime, pathlib, typing
4
+ # READS: data[/<env>]/active_grants.json, data[/<env>]/audit_log.jsonl
5
+ # WRITES: data[/<env>]/active_grants.json, data[/<env>]/audit_log.jsonl
6
+ # Imports used: argparse, json, os, re, sys, datetime, pathlib, typing
7
7
  # No imports of: requests, socket, subprocess, urllib, http, ssl, ftplib, smtplib
8
8
  """
9
9
  Revoke Grant Token & TTL Enforcement
@@ -22,13 +22,27 @@ Example:
22
22
 
23
23
  import argparse
24
24
  import json
25
+ import os
26
+ import re
25
27
  import sys
26
28
  from datetime import datetime, timezone
27
29
  from pathlib import Path
28
30
  from typing import Any
29
31
 
30
- GRANTS_FILE = Path(__file__).parent.parent / "data" / "active_grants.json"
31
- AUDIT_LOG = Path(__file__).parent.parent / "data" / "audit_log.jsonl"
32
+
33
+ def _resolve_data_dir(env: str = "") -> Path:
34
+ """Return the active data directory, scoped to <env> when set."""
35
+ _env = env or os.environ.get("NETWORK_AI_ENV", "")
36
+ base = Path(__file__).parent.parent / "data"
37
+ if _env:
38
+ if not re.match(r'^[a-zA-Z0-9_-]+$', _env):
39
+ raise ValueError(f"Invalid NETWORK_AI_ENV value: {_env!r}")
40
+ return base / _env
41
+ return base
42
+
43
+
44
+ GRANTS_FILE = _resolve_data_dir() / "active_grants.json"
45
+ AUDIT_LOG = _resolve_data_dir() / "audit_log.jsonl"
32
46
 
33
47
 
34
48
  def log_audit(action: str, details: dict[str, Any]) -> None:
@@ -186,9 +200,20 @@ def main():
186
200
  parser.add_argument("--list-expired", action="store_true",
187
201
  help="List expired tokens without removing")
188
202
  parser.add_argument("--json", action="store_true", help="Output as JSON")
189
-
203
+ parser.add_argument(
204
+ "--env",
205
+ default="",
206
+ help="Target environment (dev|st|sit|qa|sandbox|preprod|prod). Overrides NETWORK_AI_ENV."
207
+ )
208
+
190
209
  args = parser.parse_args()
191
-
210
+
211
+ # Re-resolve data paths if --env was provided explicitly
212
+ global GRANTS_FILE, AUDIT_LOG
213
+ if args.env:
214
+ GRANTS_FILE = _resolve_data_dir(args.env) / "active_grants.json"
215
+ AUDIT_LOG = _resolve_data_dir(args.env) / "audit_log.jsonl"
216
+
192
217
  # Handle --list-expired
193
218
  if args.list_expired:
194
219
  result = list_expired_tokens()