Velocity icon indicating copy to clipboard operation
Velocity copied to clipboard

don't error out when forwarding-file doesn't exist and is not needed

Open derklaro opened this issue 3 years ago • 4 comments

#743 optimized the way the forwarding secret file is read. While the change is fine, it also introduced a small annoyance I stumbled upon. When the configured and default forwarding file are missing (for whatever reason) the proxy won't start and throw an exception even when using legacy or no forwarding where no forwarding secret is needed.

There is a check a bit further down which validates that the forwarding secret is present when using bungeeguard or modern forwarding, I just extended the error message by appending a hint about the missing file there.

derklaro avatar Jul 16 '22 21:07 derklaro

The VelocityConfiguration#read method needs a rework. Imo, if the secret file doesn't exist, a default one should be created even when the velocity.toml file exists (i.e. I would remove the first condition in this line and move the create call further down when we know that the file is indeed needed -- e.g. when the VELOCITY_FORWARDING_SECRET env var is unset).

Unrelated, but I don't understand the purpose of these lines. The defaultConfig variable looks unused after loading :confused:

hugmanrique avatar Jul 17 '22 01:07 hugmanrique

After looking again it seems like the forwarding-secret presence check is there two times: during reading and during validation. Question is if we just create the file if it is missing without content and remove the check during reading 🤔

derklaro avatar Jul 18 '22 13:07 derklaro

That's what I meant, i.e. remove these lines (425-429) and add an else branch here that looks

forwardingSecretString = generateRandomString(12);
Files.writeString(secretPath, forwardingSecretString);

This preserves the behavior prior to #712.

hugmanrique avatar Jul 18 '22 16:07 hugmanrique

Yea that, and I'm talking about this check and this check

derklaro avatar Jul 18 '22 17:07 derklaro