Skip to content

Commit 95578a2

Browse files
author
Alex Levinson
committed
adding ENV var config overrides
1 parent a09a0c6 commit 95578a2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This is cumbersome and should have a better way to do this.
2828
## Explore an event pipeline
2929
I'm curious about how much "big data" we could collect in the game - trade transactions, attacks, kills, etc. Considering what to do on this front.
3030

31-
## Move some configurations to ENV vars in the bot
31+
## [DONE] Move some configurations to ENV vars in the bot
3232
Right now, the bot uses `settings.ini` with a hardcoded username and password. We should be able to pass ENV vars instead making this cleaner.
3333

3434
## clean up CommandHandler code

firescape-bot/src/org/rscdaemon/bot/util/Config.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.FileInputStream;
44
import java.io.IOException;
5+
import java.util.Map;
56
import java.util.Properties;
67

78
public class Config {
@@ -16,11 +17,15 @@ public static void initConfig(String file) throws IOException {
1617
Properties props = new Properties();
1718
props.load(new FileInputStream(file));
1819

19-
SERVER_IP = props.getProperty("server");
20-
SERVER_PORT = Integer.parseInt(props.getProperty("port"));
21-
CONF_DIR = props.getProperty("config_dir");
22-
USERNAME = props.getProperty("username");
23-
PASSWORD = props.getProperty("password");
20+
Map<String, String> env = System.getenv();
21+
22+
// override config file if ENV variables are set
23+
USERNAME = env.containsKey("FIRE_USER") ? env.get("FIRE_USER") : props.getProperty("username");
24+
PASSWORD = env.containsKey("FIRE_PASS") ? env.get("FIRE_PASS") : props.getProperty("password");
25+
SERVER_IP = env.containsKey("FIRE_SERVER") ? env.get("FIRE_SERVER") : props.getProperty("server");
26+
SERVER_PORT = env.containsKey("FIRE_PORT") ? Integer.parseInt(env.get("FIRE_PORT"))
27+
: Integer.parseInt(props.getProperty("port"));
28+
CONF_DIR = env.containsKey("FIRE_CONF_DIR") ? env.get("FIRE_CONF_DIR") : props.getProperty("config_dir");
2429

2530
props.clear();
2631
}

0 commit comments

Comments
 (0)