Generate a new forwarding secret file if the file is deleted (#1671)
* Generate a new forwarding secret file if the file is deleted This allows to generate a new forwarding secret simply by deleting the file if required. The file will only be generated if the forwarding secret is not configured through a system property resolves #1670 * Add file creation message
This commit is contained in:
@@ -515,7 +515,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
|
||||
String forwardingSecretString = System.getenv().getOrDefault(
|
||||
"VELOCITY_FORWARDING_SECRET", "");
|
||||
if (forwardingSecretString.isEmpty()) {
|
||||
if (forwardingSecretString.isBlank()) {
|
||||
final String forwardSecretFile = config.get("forwarding-secret-file");
|
||||
final Path secretPath = forwardSecretFile == null
|
||||
? defaultForwardingSecretPath
|
||||
@@ -528,7 +528,11 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
"The file " + forwardSecretFile + " is not a valid file or it is a directory.");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("The forwarding-secret-file does not exist.");
|
||||
Files.createFile(secretPath);
|
||||
Files.writeString(secretPath, forwardingSecretString = generateRandomString(12),
|
||||
StandardCharsets.UTF_8);
|
||||
logger.info("The forwarding-secret-file does not exist. A new file has been created at {}",
|
||||
forwardSecretFile);
|
||||
}
|
||||
}
|
||||
final byte[] forwardingSecret = forwardingSecretString.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user