snapkitty
compilers
c
python
nasm
File size: 1,525 Bytes
e547dfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Sovereign Node Key — provisioned per authorized node.
Generated by authority. Never committed to public repo.
Dispose and regenerate on each new authorization cycle.
"""

import json
import os
from pathlib import Path

_SOVEREIGN_DIR = Path(__file__).parent
_CAPABILITY_FILE = _SOVEREIGN_DIR / ".capability"
_AUTH_FILE = _SOVEREIGN_DIR / "authorization.json"


def require_node_key() -> str:
    """
    Load and return the node capability token.
    Raises RuntimeError if not authorized.
    """
    if not _CAPABILITY_FILE.exists():
        raise RuntimeError(
            "No capability token found. "
            "Contact jessica@collectivekitty.com for access."
        )
    token = _CAPABILITY_FILE.read_text().strip()
    if not token:
        raise RuntimeError("Capability token is empty.")

    # Verify authorization record is ACTIVE
    if _AUTH_FILE.exists():
        auth = json.loads(_AUTH_FILE.read_text())
        status = auth.get("authorization_status", "")
        if status != "ACTIVE":
            raise RuntimeError(f"Node authorization status: {status}. Access denied.")

    return token


def node_id() -> str:
    """Return the provisioned node ID."""
    if _AUTH_FILE.exists():
        auth = json.loads(_AUTH_FILE.read_text())
        return auth.get("node_id", "unknown")
    return "unknown"


def is_authorized() -> bool:
    """Check if this node is authorized without raising."""
    try:
        require_node_key()
        return True
    except RuntimeError:
        return False