improve account loading

main
Timo Bryant 2024-04-22 22:16:11 +02:00
parent 095acd24e4
commit 5d0847db0d
5 changed files with 42 additions and 12 deletions

View File

@ -1,3 +1,3 @@
[database] [database]
jdbc = "jdbc:postgresql://localhost:5432/postgres" jdbc = "jdbc:postgresql://localhost:5432/postgres"
user = "db-user" user = "static:db-user"

View File

@ -0,0 +1,23 @@
package de.itkl.modConfiguration.extensions
import com.sksamuel.hoplite.ConfigLoaderBuilder
import de.itkl.modConfiguration.decoders.decodeString
import de.itkl.modConfiguration.loaders.loadAccounts
import de.itkl.moduleCore.support.expect
import java.nio.file.Path
inline fun <reified T : Any> ConfigLoaderBuilder.addStringDecoder(crossinline decoder: (value: String) -> T): ConfigLoaderBuilder {
return addDecoder(decodeString(decoder))
}
fun ConfigLoaderBuilder.resolveAccountsFrom(path: Path): ConfigLoaderBuilder {
val accounts = loadAccounts(path)
addStringDecoder { value ->
accounts.account[value].expect {
"The account $value could not be found. " +
"Looked into path $path. " +
"Available accounts: ${accounts.account.map { it.key }.joinToString(",")}"
}
}
TODO()
}

View File

@ -1,5 +0,0 @@
package de.itkl.modConfiguration
import org.koin.dsl.module
val modConfiguration = module {}

View File

@ -1,8 +1,20 @@
package de.itkl.modConfiguration.types package de.itkl.modConfiguration.types
interface Account { data class Account(
val name: String val name: String,
val password: String val login: String,
val password: String,
) {
override fun toString(): String {
return "Account(login='$login')"
}
} }
data class AccountDef(override val name: String, override val password: String) : Account data class AccountDef(
val login: String,
val password: String,
) {
override fun toString(): String {
return "Account(login='$login')"
}
}

View File

@ -1,8 +1,8 @@
[account."test user"] [account."test user"]
name = "Sir Test" login = "Sir Test"
password = "testitest" password = "testitest"
[account."test users wife"] [account."test users wife"]
name = "Madam Test" login = "Madam Test"
password = "testitest" password = "testitest"