mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-06-27 19:48:09 +03:00
[FEATURE] Support env configuration in ServerWrapper
This commit is contained in:
parent
a67fbac8bc
commit
d4b69195b3
1 changed files with 34 additions and 0 deletions
|
@ -32,6 +32,7 @@
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
||||
|
@ -121,6 +122,7 @@ public void run(String... args) throws Throwable {
|
|||
}
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
loadConfig();
|
||||
config.applyEnv();
|
||||
updateLauncherConfig();
|
||||
Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
|
||||
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
|
||||
|
@ -304,5 +306,37 @@ public void apply() {
|
|||
ConfigService.checkServerConfig.needProperties = checkServerNeedProperties;
|
||||
}
|
||||
}
|
||||
|
||||
public void applyEnv() {
|
||||
this.authId = applyEnvOrDefault("LAUNCHSERVER_AUTH_ID", this.authId);
|
||||
this.address = applyEnvOrDefault("LAUNCHSERVER_ADDRESS", this.address);
|
||||
this.encodedServerEcPublicKey = applyEnvOrDefault("LAUNCHSERVER_EC_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||
this.encodedServerRsaPublicKey = applyEnvOrDefault("LAUNCHSERVER_RSA_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||
{
|
||||
String token = System.getenv("CHECK_SERVER_TOKEN");
|
||||
if(token != null) {
|
||||
if(extendedTokens == null) {
|
||||
extendedTokens = new HashMap<>();
|
||||
}
|
||||
extendedTokens.put("checkServer", new Request.ExtendedToken(token, 0L));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String applyEnvOrDefault(String envName, String def) {
|
||||
String value = System.getenv(envName);
|
||||
if(value == null) {
|
||||
return def;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static<T> T applyEnvOrDefault(String envName, Function<String, T> mappingFunction, T def) {
|
||||
String value = System.getenv(envName);
|
||||
if(value == null) {
|
||||
return def;
|
||||
}
|
||||
return mappingFunction.apply(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue