feat: password-file fallback for PostgreSQL (network credential convention)
This commit is contained in:
parent
023c8d1325
commit
78c03a7264
2 changed files with 20 additions and 1 deletions
|
|
@ -8,6 +8,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -66,8 +68,23 @@ public class ConfigManager {
|
||||||
return config.getString("database.postgresql.username", "lorep");
|
return config.getString("database.postgresql.username", "lorep");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** PG password: empty {@code password} falls back to one line of {@code password-file} (network convention). */
|
||||||
public String getPostgresPassword() {
|
public String getPostgresPassword() {
|
||||||
return config.getString("database.postgresql.password", "password");
|
String direct = config.getString("database.postgresql.password", "password");
|
||||||
|
if (direct != null && !direct.isEmpty()) {
|
||||||
|
return direct;
|
||||||
|
}
|
||||||
|
String path = config.getString("database.postgresql.password-file", "");
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
List<String> lines = Files.readAllLines(new File(path).toPath(), StandardCharsets.UTF_8);
|
||||||
|
return lines.isEmpty() ? "" : lines.get(0).trim();
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Cannot read password-file " + path + ": " + e.getMessage());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPostgresPoolSize() {
|
public int getPostgresPoolSize() {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ database:
|
||||||
port: 5432
|
port: 5432
|
||||||
database: "loreport"
|
database: "loreport"
|
||||||
username: "loreport"
|
username: "loreport"
|
||||||
|
# If the password above is empty, it is read from this file (single line).
|
||||||
password: "password"
|
password: "password"
|
||||||
|
password-file: ""
|
||||||
pool-size: 10
|
pool-size: 10
|
||||||
|
|
||||||
# ServGuard anticheat integration (reads the guard.violations table from the database above)
|
# ServGuard anticheat integration (reads the guard.violations table from the database above)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue