From d619bb56fd913bedd80d3d42af88ad1332eeda1c Mon Sep 17 00:00:00 2001 From: Cubxity <27609129+Cubxity@users.noreply.github.com> Date: Sun, 3 Oct 2021 22:07:45 +0200 Subject: [PATCH] feat: added VELOCITY_FORWARDING_SECRET environment variable (#582) --- .../velocitypowered/proxy/config/VelocityConfiguration.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 29dd341bb..e43d8a5af 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -424,9 +424,10 @@ public class VelocityConfiguration implements ProxyConfig { CommentedFileConfig defaultConfig = CommentedFileConfig.of(tmpFile, TomlFormat.instance()); defaultConfig.load(); - // Handle any cases where the config needs to be saved again + // Retrieve the forwarding secret. First, from environment variable, then from config. byte[] forwardingSecret; - String forwardingSecretString = config.get("forwarding-secret"); + String forwardingSecretString = System.getenv() + .getOrDefault("VELOCITY_FORWARDING_SECRET", config.get("forwarding-secret")); if (forwardingSecretString == null || forwardingSecretString.isEmpty()) { forwardingSecretString = generateRandomString(12); config.set("forwarding-secret", forwardingSecretString); @@ -434,6 +435,7 @@ public class VelocityConfiguration implements ProxyConfig { } forwardingSecret = forwardingSecretString.getBytes(StandardCharsets.UTF_8); + // Handle any cases where the config needs to be saved again if (mustResave) { config.save(); }