#!/usr/bin/env python3
"""
Admin Auth Helper – verify admin access
Usage: python3 auth.py <passphrase> or NATIRIS_ADMIN_PASS=xxx python3 ...
"""

import json
import os
import sys

PATHS = {
    "config": os.path.expanduser("~/natiris/config/admin_config.json"),
}

def check_passphrase(passphrase):
    admin_config = {}
    try:
        with open(PATHS["config"]) as f:
            admin_config = json.load(f)
    except Exception:
        pass
    return passphrase == admin_config.get("admin_passphrase", "")

if __name__ == "__main__":
    passphrase = sys.argv[1] if len(sys.argv) > 1 else os.environ.get("NATIRIS_ADMIN_PASS", "")
    if check_passphrase(passphrase):
        print("ADMIN_AUTH:OK")
        sys.exit(0)
    else:
        print("ADMIN_AUTH:FAIL")
        sys.exit(1)
