Add archiving service config file

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 7fdbe5113f
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

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

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

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

@ -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")
}
}

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

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

1
etc/.gitignore vendored

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

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