[FEATURE] Configure projectName and address from env

This commit is contained in:
Gravita 2021-05-11 16:46:37 +07:00
parent 30cabd25fd
commit 97faf5ef79
2 changed files with 29 additions and 35 deletions

View file

@ -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);
}
}
}

View file

@ -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 {
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: ");
newConfig.setProjectName(commandHandler.readLine());
projectName = commandHandler.readLine();
}
newConfig.setProjectName(projectName);
}
if (address == null || address.isEmpty()) {
logger.error("Address null. Using localhost");