Browse Source

Add archiving service config file

Signed-off-by: Graham <gpe@openrs2.org>
pull/132/head
Graham 1 year ago
parent
commit
d0df60cc1c
  1. 4
      all/build.gradle.kts
  2. 1
      archive/build.gradle.kts
  3. 3
      archive/src/main/kotlin/org/openrs2/archive/ArchiveConfig.kt
  4. 27
      archive/src/main/kotlin/org/openrs2/archive/ArchiveConfigProvider.kt
  5. 6
      archive/src/main/kotlin/org/openrs2/archive/ArchiveModule.kt
  6. 8
      archive/src/main/kotlin/org/openrs2/archive/DataSourceProvider.kt
  7. 1
      etc/.gitignore
  8. 2
      etc/archive.example.yaml

4
all/build.gradle.kts

@ -79,6 +79,10 @@ distributions { @@ -79,6 +79,10 @@ distributions {
from("$rootDir/DCO")
from("$rootDir/LICENSE")
from("$rootDir/README.md")
from("$rootDir/etc/archive.example.yaml") {
rename { "archive.yaml" }
into("etc")
}
from("$rootDir/etc/config.example.yaml") {
rename { "config.yaml" }
into("etc")

1
archive/build.gradle.kts

@ -21,6 +21,7 @@ dependencies { @@ -21,6 +21,7 @@ dependencies {
implementation(project(":net"))
implementation(project(":protocol"))
implementation(project(":util"))
implementation(project(":yaml"))
implementation("com.google.guava:guava:${Versions.guava}")
implementation("com.zaxxer:HikariCP:${Versions.hikaricp}")
implementation("io.ktor:ktor-jackson:${Versions.ktor}")

3
archive/src/main/kotlin/org/openrs2/archive/ArchiveConfig.kt

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
package org.openrs2.archive
public data class ArchiveConfig(val databaseUrl: String)

27
archive/src/main/kotlin/org/openrs2/archive/ArchiveConfigProvider.kt

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
package org.openrs2.archive
import com.fasterxml.jackson.databind.ObjectMapper
import org.openrs2.yaml.Yaml
import java.nio.file.Files
import java.nio.file.Path
import javax.inject.Inject
import javax.inject.Provider
public class ArchiveConfigProvider @Inject constructor(
@Yaml private val mapper: ObjectMapper
) : Provider<ArchiveConfig> {
override fun get(): ArchiveConfig {
if (Files.notExists(CONFIG_PATH)) {
Files.copy(EXAMPLE_CONFIG_PATH, CONFIG_PATH)
}
return Files.newBufferedReader(CONFIG_PATH).use { reader ->
mapper.readValue(reader, ArchiveConfig::class.java)
}
}
private companion object {
private val CONFIG_PATH = Path.of("etc/archive.yaml")
private val EXAMPLE_CONFIG_PATH = Path.of("etc/archive.example.yaml")
}
}

6
archive/src/main/kotlin/org/openrs2/archive/ArchiveModule.kt

@ -15,6 +15,7 @@ import org.openrs2.db.Database @@ -15,6 +15,7 @@ import org.openrs2.db.Database
import org.openrs2.http.HttpModule
import org.openrs2.json.JsonModule
import org.openrs2.net.NetworkModule
import org.openrs2.yaml.YamlModule
import javax.sql.DataSource
public object ArchiveModule : AbstractModule() {
@ -24,6 +25,11 @@ public object ArchiveModule : AbstractModule() { @@ -24,6 +25,11 @@ public object ArchiveModule : AbstractModule() {
install(HttpModule)
install(JsonModule)
install(NetworkModule)
install(YamlModule)
bind(ArchiveConfig::class.java)
.toProvider(ArchiveConfigProvider::class.java)
.`in`(Scopes.SINGLETON)
bind(DataSource::class.java)
.toProvider(DataSourceProvider::class.java)

8
archive/src/main/kotlin/org/openrs2/archive/DataSourceProvider.kt

@ -4,14 +4,16 @@ import com.zaxxer.hikari.HikariConfig @@ -4,14 +4,16 @@ import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.flywaydb.core.Flyway
import org.postgresql.ds.PGSimpleDataSource
import javax.inject.Inject
import javax.inject.Provider
import javax.sql.DataSource
public class DataSourceProvider : Provider<DataSource> {
public class DataSourceProvider @Inject constructor(
private val config: ArchiveConfig
) : Provider<DataSource> {
override fun get(): DataSource {
val dataSource = PGSimpleDataSource()
// TODO(gpe): make the URL configurable
dataSource.setUrl("jdbc:postgresql://localhost/runearchive?user=gpe&password=gpe")
dataSource.setUrl(config.databaseUrl)
Flyway.configure()
.dataSource(dataSource)

1
etc/.gitignore vendored

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
/archive.yaml
/config.yaml
/game.key
/loader.p12

2
etc/archive.example.yaml

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
---
database_url: jdbc:postgresql://localhost/openrs2_archive?user=openrs2&password=openrs2
Loading…
Cancel
Save