summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-10 23:42:43 -0700
committerAndrew Godwin2022-11-10 23:42:43 -0700
commitfbfad9fbf5e061cb7c658dada3c4014c9796021c (patch)
tree41cb9c3685e347d506876e18c8e535e3d126f1d9 /core
parent2c3a1299709f2612e96c37e4e121c83ad4df7a56 (diff)
downloadtakahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.tar.gz
takahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.tar.bz2
takahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.zip
Inbound and outbound follows basic working
Diffstat (limited to 'core')
-rw-r--r--core/signatures.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/core/signatures.py b/core/signatures.py
index 805ae91..27e7f7d 100644
--- a/core/signatures.py
+++ b/core/signatures.py
@@ -1,6 +1,6 @@
import base64
import json
-from typing import Dict, List, Literal, TypedDict
+from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict
from urllib.parse import urlparse
import httpx
@@ -8,7 +8,9 @@ from cryptography.hazmat.primitives import hashes
from django.http import HttpRequest
from django.utils.http import http_date
-from users.models import Identity
+# Prevent a circular import
+if TYPE_CHECKING:
+ from users.models import Identity
class HttpSignature:
@@ -73,7 +75,7 @@ class HttpSignature:
self,
uri: str,
body: Dict,
- identity: Identity,
+ identity: "Identity",
content_type: str = "application/json",
method: Literal["post"] = "post",
):
@@ -105,13 +107,17 @@ class HttpSignature:
del headers["(request-target)"]
async with httpx.AsyncClient() as client:
print(f"Calling {method} {uri}")
- print(body)
- return await client.request(
+ response = await client.request(
method,
uri,
headers=headers,
content=body_bytes,
)
+ if response.status_code >= 400:
+ raise ValueError(
+ f"Request error: {response.status_code} {response.content}"
+ )
+ return response
class SignatureDetails(TypedDict):