with open("/home/noor/.config/opencode/fullstacked.env") as f:
    env = {}
    for line in f:
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        key, sep, val = line.partition("=")
        env[key] = val.strip('"').strip("'")

tok = None
for key, val in env.items():
    if "PANGOLIN" in key and "TOKEN" in key:
        tok = val
auth = "Bearer" + " " + tok
base = env.get("PANGOLIN_API_BASE","http://localhost:3003/v1")
org = env.get("PANGOLIN_ORG_ID","fullstacked")

import urllib.request, json
def api(method, path, payload=None):
    req = urllib.request.Request(base+path, method=method)
    req.add_header("Authorization", auth)
    req.add_header("Content-Type","application/json")
    body = json.dumps(payload).encode() if payload is not None else None
    r = urllib.request.urlopen(req, body, timeout=20)
    return json.loads(r.read())

print("== RESOURCES ==")
d = api("GET", f"/org/{org}/resources?pageSize=50&siteId=1")
for res in d["data"]["resources"]:
    print(res.get("resourceId"), res.get("name"), res.get("fullDomain"), "ssl=",res.get("ssl"),"sso=",res.get("sso"))
print("== DOMAINS ==")
d2 = api("GET", f"/org/{org}/domains")
for dom in d2["data"].get("domains", d2["data"].get("resources",[])):
    print(dom.get("domainId"), dom.get("baseDomain"), dom.get("type"))
