|
15 | 15 | */ |
16 | 16 | package com.redis.kafka.connect.common; |
17 | 17 |
|
18 | | -import com.github.jcustenborder.kafka.connect.utils.config.ConfigKeyBuilder; |
19 | | -import com.github.jcustenborder.kafka.connect.utils.config.validators.Validators; |
20 | | -import io.lettuce.core.RedisURI; |
| 18 | +import java.util.Map; |
| 19 | + |
21 | 20 | import org.apache.kafka.common.config.AbstractConfig; |
22 | 21 | import org.apache.kafka.common.config.ConfigDef; |
23 | 22 |
|
24 | | -import java.util.Map; |
| 23 | +import com.github.jcustenborder.kafka.connect.utils.config.ConfigKeyBuilder; |
| 24 | +import com.github.jcustenborder.kafka.connect.utils.config.ConfigUtils; |
| 25 | +import com.github.jcustenborder.kafka.connect.utils.config.validators.Validators; |
| 26 | + |
| 27 | +import io.lettuce.core.RedisURI; |
25 | 28 |
|
26 | 29 | public class RedisEnterpriseConfig extends AbstractConfig { |
27 | 30 |
|
28 | | - public static final String REDIS_URI_CONFIG = "redis.uri"; |
29 | | - private static final String REDIS_URI_DEFAULT = "redis://localhost:6379"; |
30 | | - private static final String REDIS_URI_DOC = "URI of the Redis Enterprise database to connect to, e.g. redis://redis-12000.redis.com:12000"; |
| 31 | + public static final String REDIS_URI_CONFIG = "redis.uri"; |
| 32 | + private static final String REDIS_URI_DEFAULT = "redis://localhost:6379"; |
| 33 | + private static final String REDIS_URI_DOC = "URI of the Redis Enterprise database to connect to, e.g. redis://redis-12000.redis.com:12000. For secure connections use rediss URI scheme, e.g. rediss://..."; |
| 34 | + |
| 35 | + public static final String INSECURE_CONFIG = "redis.insecure"; |
| 36 | + public static final String INSECURE_DEFAULT = "false"; |
| 37 | + public static final String INSECURE_DOC = "Allow insecure connections (e.g. invalid certificates) to Redis Enterprise when using SSL."; |
| 38 | + |
| 39 | + public static final String REDIS_USERNAME_CONFIG = "redis.username"; |
| 40 | + private static final String REDIS_USERNAME_DEFAULT = null; |
| 41 | + private static final String REDIS_USERNAME_DOC = "Username to use to connect to Redis Enterprise database"; |
| 42 | + |
| 43 | + public static final String REDIS_PASSWORD_CONFIG = "redis.password"; |
| 44 | + private static final String REDIS_PASSWORD_DEFAULT = null; |
| 45 | + private static final String REDIS_PASSWORD_DOC = "Password to use to connect to Redis Enterprise database"; |
31 | 46 |
|
32 | | - public static final String INSECURE_CONFIG = "redis.insecure"; |
33 | | - public static final String INSECURE_DEFAULT = "false"; |
34 | | - public static final String INSECURE_DOC = "Allow insecure connections (e.g. invalid certificates) to Redis Enterprise when using SSL."; |
| 47 | + public RedisEnterpriseConfig(ConfigDef config, Map<?, ?> originals) { |
| 48 | + super(config, originals); |
| 49 | + } |
35 | 50 |
|
36 | | - public RedisEnterpriseConfig(ConfigDef config, Map<?, ?> originals) { |
37 | | - super(config, originals); |
38 | | - } |
| 51 | + public RedisURI getRedisURI() { |
| 52 | + RedisURI uri = RedisURI.create(ConfigUtils.uri(this, REDIS_URI_CONFIG)); |
| 53 | + uri.setVerifyPeer(!getBoolean(INSECURE_CONFIG)); |
| 54 | + String username = getString(REDIS_URI_CONFIG); |
| 55 | + if (!isEmpty(username)) { |
| 56 | + uri.setUsername(username); |
| 57 | + } |
| 58 | + if (get(REDIS_PASSWORD_CONFIG) != null) { |
| 59 | + char[] password = ConfigUtils.passwordCharArray(this, REDIS_PASSWORD_CONFIG); |
| 60 | + if (password.length > 0) { |
| 61 | + uri.setPassword(password); |
| 62 | + } |
| 63 | + } |
| 64 | + return uri; |
| 65 | + } |
39 | 66 |
|
40 | | - public RedisURI getRedisURI() { |
41 | | - RedisURI uri = RedisURI.create(getString(REDIS_URI_CONFIG)); |
42 | | - uri.setVerifyPeer(!getBoolean(INSECURE_CONFIG)); |
43 | | - return uri; |
44 | | - } |
| 67 | + protected static boolean isEmpty(String string) { |
| 68 | + return string == null || string.isEmpty(); |
| 69 | + } |
45 | 70 |
|
46 | | - protected static class RedisEnterpriseConfigDef extends ConfigDef { |
| 71 | + protected static class RedisEnterpriseConfigDef extends ConfigDef { |
47 | 72 |
|
48 | | - protected RedisEnterpriseConfigDef() { |
49 | | - defineConfigs(); |
50 | | - } |
| 73 | + protected RedisEnterpriseConfigDef() { |
| 74 | + defineConfigs(); |
| 75 | + } |
51 | 76 |
|
52 | | - protected RedisEnterpriseConfigDef(ConfigDef base) { |
53 | | - super(base); |
54 | | - defineConfigs(); |
55 | | - } |
| 77 | + protected RedisEnterpriseConfigDef(ConfigDef base) { |
| 78 | + super(base); |
| 79 | + defineConfigs(); |
| 80 | + } |
56 | 81 |
|
57 | | - private void defineConfigs() { |
58 | | - define(ConfigKeyBuilder.of(REDIS_URI_CONFIG, ConfigDef.Type.STRING).documentation(REDIS_URI_DOC).defaultValue(REDIS_URI_DEFAULT).importance(ConfigDef.Importance.HIGH).validator(Validators.validURI("redis", "rediss")).build()); |
59 | | - define(ConfigKeyBuilder.of(INSECURE_CONFIG, ConfigDef.Type.BOOLEAN).documentation(INSECURE_DOC).defaultValue(INSECURE_DEFAULT).importance(ConfigDef.Importance.MEDIUM).build()); |
60 | | - } |
| 82 | + private void defineConfigs() { |
| 83 | + define(ConfigKeyBuilder.of(REDIS_URI_CONFIG, ConfigDef.Type.STRING).documentation(REDIS_URI_DOC) |
| 84 | + .defaultValue(REDIS_URI_DEFAULT).importance(ConfigDef.Importance.HIGH) |
| 85 | + .validator(Validators.validURI("redis", "rediss")).build()); |
| 86 | + define(ConfigKeyBuilder.of(REDIS_USERNAME_CONFIG, ConfigDef.Type.STRING).documentation(REDIS_USERNAME_DOC) |
| 87 | + .defaultValue(REDIS_USERNAME_DEFAULT).importance(ConfigDef.Importance.MEDIUM).build()); |
| 88 | + define(ConfigKeyBuilder.of(REDIS_PASSWORD_CONFIG, ConfigDef.Type.PASSWORD).documentation(REDIS_PASSWORD_DOC) |
| 89 | + .defaultValue(REDIS_PASSWORD_DEFAULT).importance(ConfigDef.Importance.MEDIUM).build()); |
| 90 | + define(ConfigKeyBuilder.of(INSECURE_CONFIG, ConfigDef.Type.BOOLEAN).documentation(INSECURE_DOC) |
| 91 | + .defaultValue(INSECURE_DEFAULT).importance(ConfigDef.Importance.MEDIUM).build()); |
| 92 | + } |
61 | 93 |
|
62 | | - } |
| 94 | + } |
63 | 95 |
|
64 | 96 | } |
0 commit comments