From 36472a9173311f2edbe49746f5cf4f3faf6f1540 Mon Sep 17 00:00:00 2001
From: Oliver Janka <72382828+oliverjanka@users.noreply.github.com>
Date: Sun, 22 Sep 2024 20:25:27 +0200
Subject: [PATCH] Add velocity forwarding secret env override (#10127)

Previously, the velocity forwarding secret could only be configured via
the configuration option in the global paper configuration.
This makes configuring/passing such a value rather difficult for
containerized/orchestrated servers as these configuration files are
usually part of the server data volume itself and hence cannot be
sourced from a secret.

This commit enables administrators to define the PAPER_VELOCITY_SECRET
environment variable, which will override any potentially configured
velocity secret.
---
 patches/server/Paper-config-files.patch | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/patches/server/Paper-config-files.patch b/patches/server/Paper-config-files.patch
index 71ea2a4733..c82a6ef2df 100644
--- a/patches/server/Paper-config-files.patch
+++ b/patches/server/Paper-config-files.patch
@@ -594,7 +594,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +
 +            @PostProcess
 +            private void postProcess() {
-+                if (this.enabled && this.secret.isEmpty()) {
++                if (!this.enabled) return;
++
++                final String environmentSourcedVelocitySecret = System.getenv("PAPER_VELOCITY_SECRET");
++                if (environmentSourcedVelocitySecret != null && !environmentSourcedVelocitySecret.isEmpty()) {
++                    this.secret = environmentSourcedVelocitySecret;
++                }
++
++                if (this.secret.isEmpty()) {
 +                    LOGGER.error("Velocity is enabled, but no secret key was specified. A secret key is required. Disabling velocity...");
 +                    this.enabled = false;
 +                }