Files
natiris/admin/auth.py

32 lines
789 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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)