From 23bb178e0caffc4511dd7d00676175e10965cd1a Mon Sep 17 00:00:00 2001 From: Nicholas <3789764+skykanin@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:40:23 +0100 Subject: [PATCH] Implement refresh endpoint (as an admin endpoint) (#522) --- README.md | 8 +++ .../controller/api/admin/AdminController.java | 49 +++++++++++++++++++ .../src/main/resources/application.properties | 4 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/admin/AdminController.java diff --git a/README.md b/README.md index 5167b113..0abed96e 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,14 @@ Configurable properties : | `event.webhook.includes` | | List of events types to send the webhook for (empty = all events). e.g `service.uninstall,service.install` | | `event.webhook.excludes` | | List of events types to ignore for the webhook. e.g `service.uninstall,service.install` | +### Admin configuration: +:warning: This section should be considered pre-alpha and may be subject to major changes and revamps :warning: + +| Key | Default | Description | +|------------------|-----|--------------------------------------------------------------------------------------------| +| `admin.enabled` | `false` | Whether to enable the admin endpoints. :warning: Do not use this in production ! :warning: | + + ### Other configurations | Key | Default | Description | | --------------------- | ------- | ------------------------------------------------------------------ | diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/admin/AdminController.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/admin/AdminController.java new file mode 100644 index 00000000..0c156ef4 --- /dev/null +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/controller/api/admin/AdminController.java @@ -0,0 +1,49 @@ +package fr.insee.onyxia.api.controller.api.admin; + +import fr.insee.onyxia.api.dao.universe.*; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Admin", description = "Restricted API endpoints") +@RequestMapping("/admin") +@RestController +@SecurityRequirement(name = "auth") +@ConditionalOnExpression("'${admin.enabled}' == 'true'") +public class AdminController { + + private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class); + private final CatalogRefresher catalogRefresher; + + @PostConstruct + private void postConstruct() { + LOGGER.warn( + """ + + + + + ADMIN MODE IS ENABLED, DON'T USE THIS IN PRODUCTION + + + + """); + } + + @Autowired + public AdminController(CatalogRefresher catalogRefresher) { + this.catalogRefresher = catalogRefresher; + } + + @GetMapping("/refreshCatalogs") + public void refreshCatalogs() { + catalogRefresher.run(); + } +} diff --git a/onyxia-api/src/main/resources/application.properties b/onyxia-api/src/main/resources/application.properties index 13fa3f9b..89b1f15e 100644 --- a/onyxia-api/src/main/resources/application.properties +++ b/onyxia-api/src/main/resources/application.properties @@ -41,4 +41,6 @@ event.webhook.includes= # List of events types to ignore for the webhook. e.g service.uninstall,service.install event.webhook.excludes= # Response stream configuration -spring.mvc.async.request-timeout=600000 \ No newline at end of file +spring.mvc.async.request-timeout=600000 +# Enabled admin endpoints +admin.enabled=false