Skip to content

Commit

Permalink
Rename MONGO_HOSTNAME to MONGO_CONNECTION_STRING, stop prepending "mo…
Browse files Browse the repository at this point in the history
…ngodb://" to the hostname
  • Loading branch information
FluxCapacitor2 committed Mar 6, 2024
1 parent b05b09a commit d1e0cfd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Environment variables:
* `BLUEDRAGON_AGONES_DISABLED` - Disables Agones integration if set to any value.
* `BLUEDRAGON_ENV_TYPE` - Set to "DEV" to enable development mode.
* `BLUEDRAGON_QUEUE_TYPE` - Set to "IPC" to use Puffin or "TEST" for the `TestQueue`. If not present, a default value is inferred.
* `BLUEDRAGON_MONGO_HOSTNAME` - The hostname used to connect to MongoDB.
* `BLUEDRAGON_MONGO_CONNECTION_STRING` - The connection string used to connect to MongoDB.
* `BLUEDRAGON_PUFFIN_HOSTNAME` - The hostname used to connect to Puffin.
* `BLUEDRAGON_LUCKPERMS_HOSTNAME` - The hostname used to connect to LuckPerms.
* `HOSTNAME` - Used to determine the server name. Provided by default in Docker or Kubernetes environments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Environment {
lateinit var current: Environment

val queue get() = current.queue
val mongoHostname get() = current.mongoHostname
val mongoConnectionString get() = current.mongoConnectionString
val dbName get() = current.dbName
val puffinHostname get() = current.puffinHostname
val defaultGameName get() = current.defaultGameName
Expand All @@ -26,7 +26,7 @@ abstract class Environment {
}

abstract val queue: Queue
abstract val mongoHostname: String
abstract val mongoConnectionString: String
abstract val puffinHostname: String
abstract val luckPermsHostname: String
abstract val gameClasses: Collection<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object IntegrationsInit : Bootstrap() {
}
}

Database.initialize(DatabaseConnectionImpl("mongodb://${Environment.mongoHostname}"))
Database.initialize(DatabaseConnectionImpl(Environment.mongoConnectionString))
Permissions.initialize(PermissionManagerImpl())

if (Environment.current.isDev) {
Expand All @@ -48,7 +48,7 @@ object IntegrationsInit : Bootstrap() {
Database.connection.logEvent(
EventLog("game_server_started", Severity.DEBUG)
.withProperty("is_dev", Environment.isDev.toString())
.withProperty("mongo_hostname", Environment.mongoHostname)
.withProperty("mongo_hostname", Environment.mongoConnectionString)
.withProperty("puffin_hostname", Environment.puffinHostname)
.withProperty("luckperms_hostname", Environment.current.luckPermsHostname)
.withProperty("game_classes", Environment.current.gameClasses)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/bluedragonmc/server/queue/environments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConfiguredEnvironment : Environment() {
else -> defaultQueue()
}

override val mongoHostname: String = System.getenv("BLUEDRAGON_MONGO_HOSTNAME") ?: defaultMongoHostname()
override val mongoConnectionString: String = System.getenv("BLUEDRAGON_MONGO_CONNECTION_STRING") ?: defaultMongoConnectionString()
override val puffinHostname: String = System.getenv("BLUEDRAGON_PUFFIN_HOSTNAME") ?: defaultPuffinHostname()
override val luckPermsHostname: String = System.getenv("BLUEDRAGON_LUCKPERMS_HOSTNAME") ?: defaultLuckPermsHostname()

Expand Down Expand Up @@ -63,10 +63,10 @@ private fun defaultQueue(): Queue {
return if (isDev()) TestQueue() else IPCQueue
}

private fun defaultMongoHostname(): String {
private fun defaultMongoConnectionString(): String {
LoggerFactory.getLogger(Environment::class.java)
.warn("No environment variable specified, using default MongoDB connection configuration.")
return if (isDev()) "localhost:27017" else "mongo:27017"
return if (isDev()) "mongodb://localhost:27017" else "mongodb://mongo:27017"
}

private fun defaultPuffinHostname(): String {
Expand Down

0 comments on commit d1e0cfd

Please sign in to comment.