Skip to content

Commit

Permalink
Implement refresh endpoint (as an admin endpoint) (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
skykanin authored Nov 22, 2024
1 parent b27fef3 commit 23bb178
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --------------------- | ------- | ------------------------------------------------------------------ |
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 3 additions & 1 deletion onyxia-api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
spring.mvc.async.request-timeout=600000
# Enabled admin endpoints
admin.enabled=false

0 comments on commit 23bb178

Please sign in to comment.