From fdabd556efaa34cc68f32a6f8a665cef3b93a6a7 Mon Sep 17 00:00:00 2001 From: Fabre Florian Date: Tue, 14 Oct 2025 15:31:21 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(backend)=20add=20development=20servic?= =?UTF-8?q?e=20for=20drive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The create_demo command will now create a 'drive' service for development purpose. Add setup documentation. Signed-off-by: Fabre Florian --- CHANGELOG.md | 1 + docs/setup-for-docs.md | 9 ++-- docs/setup-for-drive.md | 43 +++++++++++++++++++ docs/setup-indexer.md | 8 +++- src/backend/demo/defaults.py | 5 +++ .../demo/tests/test_commands_create_demo.py | 5 ++- 6 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 docs/setup-for-drive.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3c065..f30b54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,3 +21,4 @@ and this project adheres to - ✨(backend) limit search to the calling app (audience) and a configured list of services - 🔧(compose) rename docker network 'lasuite-net' as 'lasuite-network' +- ✨(backend) add demo service for Drive. diff --git a/docs/setup-for-docs.md b/docs/setup-for-docs.md index 353a99c..6358108 100644 --- a/docs/setup-for-docs.md +++ b/docs/setup-for-docs.md @@ -21,13 +21,12 @@ Add those Django settings the Docs application to enable the feature. SEARCH_INDEXER_CLASS="core.services.search_indexers.FindDocumentIndexer" SEARCH_INDEXER_COUNTDOWN=10 # Debounce delay in seconds for the indexer calls. -# Indexation endpoint. -SEARCH_INDEXER_SECRET=my-token-from-the-find-impress-service -# The token from service "docs" of Find application. -SEARCH_INDEXER_URL="http://app-find:8000/api/v1.0/documents/index/" +# The token from service "docs" of Find application (development). +SEARCH_INDEXER_SECRET="find-api-key-for-docs-with-exactly-50-chars-length" +SEARCH_INDEXER_URL="http://find:8000/api/v1.0/documents/index/" # Search endpoint. Uses the OIDC token for authentication -SEARCH_INDEXER_QUERY_URL="http://app-find:8000/api/v1.0/documents/search/" +SEARCH_INDEXER_QUERY_URL="http://find:8000/api/v1.0/documents/search/" ``` We also need to enable the **OIDC Token** refresh or the authentication will fail quickly. diff --git a/docs/setup-for-drive.md b/docs/setup-for-drive.md new file mode 100644 index 0000000..54af6dd --- /dev/null +++ b/docs/setup-for-drive.md @@ -0,0 +1,43 @@ +# Setup the Find search for Drive + +This configuration will enable the fulltext search feature for Docs : +- Each save on **core.Item** or **core.Item** will trigger the indexer +- Once indexer service configured, the `api/v1.0/item/search/` will work as a proxy with the Find API for fulltext search. + +## Create an index service for Drive + +Configure a **Service** for Docs application with these settings + +- **Name**: `drive`
_request.auth.name of the Docs application._ +- **Client id**: `drive`
_Name of the token audience or client_id of the Docs application._ + +See [how-to-use-indexer.md](how-to-use-indexer.md) for details. + +## Configure settings of Drive + +Add those Django settings the Docs application to enable the feature. + +```python +SEARCH_INDEXER_CLASS="core.services.search_indexers.SearchIndexer" +SEARCH_INDEXER_COUNTDOWN=10 # Debounce delay in seconds for the indexer calls. + +# The token from service "drive" of Find application (development) +SEARCH_INDEXER_SECRET=find-api-key-for-driv-with-exactly-50-chars-length +SEARCH_INDEXER_URL="http://find:8000/api/v1.0/documents/index/" + +# Search endpoint. Uses the OIDC token for authentication +SEARCH_INDEXER_QUERY_URL="http://find:8000/api/v1.0/documents/search/" + +# Limit the mimetypes and size of indexable files +SEARCH_INDEXER_ALLOWED_MIMETYPES=["text/"] +SEARCH_INDEXER_UPLOAD_MAX_SIZE=2 * 2**20 # 2Mb +``` + +We also need to enable the **OIDC Token** refresh or the authentication will fail quickly. + +```shell +# Store OIDC tokens in the session +OIDC_STORE_ACCESS_TOKEN = True # Store the access token in the session +OIDC_STORE_REFRESH_TOKEN = True # Store the encrypted refresh token in the session +OIDC_STORE_REFRESH_TOKEN_KEY = "your-32-byte-encryption-key==" # Must be a valid Fernet key (32 url-safe base64-encoded bytes) +``` diff --git a/docs/setup-indexer.md b/docs/setup-indexer.md index f49b8c2..79a079e 100644 --- a/docs/setup-indexer.md +++ b/docs/setup-indexer.md @@ -65,12 +65,18 @@ And add the key in the calling application Django settings. **Development Mode (Docs + Find)** -The command `make demo` will create a working service configuration for `docs` with the following secret key +The command `make demo` will create a working service configuration for `docs` and `drive` with predefined secret keys ```python +# Docs SEARCH_INDEXER_SECRET="find-api-key-for-docs-with-exactly-50-chars-length" ``` +```python +# Drive +SEARCH_INDEXER_SECRET="find-api-key-for-driv-with-exactly-50-chars-length" +``` + ## Setup search API The **`/search/`** endpoint is an OIDC ResourceServer view and needs extra Django settings (see [lasuite](https://github.com/suitenumerique/django-lasuite/blob/main/documentation/how-to-use-oidc-resource-server-backend.md) for details) diff --git a/src/backend/demo/defaults.py b/src/backend/demo/defaults.py index 234b989..b487448 100644 --- a/src/backend/demo/defaults.py +++ b/src/backend/demo/defaults.py @@ -8,4 +8,9 @@ DEV_SERVICES = ( "client_id": "impress", "token": "find-api-key-for-docs-with-exactly-50-chars-length", }, + { + "name": "drive", + "client_id": "drive", + "token": "find-api-key-for-driv-with-exactly-50-chars-length", + }, ) diff --git a/src/backend/demo/tests/test_commands_create_demo.py b/src/backend/demo/tests/test_commands_create_demo.py index c9e8bbc..fde484d 100644 --- a/src/backend/demo/tests/test_commands_create_demo.py +++ b/src/backend/demo/tests/test_commands_create_demo.py @@ -26,8 +26,11 @@ def test_commands_create_demo(): """The create_demo management command should create objects as expected.""" call_command("create_demo") - assert models.Service.objects.exclude(name="docs").count() == 2 + assert models.Service.objects.exclude(name="docs").count() == 3 assert opensearch_client().count()["count"] == 4 docs = models.Service.objects.get(name="docs") assert docs.client_id == "impress" + + drive = models.Service.objects.get(name="drive") + assert drive.client_id == "drive"