4 Commits

Author SHA1 Message Date
2a69d06d7f [RELEASE] - release version: 0.2.0 2024-12-10 23:25:26 +01:00
d5746aa22d update for common messages v0.2.0
- change DeviceController addDevice to use toDeviceResponse
- add DeviceEntity.toDeviceResponse to Mapping.kt
2024-12-10 21:28:58 +01:00
5d36099738 update for common plugin v0.2.0
- rename keys folder to cert
- update build.gradle.kts to use certificate plugin
- update catalog version
2024-12-10 19:20:14 +01:00
5c2e2e617e [RELEASE] - bump version 2024-11-26 11:42:12 +01:00
11 changed files with 37 additions and 35 deletions

2
.gitignore vendored
View File

@@ -40,4 +40,4 @@ out/
.kotlin .kotlin
### Cert ### ### Cert ###
/keys/ /cert/

View File

@@ -1,47 +1,40 @@
plugins { plugins {
alias(hlaeja.plugins.kotlin.jvm) alias(hlaeja.plugins.kotlin.jvm)
alias(hlaeja.plugins.kotlin.spring) alias(hlaeja.plugins.kotlin.spring)
alias(hlaeja.plugins.ltd.hlaeja.plugin.certificate)
alias(hlaeja.plugins.ltd.hlaeja.plugin.service) alias(hlaeja.plugins.ltd.hlaeja.plugin.service)
alias(hlaeja.plugins.spring.dependency.management) alias(hlaeja.plugins.spring.dependency.management)
alias(hlaeja.plugins.springframework.boot) alias(hlaeja.plugins.springframework.boot)
} }
dependencies { dependencies {
implementation(hlaeja.com.fasterxml.jackson.module.kotlin) implementation(hlaeja.fasterxml.jackson.module.kotlin)
implementation(hlaeja.jjwt.api) implementation(hlaeja.jjwt.api)
implementation(hlaeja.kotlin.logging) implementation(hlaeja.kotlin.logging)
implementation(hlaeja.kotlin.reflect) implementation(hlaeja.kotlin.reflect)
implementation(hlaeja.kotlinx.coroutines) implementation(hlaeja.kotlinx.coroutines)
implementation(hlaeja.ltd.hlaeja.library.common.messages) implementation(hlaeja.library.hlaeja.common.messages)
implementation(hlaeja.org.springframework.springboot.actuator.starter) implementation(hlaeja.springboot.starter.actuator)
implementation(hlaeja.org.springframework.springboot.r2dbc.starter) implementation(hlaeja.springboot.starter.r2dbc)
implementation(hlaeja.org.springframework.springboot.webflux.starter) implementation(hlaeja.springboot.starter.webflux)
runtimeOnly(hlaeja.jjwt.impl) runtimeOnly(hlaeja.jjwt.impl)
runtimeOnly(hlaeja.jjwt.jackson) runtimeOnly(hlaeja.jjwt.jackson)
runtimeOnly(hlaeja.org.postgresql) runtimeOnly(hlaeja.postgresql)
runtimeOnly(hlaeja.org.postgresql.r2dbc) runtimeOnly(hlaeja.postgresql.r2dbc)
testImplementation(hlaeja.assertj.core) testImplementation(hlaeja.assertj.core)
testImplementation(hlaeja.io.mockk) testImplementation(hlaeja.mockk)
testImplementation(hlaeja.io.projectreactor.reactor.test) testImplementation(hlaeja.projectreactor.reactor.test)
testImplementation(hlaeja.kotlin.test.junit5) testImplementation(hlaeja.kotlin.test.junit5)
testImplementation(hlaeja.kotlinx.coroutines.test) testImplementation(hlaeja.kotlinx.coroutines.test)
testImplementation(hlaeja.org.springframework.springboot.test.starter) testImplementation(hlaeja.springboot.starter.test)
testRuntimeOnly(hlaeja.org.junit.platform.launcher) testRuntimeOnly(hlaeja.junit.platform.launcher)
} }
group = "ltd.hlaeja" group = "ltd.hlaeja"
tasks { tasks.named("processResources") {
named("processResources") { dependsOn("copyCertificates")
dependsOn("copyPrivateKey")
}
register<Copy>("copyPrivateKey") {
group = "hlaeja"
from("keys/private_key.pem")
into("${layout.buildDirectory.get()}/resources/main/keys")
onlyIf { file("keys/private_key.pem").exists() }
}
} }

View File

@@ -1,4 +1,4 @@
kotlin.code.style=official kotlin.code.style=official
version=0.1.0 version=0.2.0
catalog=0.4.0 catalog=0.6.0
container.port.host=9010 container.port.host=9010

View File

@@ -3,11 +3,10 @@ package ltd.hlaeja.controller
import ltd.hlaeja.library.deviceRegistry.Device import ltd.hlaeja.library.deviceRegistry.Device
import ltd.hlaeja.service.DeviceService import ltd.hlaeja.service.DeviceService
import ltd.hlaeja.service.JwtService import ltd.hlaeja.service.JwtService
import org.springframework.http.HttpStatus.EXPECTATION_FAILED import ltd.hlaeja.util.toDeviceResponse
import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ResponseStatusException
@RestController @RestController
class DeviceController( class DeviceController(
@@ -18,7 +17,6 @@ class DeviceController(
@PostMapping("/device") @PostMapping("/device")
suspend fun addDevice( suspend fun addDevice(
@RequestBody request: Device.Request, @RequestBody request: Device.Request,
): Device.Identity = deviceService.addDevice(request.type) ): Device.Response = deviceService.addDevice(request.type)
.let { jwtService.makeIdentity(it.id ?: throw ResponseStatusException(EXPECTATION_FAILED)) } .toDeviceResponse(jwtService)
.let { Device.Identity(it) }
} }

View File

@@ -1,11 +1,14 @@
package ltd.hlaeja.util package ltd.hlaeja.util
import java.time.ZonedDateTime import java.time.ZonedDateTime
import ltd.hlaeja.entity.DeviceEntity
import ltd.hlaeja.entity.NodeEntity import ltd.hlaeja.entity.NodeEntity
import ltd.hlaeja.entity.TypeEntity import ltd.hlaeja.entity.TypeEntity
import ltd.hlaeja.library.deviceRegistry.Device
import ltd.hlaeja.library.deviceRegistry.Identity import ltd.hlaeja.library.deviceRegistry.Identity
import ltd.hlaeja.library.deviceRegistry.Node import ltd.hlaeja.library.deviceRegistry.Node
import ltd.hlaeja.library.deviceRegistry.Type import ltd.hlaeja.library.deviceRegistry.Type
import ltd.hlaeja.service.JwtService
import org.springframework.http.HttpStatus.EXPECTATION_FAILED import org.springframework.http.HttpStatus.EXPECTATION_FAILED
import org.springframework.web.server.ResponseStatusException import org.springframework.web.server.ResponseStatusException
@@ -36,3 +39,11 @@ fun NodeEntity.toIdentityResponse(): Identity.Response = Identity.Response(
id ?: throw ResponseStatusException(EXPECTATION_FAILED), id ?: throw ResponseStatusException(EXPECTATION_FAILED),
device, device,
) )
suspend fun DeviceEntity.toDeviceResponse(
jwtService: JwtService,
): Device.Response = Device.Response(
id ?: throw ResponseStatusException(EXPECTATION_FAILED),
type,
jwtService.makeIdentity(id),
)

View File

@@ -11,7 +11,7 @@ spring:
version: "%APP_BUILD_OS_VERSION%" version: "%APP_BUILD_OS_VERSION%"
jwt: jwt:
private-key: keys/private_key.pem private-key: cert/private_key.pem
--- ---
############################### ###############################

View File

@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test
class JwtServiceTest { class JwtServiceTest {
val property: JwtProperty = JwtProperty("keys/valid-private-key.pem") val property: JwtProperty = JwtProperty("cert/valid-private-key.pem")
lateinit var service: JwtService lateinit var service: JwtService
@BeforeEach @BeforeEach

View File

@@ -11,7 +11,7 @@ class PrivateKeyProviderTest {
@Test @Test
fun `load private key - success`() { fun `load private key - success`() {
// given // given
val pemFilePath = "keys/valid-private-key.pem" val pemFilePath = "cert/valid-private-key.pem"
// when // when
val privateKey: RSAPrivateKey = PrivateKeyProvider.load(pemFilePath) val privateKey: RSAPrivateKey = PrivateKeyProvider.load(pemFilePath)
@@ -24,7 +24,7 @@ class PrivateKeyProviderTest {
@Test @Test
fun `load private key - file does not exist`() { fun `load private key - file does not exist`() {
// given // given
val nonExistentPemFilePath = "keys/non-existent.pem" val nonExistentPemFilePath = "cert/non-existent.pem"
// when exception // when exception
val exception = assertThrows<KeyProviderException> { val exception = assertThrows<KeyProviderException> {
@@ -38,7 +38,7 @@ class PrivateKeyProviderTest {
@Test @Test
fun `load private key - file is invalid`() { fun `load private key - file is invalid`() {
// given // given
val invalidPemFilePath = "keys/invalid-private-key.pem" val invalidPemFilePath = "cert/invalid-private-key.pem"
// when exception // when exception
val exception = assertThrows<IllegalArgumentException> { val exception = assertThrows<IllegalArgumentException> {

View File

@@ -1,5 +1,5 @@
jwt: jwt:
private-key: keys/valid-private-key.pem private-key: cert/valid-private-key.pem
spring: spring:
r2dbc: r2dbc: