Skip to content

Commit c10808b

Browse files
committed
♻️(backend) generalize YProvider API config
Abstracted base URL and API key under 'y-provider' for reuse in future endpoints, aligning with microservice naming. Please note the YProvider API here is internal to the cluster. In facts, we don't want these endpoints to be exposed by any ingress
1 parent ba63358 commit c10808b

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/backend/core/services/converter_services.py

Lines changed: 2 additions & 2 deletions
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 settings.CONVERSION_API_KEY
34+
return settings.Y_PROVIDER_API_KEY
3535

3636
def convert_markdown(self, text):
3737
"""Convert a Markdown text into our internal format using an external microservice."""
@@ -41,7 +41,7 @@ def convert_markdown(self, text):
4141

4242
try:
4343
response = requests.post(
44-
settings.CONVERSION_API_URL,
44+
f"{settings.Y_PROVIDER_API_BASE_URL}{settings.CONVERSION_API_ENDPOINT}/",
4545
json={
4646
"content": text,
4747
},

src/backend/core/tests/test_services_converter_services.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def test_auth_header(settings):
1818
"""Test authentication header generation."""
19-
settings.CONVERSION_API_KEY = "test-key"
19+
settings.Y_PROVIDER_API_KEY = "test-key"
2020
converter = YdocConverter()
2121
assert converter.auth_header == "test-key"
2222

@@ -97,8 +97,9 @@ def test_convert_markdown_missing_content_field(mock_post, settings):
9797
def test_convert_markdown_full_integration(mock_post, settings):
9898
"""Test full integration with all settings."""
9999

100-
settings.CONVERSION_API_URL = "http://test.com"
101-
settings.CONVERSION_API_KEY = "test-key"
100+
settings.Y_PROVIDER_API_BASE_URL = "http://test.com/"
101+
settings.Y_PROVIDER_API_KEY = "test-key"
102+
settings.CONVERSION_API_ENDPOINT = "conversion-endpoint"
102103
settings.CONVERSION_API_TIMEOUT = 5
103104
settings.CONVERSION_API_CONTENT_FIELD = "content"
104105

@@ -113,7 +114,7 @@ def test_convert_markdown_full_integration(mock_post, settings):
113114

114115
assert result == expected_content
115116
mock_post.assert_called_once_with(
116-
"http://test.com",
117+
"http://test.com/conversion-endpoint/",
117118
json={"content": "test markdown"},
118119
headers={
119120
"Authorization": "test-key",

src/backend/impress/settings.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,21 @@ class Base(Configuration):
505505
"day": 200,
506506
}
507507

508-
# Conversion microservice
509-
CONVERSION_API_KEY = values.Value(
510-
environ_name="CONVERSION_API_KEY",
508+
# Y provider microservice
509+
# Note: Be careful, this value is currently the same as in the collaboration service.
510+
Y_PROVIDER_API_KEY = values.Value(
511+
environ_name="Y_PROVIDER_API_KEY",
511512
environ_prefix=None,
512513
)
513-
CONVERSION_API_URL = values.Value(
514-
environ_name="CONVERSION_API_URL",
514+
Y_PROVIDER_API_BASE_URL = values.Value(
515+
environ_name="Y_PROVIDER_API_BASE_URL",
516+
environ_prefix=None,
517+
)
518+
519+
# Conversion endpoint
520+
CONVERSION_API_ENDPOINT = values.Value(
521+
default="convert-markdown",
522+
environ_name="CONVERSION_API_ENDPOINT",
515523
environ_prefix=None,
516524
)
517525
CONVERSION_API_CONTENT_FIELD = values.Value(

src/helm/env.d/dev/values.impress.yaml.gotmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ backend:
5151
AWS_S3_SECRET_ACCESS_KEY: password
5252
AWS_STORAGE_BUCKET_NAME: impress-media-storage
5353
STORAGES_STATICFILES_BACKEND: django.contrib.staticfiles.storage.StaticFilesStorage
54-
CONVERSION_API_URL: http://impress-y-provider:443/api/convert-markdown/
55-
CONVERSION_API_KEY: my-secret
54+
Y_PROVIDER_API_BASE_URL: http://impress-y-provider:443/api/
55+
Y_PROVIDER_API_KEY: my-secret
5656

5757
migrate:
5858
command:

0 commit comments

Comments
 (0)