#!/usr/bin/env python3
"""Get FULL deployment logs - all entries."""
import json, sys, urllib.request

BASE = "http://localhost:8000/api/v1"
TOKEN = "2|IqbpR94lOiexx5gXHV3BO31utUhuqwi9Y5T2lLCe1505d5d4"

def api(method, path):
    req = urllib.request.Request(BASE + path, method=method)
    req.add_header("Authorization", f"Bearer {TOKEN}")
    req.add_header("Accept", "application/json")
    try:
        with urllib.request.urlopen(req, timeout=60) as resp:
            return resp.status, json.loads(resp.read().decode())
    except urllib.error.HTTPError as e:
        return e.code, json.loads(e.read().decode())

deploy_uuid = sys.argv[1]
s, r = api("GET", f"/deployments/{deploy_uuid}")
logs = r.get('logs', '')
log_list = json.loads(logs)
# Print all output lines around the error - focus on npm/next output
for entry in log_list:
    out = entry.get('output','')
    if 'REDACTED' in out or 'x-access-token' in out:
        continue
    print(out)
