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) } +}