#!/usr/bin/env python3
"""Check app git_repository and private_key_id."""
import json, sys, urllib.request

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

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())

s, r = api("GET", f"/applications/{APP_UUID}")
print(f"git_repository: {r.get('git_repository')}")
print(f"private_key_id: {r.get('private_key_id')}")
print(f"source_type: {r.get('source_type')}")
