Skip to content

Commit 846ef4c

Browse files
committed
chore: small fixes
1 parent dcca246 commit 846ef4c

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"version": "21",
3434
"jdkDistro": "open"
3535
},
36-
"./solr": {}
36+
// "./solr": {}
3737
},
3838
"overrideFeatureInstallOrder": [
3939
"ghcr.io/devcontainers-extra/features/poetry",

components/renku_data_services/activitypub/blueprints.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,22 @@ async def _webfinger(request: Request) -> JSONResponse:
264264
def host_meta(self) -> BlueprintFactoryResponse:
265265
"""Host metadata endpoint."""
266266

267-
async def _host_meta(request: Request) -> HTTPResponse:
268-
host_meta_xml = f"""<?xml version="1.0" encoding="UTF-8"?>
269-
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
270-
<Link rel="lrdd" template="{self.config.base_url}/ap/webfinger?resource={{uri}}"/>
271-
</XRD>"""
272-
267+
async def _host_meta_handler(request: Request) -> HTTPResponse:
268+
# Create the XML response
269+
template = self.config.base_url + "/ap/webfinger?resource={uri}"
270+
xml_content = '<?xml version="1.0" encoding="UTF-8"?>\n'
271+
xml_content += '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n'
272+
xml_content += f' <Link rel="lrdd" template="{template}"/>\n'
273+
xml_content += '</XRD>'
274+
275+
# Return the response
273276
return text(
274-
host_meta_xml,
277+
xml_content,
275278
status=200,
276279
headers={"Content-Type": "application/xrd+xml"},
277280
)
278281

279-
return "/ap/.well-known/host-meta", ["GET"], _host_meta
282+
return "/ap/.well-known/host-meta", ["GET"], _host_meta_handler
280283

281284
def nodeinfo(self) -> BlueprintFactoryResponse:
282285
"""NodeInfo endpoint."""

components/renku_data_services/activitypub/core.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import UTC, datetime
66
from typing import Any, Dict, List, Optional, Union
77
import urllib.parse
8+
import dataclasses
89

910
import httpx
1011
from cryptography.hazmat.primitives.asymmetric import padding
@@ -227,7 +228,7 @@ async def _deliver_activity(
227228

228229
if response.status_code >= 400:
229230
logger.error(f"Failed to deliver activity to {inbox_url}: {response.status_code} {response.text}")
230-
raise errors.ExternalServiceError(
231+
raise errors.ProgrammingError(
231232
message=f"Failed to deliver activity to {inbox_url}: {response.status_code}"
232233
)
233234

@@ -288,23 +289,22 @@ async def _build_signature_headers(
288289
"Accept": "application/activity+json",
289290
}
290291

291-
def _to_dict(self, obj: Any) -> Dict[str, Any]:
292+
def _to_dict(self, obj: Any) -> Any:
292293
"""Convert an object to a dictionary."""
293294
if isinstance(obj, dict):
294295
return {k: self._to_dict(v) for k, v in obj.items()}
295296
elif isinstance(obj, list):
296297
return [self._to_dict(item) for item in obj]
297-
elif hasattr(obj, "__dataclass_fields__"):
298-
# It's a dataclass
298+
elif dataclasses.is_dataclass(obj) and not isinstance(obj, type):
299+
# Convert dataclass instance to dict
299300
result = {}
300-
for field_name in obj.__dataclass_fields__:
301-
value = getattr(obj, field_name)
302-
if value is not None: # Skip None values
301+
for field_name, field_value in dataclasses.asdict(obj).items():
302+
if field_value is not None: # Skip None values
303303
if field_name == "context":
304304
# Special case for @context
305-
result["@context"] = self._to_dict(value)
305+
result["@context"] = field_value
306306
else:
307-
result[field_name] = self._to_dict(value)
307+
result[field_name] = field_value
308308
return result
309309
elif isinstance(obj, datetime):
310310
return obj.isoformat()

0 commit comments

Comments
 (0)