Skip to content

Commit 52534db

Browse files
committed
🐛(backend) fix issues with conversion microservice integration
Minor adjustments were needed after working in parallel on two PRs. The microservice now accepts an API key without requiring it as a Bearer token. A mistake in reading the microservice response was corrected after refactoring the serializer to delegate logic to the converter microservice.
1 parent dc9b375 commit 52534db

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/backend/core/api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@ def create(self, validated_data):
275275
language = user.language or language
276276

277277
try:
278-
converter_response = YdocConverter().convert_markdown(
278+
document_content = YdocConverter().convert_markdown(
279279
validated_data["content"]
280280
)
281281
except ConversionError as err:
282282
raise exceptions.APIException(detail="could not convert content") from err
283283

284284
document = models.Document.objects.create(
285285
title=validated_data["title"],
286-
content=converter_response["content"],
286+
content=document_content,
287287
creator=user,
288288
)
289289

src/backend/core/services/converter_services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class YdocConverter:
3131
@property
3232
def auth_header(self):
3333
"""Build microservice authentication header."""
34-
return f"Bearer {settings.CONVERSION_API_KEY}"
34+
return settings.CONVERSION_API_KEY
3535

3636
def convert_markdown(self, text):
3737
"""Convert a Markdown text into our internal format using an external microservice."""
@@ -50,6 +50,7 @@ def convert_markdown(self, text):
5050
"Content-Type": "application/json",
5151
},
5252
timeout=settings.CONVERSION_API_TIMEOUT,
53+
verify=settings.CONVERSION_API_SECURE,
5354
)
5455
response.raise_for_status()
5556
conversion_response = response.json()

src/backend/core/tests/documents/test_api_documents_create_for_owner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def mock_convert_markdown():
2525
with patch.object(
2626
YdocConverter,
2727
"convert_markdown",
28-
return_value={"content": "Converted document content"},
28+
return_value="Converted document content",
2929
) as mock:
3030
yield mock
3131

src/backend/core/tests/test_services_converter_services.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_auth_header(settings):
1818
"""Test authentication header generation."""
1919
settings.CONVERSION_API_KEY = "test-key"
2020
converter = YdocConverter()
21-
assert converter.auth_header == "Bearer test-key"
21+
assert converter.auth_header == "test-key"
2222

2323

2424
def test_convert_markdown_empty_text():
@@ -116,10 +116,11 @@ def test_convert_markdown_full_integration(mock_post, settings):
116116
"http://test.com",
117117
json={"content": "test markdown"},
118118
headers={
119-
"Authorization": "Bearer test-key",
119+
"Authorization": "test-key",
120120
"Content-Type": "application/json",
121121
},
122122
timeout=5,
123+
verify=False,
123124
)
124125

125126

src/backend/impress/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ class Base(Configuration):
524524
environ_name="CONVERSION_API_TIMEOUT",
525525
environ_prefix=None,
526526
)
527+
CONVERSION_API_SECURE = values.Value(
528+
default=False,
529+
environ_name="CONVERSION_API_SECURE",
530+
environ_prefix=None,
531+
)
527532

528533
# Logging
529534
# We want to make it easy to log to console but by default we log production

0 commit comments

Comments
 (0)