|
1 | 1 | from fastapi import HTTPException |
2 | 2 | import httpx |
3 | | -from nilai_common import Nonce, AttestationReport, SETTINGS |
| 3 | +from nilai_common import AttestationReport |
4 | 4 | from nilai_common.logger import setup_logger |
5 | 5 |
|
6 | 6 | logger = setup_logger(__name__) |
7 | 7 |
|
| 8 | +ATTESTATION_URL = "http://nilcc-attester/v2/report" |
8 | 9 |
|
9 | | -async def get_attestation_report( |
10 | | - nonce: Nonce | None, |
11 | | -) -> AttestationReport: |
12 | | - """Get the attestation report for the given nonce""" |
13 | | - |
14 | | - try: |
15 | | - attestation_url = f"http://{SETTINGS.attestation_host}:{SETTINGS.attestation_port}/attestation/report" |
16 | | - async with httpx.AsyncClient() as client: |
17 | | - response: httpx.Response = await client.get(attestation_url, params=nonce) |
18 | | - report = AttestationReport(**response.json()) |
19 | | - return report |
20 | | - except Exception as e: |
21 | | - raise HTTPException(status_code=500, detail=str(e)) |
22 | 10 |
|
| 11 | +async def get_attestation_report() -> AttestationReport: |
| 12 | + """Get the attestation report""" |
23 | 13 |
|
24 | | -async def verify_attestation_report(attestation_report: AttestationReport) -> bool: |
25 | | - """Verify the attestation report""" |
26 | 14 | try: |
27 | | - attestation_url = f"http://{SETTINGS.attestation_host}:{SETTINGS.attestation_port}/attestation/verify" |
28 | 15 | async with httpx.AsyncClient() as client: |
29 | | - response: httpx.Response = await client.get( |
30 | | - attestation_url, params=attestation_report.model_dump() |
| 16 | + response: httpx.Response = await client.get(ATTESTATION_URL) |
| 17 | + response_json = response.json() |
| 18 | + return AttestationReport( |
| 19 | + gpu_attestation=response_json["report"], |
| 20 | + cpu_attestation=response_json["gpu_token"], |
| 21 | + verifying_key="", # Added later by the API |
31 | 22 | ) |
32 | | - return response.json() |
| 23 | + except httpx.HTTPStatusError as e: |
| 24 | + raise HTTPException( |
| 25 | + status_code=e.response.status_code, |
| 26 | + detail=str("Error getting attestation report" + str(e)), |
| 27 | + ) |
33 | 28 | except Exception as e: |
34 | | - raise HTTPException(status_code=500, detail=str(e)) |
| 29 | + raise HTTPException( |
| 30 | + status_code=500, detail=str("Error getting attestation report" + str(e)) |
| 31 | + ) |
0 commit comments