Skip to content

Commit

Permalink
fix(shulker-proxy-agent): having no network admins tries to parse an …
Browse files Browse the repository at this point in the history
…empty string uuid
  • Loading branch information
jeremylvln committed Nov 28, 2023
1 parent 2b82d07 commit 47e26e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ object Configuration {
val PROXY_TTL_SECONDS = getLongEnv("SHULKER_PROXY_TTL_SECONDS")

val NETWORK_ADMINS: List<UUID> = getOptionalStringEnv("SHULKER_NETWORK_ADMINS")
.map { it.split(",").map(UUID::fromString) }
.map {
it.split(",")
.filter(String::isNotBlank)
.map(UUID::fromString)
}
.orElse(emptyList())

val REDIS_HOST = getStringEnv("SHULKER_PROXY_REDIS_HOST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo

fun onProxyInitialization() {
try {
this.logger.fine("Creating Agones SDK from environment")
this.agonesGateway = AgonesSDKImpl.createFromEnvironment()

val gameServer = this.agonesGateway.getGameServer().get()
this.logger.info(
"Identified Shulker proxy: ${gameServer.objectMeta.namespace}/${gameServer.objectMeta.name}"
)

ShulkerProxyAPI.INSTANCE = ShulkerProxyAPIImpl(this)

this.logger.fine("Creating Redis pool")
this.jedisPool = this.createJedisPool()
this.jedisPool.resource.use { jedis -> jedis.ping() }

Expand Down Expand Up @@ -84,7 +87,7 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo
this.cache.registerProxy(Configuration.PROXY_NAME)
this.agonesGateway.setAllocated()
} catch (e: Exception) {
this.logger.severe("Failed to parse configuration")
this.logger.severe("Shulker Agent crashed, stopping proxy")
e.printStackTrace()
this.shutdown()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package io.shulkermc.serveragent

import java.util.Optional
import java.util.UUID

object Configuration {
val NETWORK_ADMINS = (getOptionalStringEnv("SHULKER_NETWORK_ADMINS") ?: "")
.split(",")
.map(UUID::fromString)
val NETWORK_ADMINS: List<UUID> = getOptionalStringEnv("SHULKER_NETWORK_ADMINS")
.map {
it.split(",")
.filter(String::isNotBlank)
.map(UUID::fromString)
}
.orElse(emptyList())

private fun getOptionalStringEnv(name: String): String? = System.getenv(name)
private fun getOptionalStringEnv(name: String): Optional<String> = Optional.ofNullable(System.getenv(name))
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ShulkerServerAgentCommon(val serverInterface: ServerInterface, private val

fun onServerInitialization() {
try {
this.logger.fine("Creating Agones SDK from environment")
this.agonesGateway = AgonesSDKImpl.createFromEnvironment()
val gameServer = this.agonesGateway.getGameServer().get()
this.logger.info(
Expand All @@ -48,7 +49,7 @@ class ShulkerServerAgentCommon(val serverInterface: ServerInterface, private val

this.agonesGateway.setReady()
} catch (e: Exception) {
this.logger.severe("Failed to parse configuration: ${e.message}")
this.logger.severe("Shulker Agent crashed, stopping server")
e.printStackTrace()
this.shutdown()
}
Expand Down

0 comments on commit 47e26e8

Please sign in to comment.