add ConfigurationController

This commit is contained in:
2024-11-30 18:37:19 +01:00
parent 47bfa9802c
commit a8f1a4d38b
2 changed files with 35 additions and 0 deletions

4
http/configuration.http Normal file
View File

@@ -0,0 +1,4 @@
### get measurement
GET {{hostname}}/configuration
Content-Type: application/json
Identity: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@@ -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<String, String> = extracted(identityToken)
.let { configurationService.getConfiguration(it.node).toDeviceResponse() }
private suspend fun extracted(
identityToken: String,
): Identity.Response = jwtService.readIdentity(identityToken)
.let { deviceRegistry.getIdentityFromDevice(it) }
}