aipackage/scripts/cezen-license-check.py

61 lines
2.5 KiB
Python

#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
from cezen_license import (
STAGING_MAX_TIER,
build_tier_options,
evaluate_license,
evaluate_override,
normalize_tier,
read_json_file,
)
def main():
parser = argparse.ArgumentParser(description="Evaluate Nexus One AI license and tier constraints")
parser.add_argument("--license", dest="license_path", default="/opt/cezen/license.json")
parser.add_argument("--override", dest="override_path", default="/opt/cezen/license.override.json")
parser.add_argument("--feasibility", dest="feasibility_path", default="/opt/cezen/feasibility.json")
parser.add_argument("--public-key", dest="public_key_path", default="")
parser.add_argument("--machine-id", dest="machine_id", default="")
args = parser.parse_args()
script_dir = Path(__file__).resolve().parent
default_pub = script_dir.parent / "autoinstall" / "keys" / "cezen-license-public.pem"
public_key_path = args.public_key_path or str(default_pub)
license_record = read_json_file(args.license_path)
override_record = read_json_file(args.override_path)
feasibility = read_json_file(args.feasibility_path)
hardware_tier = normalize_tier(((feasibility.get("recommendation") or {}).get("recommended_tier")), STAGING_MAX_TIER)
license_eval = evaluate_license(license_record, public_key_path, machine_id=args.machine_id or None)
override_eval = evaluate_override(override_record, public_key_path)
tier_options = build_tier_options(license_eval, hardware_tier, override_eval)
response = {
"license": license_eval,
"override": override_eval,
"hardware": {
"recommended_tier": hardware_tier,
"recommended_profile": (feasibility.get("recommendation") or {}).get("recommended_profile", ""),
"estimated_concurrent_users": (feasibility.get("recommendation") or {}).get("estimated_concurrent_users", ""),
"notes": (feasibility.get("recommendation") or {}).get("notes", []),
"features": feasibility.get("features", {}),
},
"tier_options": tier_options,
"effective_max_tier": max(
[opt["tier"] for opt in tier_options if opt["selectable"]],
default=STAGING_MAX_TIER,
key=lambda tier: ("starter", "basic", "pro", "max").index(tier),
),
"staging_only": license_eval.get("status") != "valid",
}
print(json.dumps(response, indent=2))
if __name__ == "__main__":
main()