Skip to content

Commit

Permalink
fix: change to SQLDelight
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 29, 2024
1 parent 52b0c0d commit e6d167f
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 130 deletions.
19 changes: 0 additions & 19 deletions .docker/local-kms/Dockerfile

This file was deleted.

17 changes: 0 additions & 17 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,6 @@ services:
networks:
- openid_network

local-kms:
build:
context: .
dockerfile: ./.docker/local-kms/Dockerfile
ports:
- "8082:8082"
container_name: openid-federation-local-kms
environment:
DATASOURCE_URL: ${DATASOURCE_URL}
DATASOURCE_USER: ${DATASOURCE_USER}
DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD}
depends_on:
db:
condition: service_healthy
networks:
- openid_network

networks:
openid_network:
driver: bridge
Expand Down
43 changes: 31 additions & 12 deletions modules/local-kms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
alias(libs.plugins.springboot)
alias(libs.plugins.springDependencyManagement)
alias(libs.plugins.kotlinJvm)
kotlin("multiplatform") version "2.0.0"
id("app.cash.sqldelight") version "2.0.2"
}

group = "com.sphereon.oid.fed.kms.local"
Expand All @@ -13,16 +12,36 @@ repositories {
google()
}

dependencies {
testImplementation(kotlin("test"))
implementation(projects.modules.services)
implementation(libs.springboot.data.jdbc)
testImplementation(libs.springboot.test)
sqldelight {
databases {
create("Database") {
packageName = "com.sphereon.oid.fed.kms.local"
dialect("app.cash.sqldelight:postgresql-dialect:2.0.2")
schemaOutputDirectory = file("src/commonMain/resources/db/migration")
migrationOutputDirectory = file("src/commonMain/resources/db/migration")
deriveSchemaFromMigrations = true
migrationOutputFileFormat = ".sql"
srcDirs.from(
"src/commonMain/sqldelight"
)
}
}
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
jvm()

sourceSets {
commonMain {
dependencies {
implementation(projects.modules.services)
}
}

jvmMain {
dependencies {
implementation("app.cash.sqldelight:sqlite-driver:2.0.2")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.sphereon.oid.fed.kms.local
import com.sphereon.oid.fed.persistence.models.Jwk
import com.sphereon.oid.fed.services.KmsClient

class LocalKmsClient(private val database: LocalKmsDatabaseConnection) : KmsClient {
class LocalKmsClient(private val database: LocalKmsDatabase) : KmsClient {

override fun generateKeyPair(keyId: String): Jwk {
TODO("Not yet implemented")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sphereon.oid.fed.kms.local

import com.sphereon.oid.fed.kms.local.models.Keys

expect class LocalKmsDatabase {
fun getKey(keyId: String): Keys
fun insertKey(keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String)
fun updateKey(keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String)
fun deleteKey(keyId: String)
}

class KeyNotFoundException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE keys (
id TEXT PRIMARY KEY,
private_key TEXT NOT NULL,
public_key TEXT NOT NULL,
algorithm TEXT NOT NULL
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.sphereon.oid.fed.kms.local

import app.cash.sqldelight.db.SqlDriver
import com.sphereon.oid.fed.kms.local.models.Keys
import com.sphereon.oid.fed.persistence.Constants
import com.sphereon.oid.fed.persistence.database.PlatformSqlDriver


actual class LocalKmsDatabase {

init {
val driver = getDriver()

val database = Database(driver)

}

private fun getDriver(): SqlDriver {
return PlatformSqlDriver().createPostgresDriver(
System.getenv(Constants.DATASOURCE_URL),
System.getenv(Constants.DATASOURCE_USER),
System.getenv(Constants.DATASOURCE_PASSWORD)
)
}

actual fun getKey(keyId: String): Keys {
TODO("Not yet implemented")
}

actual fun insertKey(
keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String
) {
TODO("Not yet implemented")
}

actual fun updateKey(
keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String
) {
TODO("Not yet implemented")
}

actual fun deleteKey(keyId: String) {
TODO("Not yet implemented")
}
}
13 changes: 0 additions & 13 deletions modules/local-kms/src/main/kotlin/Key.kt

This file was deleted.

12 changes: 0 additions & 12 deletions modules/local-kms/src/main/kotlin/KeyRepository.kt

This file was deleted.

34 changes: 0 additions & 34 deletions modules/local-kms/src/main/kotlin/LocalKmsDatabaseConnection.kt

This file was deleted.

14 changes: 0 additions & 14 deletions modules/local-kms/src/main/resources/application.properties

This file was deleted.

8 changes: 0 additions & 8 deletions modules/local-kms/src/main/resources/schema.sql

This file was deleted.

0 comments on commit e6d167f

Please sign in to comment.