mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
feat: make redis user and database configurable (#518)
* Make redis user and database configurable * Update documentation
This commit is contained in:
@@ -159,7 +159,9 @@ public class Settings {
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public static class RedisSettings {
|
public static class RedisSettings {
|
||||||
|
|
||||||
@Comment("Specify the credentials of your Redis server here. Set \"password\" to '' if you don't have one")
|
@Comment({"Specify the credentials of your Redis server here.",
|
||||||
|
"Set \"user\" to '' if you don't have one or would like to use the default user.",
|
||||||
|
"Set \"password\" to '' if you don't have one."})
|
||||||
private RedisCredentials credentials = new RedisCredentials();
|
private RedisCredentials credentials = new RedisCredentials();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -168,6 +170,9 @@ public class Settings {
|
|||||||
public static class RedisCredentials {
|
public static class RedisCredentials {
|
||||||
private String host = "localhost";
|
private String host = "localhost";
|
||||||
private int port = 6379;
|
private int port = 6379;
|
||||||
|
@Comment("Only change the database if you know what you are doing. The default is 0.")
|
||||||
|
private int database = 0;
|
||||||
|
private String user = "";
|
||||||
private String password = "";
|
private String password = "";
|
||||||
private boolean useSsl = false;
|
private boolean useSsl = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,9 +65,11 @@ public class RedisManager extends JedisPubSub {
|
|||||||
@Blocking
|
@Blocking
|
||||||
public void initialize() throws IllegalStateException {
|
public void initialize() throws IllegalStateException {
|
||||||
final Settings.RedisSettings.RedisCredentials credentials = plugin.getSettings().getRedis().getCredentials();
|
final Settings.RedisSettings.RedisCredentials credentials = plugin.getSettings().getRedis().getCredentials();
|
||||||
|
final String user = credentials.getUser();
|
||||||
final String password = credentials.getPassword();
|
final String password = credentials.getPassword();
|
||||||
final String host = credentials.getHost();
|
final String host = credentials.getHost();
|
||||||
final int port = credentials.getPort();
|
final int port = credentials.getPort();
|
||||||
|
final int database = credentials.getDatabase();
|
||||||
final boolean useSSL = credentials.isUseSsl();
|
final boolean useSSL = credentials.isUseSsl();
|
||||||
|
|
||||||
// Create the jedis pool
|
// Create the jedis pool
|
||||||
@@ -79,9 +81,20 @@ public class RedisManager extends JedisPubSub {
|
|||||||
final Settings.RedisSettings.RedisSentinel sentinel = plugin.getSettings().getRedis().getSentinel();
|
final Settings.RedisSettings.RedisSentinel sentinel = plugin.getSettings().getRedis().getSentinel();
|
||||||
Set<String> redisSentinelNodes = new HashSet<>(sentinel.getNodes());
|
Set<String> redisSentinelNodes = new HashSet<>(sentinel.getNodes());
|
||||||
if (redisSentinelNodes.isEmpty()) {
|
if (redisSentinelNodes.isEmpty()) {
|
||||||
this.jedisPool = password.isEmpty()
|
DefaultJedisClientConfig.Builder clientConfigBuilder = DefaultJedisClientConfig.builder()
|
||||||
? new JedisPool(config, host, port, 0, useSSL)
|
.ssl(useSSL)
|
||||||
: new JedisPool(config, host, port, 0, password, useSSL);
|
.database(database)
|
||||||
|
.timeoutMillis(0);
|
||||||
|
|
||||||
|
if (!user.isEmpty()) {
|
||||||
|
clientConfigBuilder.user(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.isEmpty()) {
|
||||||
|
clientConfigBuilder.password(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.jedisPool = new JedisPool(config, new HostAndPort(host, port), clientConfigBuilder.build());
|
||||||
} else {
|
} else {
|
||||||
final String sentinelPassword = sentinel.getPassword();
|
final String sentinelPassword = sentinel.getPassword();
|
||||||
this.jedisPool = new JedisSentinelPool(sentinel.getMaster(), redisSentinelNodes, password.isEmpty()
|
this.jedisPool = new JedisSentinelPool(sentinel.getMaster(), redisSentinelNodes, password.isEmpty()
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ public interface DumpProvider {
|
|||||||
Map.entry("Redis Version", StatusLine.REDIS_VERSION.getValue(getPlugin())),
|
Map.entry("Redis Version", StatusLine.REDIS_VERSION.getValue(getPlugin())),
|
||||||
Map.entry("Redis Latency", StatusLine.REDIS_LATENCY.getValue(getPlugin())),
|
Map.entry("Redis Latency", StatusLine.REDIS_LATENCY.getValue(getPlugin())),
|
||||||
Map.entry("Redis Sentinel", StatusLine.USING_REDIS_SENTINEL.getValue(getPlugin())),
|
Map.entry("Redis Sentinel", StatusLine.USING_REDIS_SENTINEL.getValue(getPlugin())),
|
||||||
|
Map.entry("Redis Database", StatusLine.REDIS_DATABASE.getValue(getPlugin())),
|
||||||
|
Map.entry("Redis User", StatusLine.USING_REDIS_USER.getValue(getPlugin())),
|
||||||
Map.entry("Redis Password", StatusLine.USING_REDIS_PASSWORD.getValue(getPlugin())),
|
Map.entry("Redis Password", StatusLine.USING_REDIS_PASSWORD.getValue(getPlugin())),
|
||||||
Map.entry("Redis SSL", StatusLine.REDIS_USING_SSL.getValue(getPlugin())),
|
Map.entry("Redis SSL", StatusLine.REDIS_USING_SSL.getValue(getPlugin())),
|
||||||
Map.entry("Redis Local", StatusLine.IS_REDIS_LOCAL.getValue(getPlugin()))
|
Map.entry("Redis Local", StatusLine.IS_REDIS_LOCAL.getValue(getPlugin()))
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ public enum StatusLine {
|
|||||||
USING_REDIS_SENTINEL(plugin -> getBoolean(
|
USING_REDIS_SENTINEL(plugin -> getBoolean(
|
||||||
!plugin.getSettings().getRedis().getSentinel().getMaster().isBlank()
|
!plugin.getSettings().getRedis().getSentinel().getMaster().isBlank()
|
||||||
)),
|
)),
|
||||||
|
REDIS_DATABASE(plugin -> Component.text(plugin.getSettings().getRedis().getCredentials().getDatabase())),
|
||||||
|
USING_REDIS_USER(plugin -> getBoolean(
|
||||||
|
!plugin.getSettings().getRedis().getCredentials().getUser().isBlank()
|
||||||
|
)),
|
||||||
USING_REDIS_PASSWORD(plugin -> getBoolean(
|
USING_REDIS_PASSWORD(plugin -> getBoolean(
|
||||||
!plugin.getSettings().getRedis().getCredentials().getPassword().isBlank()
|
!plugin.getSettings().getRedis().getCredentials().getPassword().isBlank()
|
||||||
)),
|
)),
|
||||||
|
|||||||
@@ -65,10 +65,15 @@ database:
|
|||||||
user_data: husksync_user_data
|
user_data: husksync_user_data
|
||||||
# Redis settings
|
# Redis settings
|
||||||
redis:
|
redis:
|
||||||
# Specify the credentials of your Redis server here. Set "password" to '' if you don't have one
|
# Specify the credentials of your Redis server here.
|
||||||
|
# Set "user" to '' if you don't have one or would like to use the default user.
|
||||||
|
# Set "password" to '' if you don't have one.
|
||||||
credentials:
|
credentials:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
|
# Only change the database if you know what you are doing. The default is 0.
|
||||||
|
database: 0
|
||||||
|
user: ''
|
||||||
password: ''
|
password: ''
|
||||||
use_ssl: false
|
use_ssl: false
|
||||||
# Options for if you're using Redis sentinel. Don't modify this unless you know what you're doing!
|
# Options for if you're using Redis sentinel. Don't modify this unless you know what you're doing!
|
||||||
|
|||||||
@@ -16,10 +16,15 @@ To configure Redis, navigate to your [`config.yml`](Config-File) file and modify
|
|||||||
```yaml
|
```yaml
|
||||||
# Redis settings
|
# Redis settings
|
||||||
redis:
|
redis:
|
||||||
# Specify the credentials of your Redis server here. Set "password" to '' if you don't have one
|
# Specify the credentials of your Redis server here.
|
||||||
|
# Set "user" to '' if you don't have one or would like to use the default user.
|
||||||
|
# Set "password" to '' if you don't have one.
|
||||||
credentials:
|
credentials:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
|
# Only change the database if you know what you are doing. The default is 0.
|
||||||
|
database: 0
|
||||||
|
user: ''
|
||||||
password: ''
|
password: ''
|
||||||
use_ssl: false
|
use_ssl: false
|
||||||
# Options for if you're using Redis sentinel. Don't modify this unless you know what you're doing!
|
# Options for if you're using Redis sentinel. Don't modify this unless you know what you're doing!
|
||||||
@@ -33,8 +38,9 @@ redis:
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Credentials
|
### Credentials
|
||||||
Enter the hostname, port, and default user password of your Redis server.
|
Enter the hostname, port, user, and password of your Redis server.
|
||||||
|
|
||||||
|
If you don't have a Redis user, just use the default user password and leave the user field empty (`user: ''`).
|
||||||
If your Redis default user doesn't have a password, leave the password field blank (`password: ''`') and the plugin will attempt to connect without a password.
|
If your Redis default user doesn't have a password, leave the password field blank (`password: ''`') and the plugin will attempt to connect without a password.
|
||||||
|
|
||||||
### Default user password
|
### Default user password
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ redis:
|
|||||||
credentials:
|
credentials:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
|
# Only change the database if you know what you are doing. The default is 0.
|
||||||
|
database: 0
|
||||||
|
user: ''
|
||||||
password: ''
|
password: ''
|
||||||
use_ssl: false
|
use_ssl: false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user