fix(main): rett async httpx syntaksfeil i build-status + terminal + logs
This commit is contained in:
parent
787edea5f6
commit
fa2d995fda
22
main.py
22
main.py
|
|
@ -185,7 +185,9 @@ async def build_status():
|
|||
creds, project = google.auth.default()
|
||||
creds.refresh(google.auth.transport.requests.Request())
|
||||
url = f"https://cloudbuild.googleapis.com/v1/projects/{project}/builds?pageSize=5"
|
||||
async with httpx.AsyncClient(timeout=15.0) as client: r = await client.get(url, headers={"Authorization": f"Bearer {creds.token}"}) r.raise_for_status()
|
||||
async with httpx.AsyncClient(timeout=15.0) as client:
|
||||
r = await client.get(url, headers={"Authorization": f"Bearer {creds.token}"})
|
||||
r.raise_for_status()
|
||||
builds = r.json().get("builds", [])
|
||||
return {"builds": [{"id": b["id"], "status": b["status"],
|
||||
"branch": b.get("substitutions", {}).get("BRANCH_NAME", ""),
|
||||
|
|
@ -245,7 +247,9 @@ async def terminal_exec(req: TerminalExecRequest):
|
|||
creds, project = google.auth.default()
|
||||
creds.refresh(google.auth.transport.requests.Request())
|
||||
url = f"https://cloudbuild.googleapis.com/v1/projects/{project}/builds?pageSize=5"
|
||||
async with httpx.AsyncClient(timeout=15.0) as client: r = await client.get(url, headers={"Authorization": f"Bearer {creds.token}"}) r.raise_for_status()
|
||||
async with httpx.AsyncClient(timeout=15.0) as client:
|
||||
r = await client.get(url, headers={"Authorization": f"Bearer {creds.token}"})
|
||||
r.raise_for_status()
|
||||
builds = r.json().get("builds", [])
|
||||
result = [{"id": b["id"], "status": b["status"],
|
||||
"branch": b.get("substitutions", {}).get("BRANCH_NAME", ""),
|
||||
|
|
@ -269,12 +273,12 @@ async def terminal_exec(req: TerminalExecRequest):
|
|||
"orderBy": "timestamp desc",
|
||||
"pageSize": 20,
|
||||
}
|
||||
r = httpx.post(
|
||||
"https://logging.googleapis.com/v2/entries:list",
|
||||
headers={"Authorization": f"Bearer {creds.token}"},
|
||||
json=body,
|
||||
timeout=10,
|
||||
)
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
r = await client.post(
|
||||
"https://logging.googleapis.com/v2/entries:list",
|
||||
headers={"Authorization": f"Bearer {creds.token}"},
|
||||
json=body,
|
||||
)
|
||||
entries = r.json().get("entries", [])
|
||||
if not entries:
|
||||
return {"output": "(ingen logglinjer funnet)", "exit_code": 0}
|
||||
|
|
@ -317,7 +321,6 @@ async def vm_ssh_key(instance: str = "osvauco-dev-vm"):
|
|||
raise HTTPException(status_code=r.status_code, detail=f"Compute API feil: {r.text[:200]}")
|
||||
|
||||
data = r.json()
|
||||
# SSH-nøkler ligger i metadata items med key "ssh-keys"
|
||||
metadata_items = data.get("metadata", {}).get("items", [])
|
||||
ssh_keys_raw = next(
|
||||
(item["value"] for item in metadata_items if item["key"] == "ssh-keys"),
|
||||
|
|
@ -326,7 +329,6 @@ async def vm_ssh_key(instance: str = "osvauco-dev-vm"):
|
|||
if not ssh_keys_raw:
|
||||
return {"public_key": None, "instance": instance, "detail": "Ingen SSH-nøkkel funnet i metadata"}
|
||||
|
||||
# Format: "user:ssh-rsa AAAA..." — returner kun public key-delen
|
||||
public_key = ssh_keys_raw.strip()
|
||||
if ":" in public_key:
|
||||
public_key = public_key.split(":", 1)[1].strip()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user