new feature to load sasl password from file

This commit is contained in:
Chris Naude 2024-05-12 14:32:20 -07:00
parent 3d13fe57c3
commit 189092f27e
4 changed files with 48 additions and 4 deletions

14
pom.xml
View File

@ -6,7 +6,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Bukkit API Version, change if out dated -->
<bukkit.version>1.20-R0.1-SNAPSHOT</bukkit.version>
<bukkit.version>1.20.6-R0.1-SNAPSHOT</bukkit.version>
<build.number>SNAPSHOT</build.number>
</properties>
@ -24,7 +24,6 @@
</pluginRepository>
</pluginRepositories>
<repositories>
<!-- For anything else without its own repo -->
<repository>
@ -74,6 +73,17 @@
<url>https://repo.mikeprimm.com/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.sk89q.com/repo/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>

View File

@ -39,6 +39,7 @@ import static com.cnaude.purpleirc.IRCMessage.Type.CTCP;
import static com.cnaude.purpleirc.IRCMessage.Type.MESSAGE;
import static com.cnaude.purpleirc.IRCMessage.Type.NOTICE;
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
import com.cnaude.purpleirc.Utilities.FileHelpers;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSortedSet;
import com.massivecraft.factions.entity.Faction;
@ -132,6 +133,7 @@ public final class PurpleBot {
public String botIdentPassword;
public String saslUsername;
public String saslPassword;
public String saslPasswordFile;
public List<String> rawMessages;
public String channelCmdNotifyMode;
public String partInvalidChannelsMsg;
@ -818,7 +820,14 @@ public final class PurpleBot {
botServerPass = config.getString("password", "");
botIdentPassword = config.getString("ident-password", "");
saslUsername = config.getString("sasl-username", "");
saslPasswordFile = config.getString("sasl-password-file", "");
if (!saslPasswordFile.isEmpty()) {
plugin.logInfo("Loading sasl password from file: " + saslPasswordFile);
saslPassword = FileHelpers.loadFirstLineFromFile(saslPasswordFile);
} else {
saslPassword = config.getString("sasl-password", "");
}
// plugin.logDebug("saslPassword: " + saslPassword);
commandPrefix = config.getString("command-prefix", ".");
chatDelay = config.getLong("message-delay", 1000);
finger = config.getString("finger-reply", "PurpleIRC");

View File

@ -0,0 +1,23 @@
package com.cnaude.purpleirc.Utilities;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class FileHelpers {
public static String loadFirstLineFromFile(String filePath) throws IOException {
File file = new File(filePath);
if (!file.exists() || !file.canRead()) {
throw new IOException("File does not exist or is not readable.");
}
String firstLine;
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath))) {
firstLine = bufferedReader.readLine();
}
return firstLine;
}
}

View File

@ -47,6 +47,8 @@ ident-password: ''
sasl: false
# SASL password
sasl-password: ''
# Load SASL password from a file instead of this YAML file
sasl-password-file: ''
# SASL username
sasl-username: ''
# command-prefix - The bot will listen for commands that start with this.