From a8f1a4d38b356032ddc928f90edf5b1ab7787c5b Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Sat, 30 Nov 2024 18:37:19 +0100 Subject: [PATCH] add ConfigurationController --- http/configuration.http | 4 +++ .../controller/ConfigurationController.kt | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 http/configuration.http create mode 100644 src/main/kotlin/ltd/hlaeja/controller/ConfigurationController.kt diff --git a/http/configuration.http b/http/configuration.http new file mode 100644 index 0000000..b81c551 --- /dev/null +++ b/http/configuration.http @@ -0,0 +1,4 @@ +### get measurement +GET {{hostname}}/configuration +Content-Type: application/json +Identity: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/src/main/kotlin/ltd/hlaeja/controller/ConfigurationController.kt b/src/main/kotlin/ltd/hlaeja/controller/ConfigurationController.kt new file mode 100644 index 0000000..222e577 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/controller/ConfigurationController.kt @@ -0,0 +1,31 @@ +package ltd.hlaeja.controller + +import ltd.hlaeja.library.deviceRegistry.Identity +import ltd.hlaeja.service.DeviceConfigurationService +import ltd.hlaeja.service.DeviceRegistryService +import ltd.hlaeja.service.JwtService +import ltd.hlaeja.util.toDeviceResponse +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestHeader +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/configuration") +class ConfigurationController( + private val configurationService: DeviceConfigurationService, + private val deviceRegistry: DeviceRegistryService, + private val jwtService: JwtService, +) { + + @GetMapping + suspend fun getNodeConfiguration( + @RequestHeader("Identity") identityToken: String, + ): Map = extracted(identityToken) + .let { configurationService.getConfiguration(it.node).toDeviceResponse() } + + private suspend fun extracted( + identityToken: String, + ): Identity.Response = jwtService.readIdentity(identityToken) + .let { deviceRegistry.getIdentityFromDevice(it) } +}