Skip to content

Commit

Permalink
fix: added missing function in LocalKmsDatabaseConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 28, 2024
1 parent a613730 commit 52b0c0d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions modules/local-kms/src/main/kotlin/KeyRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

@Repository
interface KeyRepository : CrudRepository<Key,
String> {
interface KeyRepository : CrudRepository<Key, String> {

@Query("SELECT * FROM keys WHERE id = :keyId")
fun findByKeyId(keyId: String): Key?
Expand Down
21 changes: 18 additions & 3 deletions modules/local-kms/src/main/kotlin/LocalKmsDatabaseConnection.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sphereon.oid.fed.kms.local

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.dao.EmptyResultDataAccessException
import org.springframework.stereotype.Component

@Component
Expand All @@ -12,8 +13,22 @@ class LocalKmsDatabaseConnection @Autowired constructor(private val keyRepositor
}

fun getKey(keyId: String): Key {
return keyRepository.findByKeyId(keyId) ?: throw Exception("Key not found")
return keyRepository.findByKeyId(keyId) ?: throw KeyNotFoundException("Key with ID $keyId not found")
}

// ... (Implement other methods like updateKey, deleteKey as needed)
}
fun updateKey(keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String) {
val existingKey = keyRepository.findByKeyId(keyId) ?: throw KeyNotFoundException("Key with ID $keyId not found")
val updatedKey = existingKey.copy(privateKey = privateKey, publicKey = publicKey, algorithm = algorithm)
keyRepository.save(updatedKey)
}

fun deleteKey(keyId: String) {
try {
keyRepository.deleteById(keyId)
} catch (e: EmptyResultDataAccessException) {
throw KeyNotFoundException("Key with ID $keyId not found")
}
}
}

class KeyNotFoundException(message: String) : Exception(message)
5 changes: 5 additions & 0 deletions modules/local-kms/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ spring.application.name=OpenID Federation Server
spring.datasource.url=${DATASOURCE_URL}
spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}

# Mapping /actuator/health to /status
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=status
server.port=8080

# Spring Boot to execute the schema.sql script on startup
spring.sql.init.mode=always
spring.datasource.schema=classpath:schema.sql
File renamed without changes.

0 comments on commit 52b0c0d

Please sign in to comment.