13
0
geforkt von Mirrors/Velocity

feat: added VELOCITY_FORWARDING_SECRET environment variable (#582)

Dieser Commit ist enthalten in:
Cubxity 2021-10-03 22:07:45 +02:00 committet von GitHub
Ursprung 340e1b23d6
Commit d619bb56fd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -424,9 +424,10 @@ public class VelocityConfiguration implements ProxyConfig {
CommentedFileConfig defaultConfig = CommentedFileConfig.of(tmpFile, TomlFormat.instance()); CommentedFileConfig defaultConfig = CommentedFileConfig.of(tmpFile, TomlFormat.instance());
defaultConfig.load(); 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; 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()) { if (forwardingSecretString == null || forwardingSecretString.isEmpty()) {
forwardingSecretString = generateRandomString(12); forwardingSecretString = generateRandomString(12);
config.set("forwarding-secret", forwardingSecretString); config.set("forwarding-secret", forwardingSecretString);
@ -434,6 +435,7 @@ public class VelocityConfiguration implements ProxyConfig {
} }
forwardingSecret = forwardingSecretString.getBytes(StandardCharsets.UTF_8); forwardingSecret = forwardingSecretString.getBytes(StandardCharsets.UTF_8);
// Handle any cases where the config needs to be saved again
if (mustResave) { if (mustResave) {
config.save(); config.save();
} }