From 5b3e9469f0c22abb5688ead8bcac03c65db9c9e3 Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Thu, 29 Aug 2024 16:25:01 +0530 Subject: [PATCH] feat: changed dependencies --- modules/local-kms/build.gradle.kts | 6 +++-- .../sphereon/oid/fed/kms/local/Constants.kt | 10 ++++++++ .../local/{ => database}/LocalKmsDatabase.kt | 4 ++-- .../kms/local/database/PlatformSqlDriver.kt | 8 +++++++ .../{ => database}/LocalKmsDatabase.jvm.kt | 6 ++--- .../kms/local/database/PlatformSqlDriver.kt | 23 +++++++++++++++++++ modules/services/build.gradle.kts | 1 + .../sphereon/oid/fed/services/KmsService.kt | 12 ++++------ .../oid/fed/services}/LocalKmsClient.kt | 10 ++++---- 9 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/Constants.kt rename modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/{ => database}/LocalKmsDatabase.kt (77%) create mode 100644 modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt rename modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/{ => database}/LocalKmsDatabase.jvm.kt (86%) create mode 100644 modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt rename modules/{local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local => services/src/commonMain/kotlin/com/sphereon/oid/fed/services}/LocalKmsClient.kt (55%) diff --git a/modules/local-kms/build.gradle.kts b/modules/local-kms/build.gradle.kts index 39d3c9f0..a86c522b 100644 --- a/modules/local-kms/build.gradle.kts +++ b/modules/local-kms/build.gradle.kts @@ -34,13 +34,15 @@ kotlin { sourceSets { commonMain { dependencies { - implementation(projects.modules.services) + api(projects.modules.openapi) } } jvmMain { dependencies { - implementation("app.cash.sqldelight:sqlite-driver:2.0.2") + implementation("app.cash.sqldelight:jdbc-driver:2.0.2") + implementation("com.zaxxer:HikariCP:5.1.0") + implementation("org.postgresql:postgresql:42.7.3") } } } diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/Constants.kt b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/Constants.kt new file mode 100644 index 00000000..421da153 --- /dev/null +++ b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/Constants.kt @@ -0,0 +1,10 @@ +package com.sphereon.oid.fed.kms.local + +class Constants { + companion object { + const val DATASOURCE_URL = "DATASOURCE_URL" + const val DATASOURCE_USER = "DATASOURCE_USER" + const val DATASOURCE_PASSWORD = "DATASOURCE_PASSWORD" + const val SQLITE_IS_NOT_SUPPORTED_IN_JVM = "SQLite is not supported in JVM" + } +} diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.kt b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.kt similarity index 77% rename from modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.kt rename to modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.kt index 98cc7901..6b660d7a 100644 --- a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.kt +++ b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.kt @@ -1,8 +1,8 @@ -package com.sphereon.oid.fed.kms.local +package com.sphereon.oid.fed.kms.local.database import com.sphereon.oid.fed.kms.local.models.Keys -expect class LocalKmsDatabase { +expect class LocalKmsDatabase() { fun getKey(keyId: String): Keys fun insertKey(keyId: String, privateKey: ByteArray, publicKey: ByteArray, algorithm: String) fun deleteKey(keyId: String) diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt new file mode 100644 index 00000000..fefec3c7 --- /dev/null +++ b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt @@ -0,0 +1,8 @@ +package com.sphereon.oid.fed.kms.local.database + +import app.cash.sqldelight.db.SqlDriver + +expect class PlatformSqlDriver { + fun createPostgresDriver(url: String, username: String, password: String): SqlDriver + fun createSqliteDriver(path: String): SqlDriver +} \ No newline at end of file diff --git a/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.jvm.kt b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.jvm.kt similarity index 86% rename from modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.jvm.kt rename to modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.jvm.kt index 261b7a5a..3b834f4e 100644 --- a/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsDatabase.jvm.kt +++ b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/LocalKmsDatabase.jvm.kt @@ -1,9 +1,9 @@ -package com.sphereon.oid.fed.kms.local +package com.sphereon.oid.fed.kms.local.database import app.cash.sqldelight.db.SqlDriver +import com.sphereon.oid.fed.kms.local.Constants +import com.sphereon.oid.fed.kms.local.Database 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 { diff --git a/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt new file mode 100644 index 00000000..6a76e099 --- /dev/null +++ b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/database/PlatformSqlDriver.kt @@ -0,0 +1,23 @@ +package com.sphereon.oid.fed.kms.local.database + +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.driver.jdbc.asJdbcDriver +import com.sphereon.oid.fed.kms.local.Constants +import com.zaxxer.hikari.HikariConfig +import com.zaxxer.hikari.HikariDataSource + +actual class PlatformSqlDriver { + actual fun createPostgresDriver(url: String, username: String, password: String): SqlDriver { + val config = HikariConfig() + config.jdbcUrl = url + config.username = username + config.password = password + + val dataSource = HikariDataSource(config) + return dataSource.asJdbcDriver() + } + + actual fun createSqliteDriver(path: String): SqlDriver { + throw UnsupportedOperationException(Constants.SQLITE_IS_NOT_SUPPORTED_IN_JVM) + } +} \ No newline at end of file diff --git a/modules/services/build.gradle.kts b/modules/services/build.gradle.kts index aa45dd97..56eeb580 100644 --- a/modules/services/build.gradle.kts +++ b/modules/services/build.gradle.kts @@ -21,6 +21,7 @@ kotlin { api(projects.modules.openapi) api(projects.modules.persistence) api(projects.modules.openidFederationCommon) + api(projects.modules.localKms) implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.11") } } diff --git a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/KmsService.kt b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/KmsService.kt index 8dc53cda..b8fae3ac 100644 --- a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/KmsService.kt +++ b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/KmsService.kt @@ -1,15 +1,13 @@ package com.sphereon.oid.fed.services -import com.sphereon.oid.fed.persistence.models.Jwk +import com.sphereon.oid.fed.openapi.models.Jwk + class KmsService(private val provider: String) { - private val kmsClient: KmsClient by lazy { - when (provider) { - //"local" -> LocalKmsClient() - //"aws" -> AwsKmsClient() - else -> throw IllegalArgumentException("Unsupported KMS provider: $provider") - } + private val kmsClient: KmsClient = when (provider) { + "local" -> LocalKmsClient() + else -> throw IllegalArgumentException("Unsupported KMS provider: $provider") } fun generateKeyPair(keyId: String): Jwk { diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsClient.kt b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt similarity index 55% rename from modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsClient.kt rename to modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt index 52702ff1..610557fa 100644 --- a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKmsClient.kt +++ b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt @@ -1,9 +1,11 @@ -package com.sphereon.oid.fed.kms.local +package com.sphereon.oid.fed.services -import com.sphereon.oid.fed.persistence.models.Jwk -import com.sphereon.oid.fed.services.KmsClient +import com.sphereon.oid.fed.kms.local.database.LocalKmsDatabase +import com.sphereon.oid.fed.openapi.models.Jwk -class LocalKmsClient(private val database: LocalKmsDatabase) : KmsClient { +class LocalKmsClient : KmsClient { + + private val database: LocalKmsDatabase = LocalKmsDatabase() override fun generateKeyPair(keyId: String): Jwk { TODO("Not yet implemented")