Skip to content

Commit

Permalink
feat: changed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 29, 2024
1 parent 8d4b9fa commit 5b3e946
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 18 deletions.
6 changes: 4 additions & 2 deletions modules/local-kms/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions modules/services/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 5b3e946

Please sign in to comment.