"""HTTPS class-K exports and authenticated reads, without annotation POSTs."""
from pathlib import Path
import sys

PROJECT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(PROJECT));sys.path.insert(0,str(PROJECT/'scripts'))
from scripts import check_mask_model_requests_public as checks
from pallet.pose_review_geometry import canonical


if __name__=='__main__':
    import argparse
    parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--output',type=Path,default=PROJECT/'outputs/pallet_mask_class_keypoint_public_v1');args=parser.parse_args()
    checks.ROOT=PROJECT/'outputs/pallet_mask_model_requests_v3';checks.OUT=args.output.resolve()
    checks.STATE=PROJECT/'outputs/pallet_mask_class_keypoint_managed_v1/public_access.json'
    checks.REVIEWS=PROJECT/'outputs/pallet_mask_model_reviews_v3/mask_reviews.sqlite3'
    if checks.OUT.parent!=PROJECT/'outputs' or not checks.OUT.name.startswith('pallet_mask_class_keypoint_public_'):raise ValueError('Fresh public evidence directory required')
    try:checks.main()
    except Exception as error:
        if checks.OUT.exists() and not (checks.OUT/'failure.json').exists():
            secret=(PROJECT/'outputs/pallet_pose_human_review_v1/access_key.txt').read_text().strip()
            with (checks.OUT/'failure.json').open('xb') as stream:stream.write(canonical(dict(state='failed_not_class_keypoint_public_release',
                error=str(error).replace(secret,'[redacted]'),production_annotation_POST_attempts=0))+b'\n')
        raise
