Compare commits
No commits in common. "18" and "main" have entirely different histories.
|
|
@ -29,7 +29,6 @@ private val Log = KotlinLogging.logger { }
|
|||
class XsClient : KoinComponent {
|
||||
private val httpClient by inject<HttpClient>()
|
||||
|
||||
|
||||
suspend fun waitFor(task: XsTask): WaitForResponse {
|
||||
Log.info { "Wait for competition: $task" }
|
||||
val response = httpClient.get {
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
plugins {
|
||||
kotlin("plugin.serialization") version embeddedKotlinVersion
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.akuleshov7:ktoml-core:0.5.1")
|
||||
implementation("com.akuleshov7:ktoml-file:0.5.1")
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package de.itkl.xtractionstudio
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
data class XsEnvironment(
|
||||
val http: Http,
|
||||
val data: Data,
|
||||
val build: Build,
|
||||
@SerialName("xs")
|
||||
val xs: XS,
|
||||
val env: Map<String, Environment>,
|
||||
val credentials: Map<String, Credentials>
|
||||
) {
|
||||
|
||||
|
||||
@Serializable
|
||||
data class Build(
|
||||
val worker: String
|
||||
)
|
||||
|
||||
|
||||
@Serializable
|
||||
data class Http(
|
||||
val proxy: String,
|
||||
@SerialName("request-timeout")
|
||||
val requestTimeout: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Data(
|
||||
@SerialName("corpus-dir")
|
||||
val corpusDir: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class XS(
|
||||
@SerialName("concurrency_limit")
|
||||
val concurrencyLimit: Int
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Environment(
|
||||
@SerialName("user")
|
||||
val user: String,
|
||||
@SerialName("backend-url")
|
||||
val backendUrl: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Credentials(
|
||||
val login: String,
|
||||
val password: String
|
||||
)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class XsEnvironmentInternal(
|
||||
val http: XsEnvironment.Http,
|
||||
val data: XsEnvironment.Data,
|
||||
val build: XsEnvironment.Build,
|
||||
@SerialName("xs")
|
||||
val xs: XsEnvironment.XS,
|
||||
val env: Map<String, Map<String, String>>,
|
||||
val credentials: Map<String, Map<String, String>>
|
||||
) {
|
||||
|
||||
val environmentNames get() = env.keys
|
||||
fun environment(name: String): XsEnvironment.Environment? {
|
||||
return env[name]?.let {
|
||||
val json = Json.encodeToString(it)
|
||||
Json.decodeFromString(json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package de.itkl.xtractionstudio
|
||||
|
||||
import com.akuleshov7.ktoml.file.TomlFileReader
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.nio.file.Path
|
||||
|
||||
class XsEnvironmentTomlProvider(private val path: Path) {
|
||||
fun environment(): XsEnvironment {
|
||||
val result = TomlFileReader.decodeFromFile(XsEnvironmentInternal.serializer(), path.toAbsolutePath().toString())
|
||||
return XsEnvironment(
|
||||
http = result.http,
|
||||
data = result.data,
|
||||
build = result.build,
|
||||
xs = result.xs,
|
||||
env = result.env.mapValues { (_, value) ->
|
||||
mapToObject(XsEnvironment.Environment.serializer(), value)
|
||||
},
|
||||
credentials = result.credentials.mapValues { (_, value) ->
|
||||
mapToObject(XsEnvironment.Credentials.serializer(), value)
|
||||
}
|
||||
)
|
||||
}
|
||||
private fun <T: Any> mapToObject(deserializationStrategy: DeserializationStrategy<T>, map: Map<String, String>): T {
|
||||
val json = Json.encodeToString(map)
|
||||
return Json.decodeFromString(deserializationStrategy, json)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package de.itkl.xtractionstudio
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.nio.file.Paths
|
||||
|
||||
class XsEnvironmentTomlProviderTest {
|
||||
@Test
|
||||
fun `can parse the toml`() {
|
||||
val tomlPath = Paths.get("../../assets/environments.toml")
|
||||
val environment = XsEnvironmentTomlProvider(tomlPath).environment()
|
||||
println(environment)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue