Skip to content

Commit b7c66c6

Browse files
committed
✨(backend) add settings to configure drive external service
We want to add ability to Messages to interop with our Drive application. First, we want to be able to set the Drive base url through environment variable then pass down Drive configuration to frontend through the config api endpoint. https://github.com/suitenumerique/drive
1 parent e1c0dea commit b7c66c6

File tree

9 files changed

+114
-2
lines changed

9 files changed

+114
-2
lines changed

docs/env.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ The application uses a new environment file structure with `.defaults` and `.loc
268268
| `AI_MODEL` | None | Default model used for AI features | Optional |
269269
| `AI_FEATURE_SUMMARY_ENABLED` | `False` | Default enabled mode for summary AI features | Required |
270270

271+
### External Services
272+
273+
#### Drive
274+
275+
| Variable | Default | Description | Required |
276+
|----------|---------|-------------|----------|
277+
| `DRIVE_BASE_URL` | None | Base URL to access Drive endpoints | Optional |
278+
279+
280+
271281
## Legend
272282

273283
- **Required**: Must be set for the application to function

env.d/development/backend.defaults

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ MTA_OUT_SMTP_PASSWORD=pass
7373
MDA_API_SECRET=my-shared-secret-mda
7474
SALT_KEY=ThisIsAnExampleSaltForDevPurposeOnly
7575

76-
# AI
76+
# AI
7777
AI_BASE_URL=
7878
AI_API_KEY=
7979
AI_MODEL=
8080

81-
AI_FEATURE_SUMMARY_ENABLED=False
81+
AI_FEATURE_SUMMARY_ENABLED=False
82+
83+
# Interoperability
84+
# Drive - https://github.com/suitenumerique/drive
85+
DRIVE_BASE_URL=

src/backend/core/api/openapi.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@
181181
"AI_FEATURE_SUMMARY_ENABLED": {
182182
"type": "boolean",
183183
"readOnly": true
184+
},
185+
"DRIVE": {
186+
"type": "object",
187+
"description": "The URLs of the Drive external service.",
188+
"properties": {
189+
"sdk_url": {
190+
"type": "string",
191+
"readOnly": true
192+
},
193+
"api_url": {
194+
"type": "string",
195+
"readOnly": true
196+
}
197+
},
198+
"readOnly": true,
199+
"required": [
200+
"sdk_url",
201+
"api_url"
202+
]
184203
}
185204
},
186205
"required": [

src/backend/core/api/viewsets/config.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ class ConfigView(drf.views.APIView):
4949
"type": "boolean",
5050
"readOnly": True,
5151
},
52+
"DRIVE": {
53+
"type": "object",
54+
"description": "The URLs of the Drive external service.",
55+
"properties": {
56+
"sdk_url": {
57+
"type": "string",
58+
"readOnly": True,
59+
},
60+
"api_url": {
61+
"type": "string",
62+
"readOnly": True,
63+
},
64+
},
65+
"readOnly": True,
66+
"required": ["sdk_url", "api_url"],
67+
},
5268
},
5369
"required": [
5470
"ENVIRONMENT",
@@ -83,7 +99,19 @@ def get(self, request):
8399
if hasattr(settings, setting):
84100
dict_settings[setting] = getattr(settings, setting)
85101

102+
# AI Features
86103
dict_settings["AI_ENABLED"] = is_ai_enabled()
87104
dict_settings["AI_FEATURE_SUMMARY_ENABLED"] = is_ai_summary_enabled()
88105

106+
# Drive service
107+
if base_url := settings.DRIVE_CONFIG.get("base_url"):
108+
dict_settings.update(
109+
{
110+
"DRIVE": {
111+
"sdk_url": f"{base_url}{settings.DRIVE_CONFIG.get('sdk_url')}",
112+
"api_url": f"{base_url}{settings.DRIVE_CONFIG.get('api_url')}",
113+
}
114+
}
115+
)
116+
89117
return drf.response.Response(dict_settings)

src/backend/core/tests/api/test_config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
AI_BASE_URL=None,
2626
AI_MODEL=None,
2727
AI_FEATURE_SUMMARY_ENABLED=False,
28+
DRIVE_CONFIG={"base_url": None},
2829
)
2930
@pytest.mark.parametrize("is_authenticated", [False, True])
3031
def test_api_config(is_authenticated):
@@ -47,3 +48,22 @@ def test_api_config(is_authenticated):
4748
"AI_ENABLED": False,
4849
"AI_FEATURE_SUMMARY_ENABLED": False,
4950
}
51+
52+
53+
@override_settings(
54+
DRIVE_CONFIG={
55+
"base_url": "http://localhost:8902",
56+
"sdk_url": "/sdk",
57+
"api_url": "/api/v1.0",
58+
}
59+
)
60+
def test_api_config_with_external_services():
61+
"""If Drive external service is configured, it should be included in the configuration."""
62+
client = APIClient()
63+
64+
response = client.get("/api/v1.0/config/")
65+
assert response.status_code == HTTP_200_OK
66+
assert response.json().get("DRIVE") == {
67+
"sdk_url": "http://localhost:8902/sdk",
68+
"api_url": "http://localhost:8902/api/v1.0",
69+
}

src/backend/messages/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ class Base(Configuration):
592592
environ_prefix=None,
593593
)
594594

595+
# External services
596+
# Settings related to the interoperability with external services
597+
# that messges is able to use
598+
# 1. Drive - https://github.com/suitenumerique/drive
599+
DRIVE_CONFIG = {
600+
"base_url": values.Value(
601+
default=None, environ_name="DRIVE_BASE_URL", environ_prefix=None
602+
),
603+
"sdk_url": "/sdk",
604+
"api_url": "/api/v1.0",
605+
}
606+
595607
# pylint: disable=invalid-name
596608
def __init__(self, *args, **kwargs):
597609
super().__init__(*args, **kwargs)

src/frontend/src/features/api/gen/models/config_retrieve200.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* This is the messages API schema.
66
* OpenAPI spec version: 1.0.0 (v1.0)
77
*/
8+
import type { ConfigRetrieve200DRIVE } from "./config_retrieve200_driv_e";
89

910
export type ConfigRetrieve200 = {
1011
readonly ENVIRONMENT: string;
@@ -18,4 +19,6 @@ export type ConfigRetrieve200 = {
1819
readonly LANGUAGE_CODE: string;
1920
readonly AI_ENABLED: boolean;
2021
readonly AI_FEATURE_SUMMARY_ENABLED: boolean;
22+
/** The URLs of the Drive external service. */
23+
readonly DRIVE?: ConfigRetrieve200DRIVE;
2124
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Generated by orval v7.10.0 🍺
3+
* Do not edit manually.
4+
* messages API
5+
* This is the messages API schema.
6+
* OpenAPI spec version: 1.0.0 (v1.0)
7+
*/
8+
9+
/**
10+
* The URLs of the Drive external service.
11+
*/
12+
export type ConfigRetrieve200DRIVE = {
13+
readonly sdk_url: string;
14+
readonly api_url: string;
15+
};

src/frontend/src/features/api/gen/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export * from "./blob_upload_create201";
1111
export * from "./blob_upload_create_body";
1212
export * from "./change_flag_request_request";
1313
export * from "./config_retrieve200";
14+
export * from "./config_retrieve200_driv_e";
1415
export * from "./contact";
1516
export * from "./contacts_list_params";
1617
export * from "./dnscheck_response";

0 commit comments

Comments
 (0)