From 119173f2d209c0f8d21e2038b828222fca0316d9 Mon Sep 17 00:00:00 2001 From: MarkBryanMilligan Date: Fri, 25 Feb 2022 22:15:54 -0600 Subject: [PATCH] Move the config creation files to their own shaded jar so they can be run from the command line without an IDE or messy classpath specification. --- README.md | 2 +- .../lantern-config-currentmonitor/pom.xml | 105 ++++++++++++++++++ .../currentmonitor/CreateAuthKey.java | 0 .../currentmonitor/CreateMongoConfig.java | 14 +++ .../currentmonitor/CreateMongoConfig.java | 10 -- currentmonitor/pom.xml | 1 + .../lanternsoftware/util/ResourceLoader.java | 4 + .../util/external/LanternFiles.java | 2 +- 8 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 currentmonitor/lantern-config-currentmonitor/pom.xml rename currentmonitor/{lantern-service-currentmonitor/src/test => lantern-config-currentmonitor/src/main}/java/com/lanternsoftware/currentmonitor/CreateAuthKey.java (100%) create mode 100644 currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java delete mode 100644 currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java diff --git a/README.md b/README.md index 98e68e4..77da761 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ After your reactor build, the compiled war will be at LanternPowerMonitor/curren That can be deployed to tomcat. The 'host' parameter in the raspberry pi config.json file needs to point to wherever you deploy the service so your hubs post the data to your server instead of the official lantern software one.
I'd recommend a valid dns entry and an ssl certificate, but, it's up to you, you're already knee deep in "I'll do what I want" territory here.

Before you deploy it, you need to generate a config file that contains the mongodb credentials.
-There is a file at lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java that can do this for you.
+There is a file at lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java that can do this for you.
Place the generated config file in /opt/tomcat (which is where I have tomcat installed). If you want it to be read from somewhere else, you can modify the paths in LanternFiles.java

The last thing you need is a private aes key to encrypt user auth tokens. One of those can be generated with CreateAuthKey.java.
I realize these instructions aren't complete, but if you're going down this path, I suspect you sort of already know what you're doing, so hopefully that's enough to point you in the right direction. diff --git a/currentmonitor/lantern-config-currentmonitor/pom.xml b/currentmonitor/lantern-config-currentmonitor/pom.xml new file mode 100644 index 0000000..66d3f95 --- /dev/null +++ b/currentmonitor/lantern-config-currentmonitor/pom.xml @@ -0,0 +1,105 @@ + + 4.0.0 + com.lanternsoftware.currentmonitor + lantern-config-currentmonitor + jar + 1.0.0 + lantern-config-currentmonitor + + + 1.8 + 1.8 + + + + + org.slf4j + slf4j-api + 1.7.29 + + + ch.qos.logback + logback-classic + 1.2.3 + + + com.lanternsoftware.util + lantern-util-dao-mongo + 1.0.0 + + + com.lanternsoftware.util + lantern-util-common + 1.0.0 + + + + + + src/main/resources + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + + + testCompile + + compile + + + + true + true + UTF-8 + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + false + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + package + + shade + + + lantern-config-currentmonitor + + + + + com.lanternsoftware.currentmonitor.CreateMongoConfig + Lantern Power Monitor + ${project.version} + Lantern Software, Inc. + + + + + + + + + + diff --git a/currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateAuthKey.java b/currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateAuthKey.java similarity index 100% rename from currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateAuthKey.java rename to currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateAuthKey.java diff --git a/currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java b/currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java new file mode 100644 index 0000000..2ae93f3 --- /dev/null +++ b/currentmonitor/lantern-config-currentmonitor/src/main/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java @@ -0,0 +1,14 @@ +package com.lanternsoftware.currentmonitor; + +import com.lanternsoftware.util.CollectionUtils; +import com.lanternsoftware.util.dao.mongo.MongoConfig; +import com.lanternsoftware.util.external.LanternFiles; + +public class CreateMongoConfig { + public static void main(String[] args) { + if (CollectionUtils.size(args) == 3) + new MongoConfig(args[0], args[1], args[2], "CURRENT_MONITOR").saveToDisk(LanternFiles.CONFIG_PATH + "mongo.cfg"); + else + new MongoConfig("lanternsoftware.com", "*redacted*", "*redacted*", "CURRENT_MONITOR").saveToDisk(LanternFiles.CONFIG_PATH + "mongo.cfg"); + } +} diff --git a/currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java b/currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java deleted file mode 100644 index 1b1b235..0000000 --- a/currentmonitor/lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.lanternsoftware.currentmonitor; - -import com.lanternsoftware.util.external.LanternFiles; -import com.lanternsoftware.util.dao.mongo.MongoConfig; - -public class CreateMongoConfig { - public static void main(String[] args) { - new MongoConfig("lanternsoftware.com", "*redacted*", "*redacted*", "CURRENT_MONITOR").saveToDisk(LanternFiles.CONFIG_PATH + "mongo.cfg"); - } -} diff --git a/currentmonitor/pom.xml b/currentmonitor/pom.xml index db89212..bfc8e1f 100644 --- a/currentmonitor/pom.xml +++ b/currentmonitor/pom.xml @@ -12,6 +12,7 @@ + lantern-config-currentmonitor lantern-currentmonitor lantern-dataaccess-currentmonitor lantern-datamodel-currentmonitor diff --git a/util/lantern-util-common/src/main/java/com/lanternsoftware/util/ResourceLoader.java b/util/lantern-util-common/src/main/java/com/lanternsoftware/util/ResourceLoader.java index ae89a4c..2bc358b 100644 --- a/util/lantern-util-common/src/main/java/com/lanternsoftware/util/ResourceLoader.java +++ b/util/lantern-util-common/src/main/java/com/lanternsoftware/util/ResourceLoader.java @@ -116,6 +116,10 @@ public abstract class ResourceLoader { public static void writeFile(String _sFile, byte[] _btData) { FileOutputStream os = null; try { + if (File.separator.equals("/")) + _sFile = _sFile.replace("\\", File.separator); + else + _sFile = _sFile.replace("/", File.separator); int idx = _sFile.lastIndexOf(File.separator); new File((idx > 0)?_sFile.substring(0, idx):_sFile).mkdirs(); os = new FileOutputStream(_sFile, false); diff --git a/util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java b/util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java index 27efa87..f95af4d 100644 --- a/util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java +++ b/util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java @@ -7,6 +7,6 @@ public abstract class LanternFiles { public static boolean runOpsTasks; static { - ProdConsoleFiles.init(); + ProdFiles.init(); } }