From 97faf5ef799409f665f77184606194d3d8c68a59 Mon Sep 17 00:00:00 2001 From: Gravita Date: Tue, 11 May 2021 16:46:37 +0700 Subject: [PATCH] [FEATURE] Configure projectName and address from env --- .../pro/gravit/launchserver/LaunchServer.java | 18 +++++--- .../launchserver/LaunchServerStarter.java | 46 +++++++------------ 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index e3e2d9af..2a75a633 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -531,14 +531,20 @@ public static class LaunchServerDirectories { public Path tmpDir; public void collect() { - if (updatesDir == null) updatesDir = dir.resolve(UPDATES_NAME); - if (profilesDir == null) profilesDir = dir.resolve(PROFILES_NAME); - if (trustStore == null) trustStore = dir.resolve(TRUSTSTORE_NAME); - if (launcherLibrariesDir == null) launcherLibrariesDir = dir.resolve(LAUNCHERLIBRARIES_NAME); + if (updatesDir == null) updatesDir = getPath(UPDATES_NAME); + if (profilesDir == null) profilesDir = getPath(PROFILES_NAME); + if (trustStore == null) trustStore = getPath(TRUSTSTORE_NAME); + if (launcherLibrariesDir == null) launcherLibrariesDir = getPath(LAUNCHERLIBRARIES_NAME); if (launcherLibrariesCompileDir == null) - launcherLibrariesCompileDir = dir.resolve(LAUNCHERLIBRARIESCOMPILE_NAME); - if(keyDirectory == null) keyDirectory = dir.resolve(KEY_NAME); + launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME); + if(keyDirectory == null) keyDirectory = getPath(KEY_NAME); if(tmpDir ==null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(String.format("launchserver-%s", SecurityHelper.randomStringToken())); } + + private Path getPath(String dirName) { + String property = System.getProperty("launchserver.dir."+dirName, null); + if(property == null) return dir.resolve(dirName); + else return Paths.get(property); + } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index c1b185a7..4e73457d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -46,7 +46,6 @@ public class LaunchServerStarter { public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); - public static final boolean inDocker = Boolean.getBoolean("launchserver.dockered"); public static final boolean prepareMode = Boolean.getBoolean("launchserver.prepareMode"); private static final Logger logger = LogManager.getLogger(); @@ -62,10 +61,6 @@ public static void main(String[] args) throws Exception { } Path dir = IOHelper.WORKING_DIR; Path configFile, runtimeConfigFile; - Path publicKeyFile = dir.resolve("public.key"); - Path privateKeyFile = dir.resolve("private.key"); - ECPublicKey publicKey; - ECPrivateKey privateKey; try { Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Security.addProvider(new BouncyCastleProvider()); @@ -122,21 +117,6 @@ public static void main(String[] args) throws Exception { localCommandHandler = new StdCommandHandler(true); logger.warn("JLine2 isn't in classpath, using std"); } - if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) { - logger.info("Reading EC keypair"); - publicKey = SecurityHelper.toPublicECDSAKey(IOHelper.read(publicKeyFile)); - privateKey = SecurityHelper.toPrivateECDSAKey(IOHelper.read(privateKeyFile)); - } else { - logger.info("Generating EC keypair"); - KeyPair pair = SecurityHelper.genECDSAKeyPair(new SecureRandom()); - publicKey = (ECPublicKey) pair.getPublic(); - privateKey = (ECPrivateKey) pair.getPrivate(); - - // Write key pair list - logger.info("Writing EC keypair list"); - IOHelper.write(publicKeyFile, publicKey.getEncoded()); - IOHelper.write(privateKeyFile, privateKey.getEncoded()); - } modulesManager.invokeEvent(new PreConfigPhase()); generateConfigIfNotExists(configFile, localCommandHandler, env); logger.info("Reading LaunchServer config file"); @@ -197,11 +177,6 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept }; LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); directories.dir = dir; - if (inDocker) { - Path parentLibraries = StarterAgent.libraries.toAbsolutePath().normalize().getParent(); - directories.launcherLibrariesCompileDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIESCOMPILE_NAME); - directories.launcherLibrariesDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIES_NAME); - } LaunchServer server = new LaunchServerBuilder() .setDirectories(directories) .setEnv(env) @@ -255,10 +230,23 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com address = "localhost"; newConfig.setProjectName("test"); } else { - System.out.println("LaunchServer address(default: localhost): "); - address = commandHandler.readLine(); - System.out.println("LaunchServer projectName: "); - newConfig.setProjectName(commandHandler.readLine()); + address = System.getenv("ADDRESS"); + if(address == null) { + address = System.getProperty("launchserver.address", null); + } + if(address == null) { + System.out.println("LaunchServer address(default: localhost): "); + address = commandHandler.readLine(); + } + String projectName = System.getenv("PROJECTNAME"); + if(projectName == null) { + projectName = System.getProperty("launchserver.projectname", null); + } + if(projectName == null) { + System.out.println("LaunchServer projectName: "); + projectName = commandHandler.readLine(); + } + newConfig.setProjectName(projectName); } if (address == null || address.isEmpty()) { logger.error("Address null. Using localhost");