Skip to content

Commit

Permalink
Merge pull request #522 from swisspost/support_redis_tls_connection
Browse files Browse the repository at this point in the history
added redis tls support
  • Loading branch information
dominik-cnx authored Aug 3, 2023
2 parents 6a30fd1 + 5812982 commit d20cd24
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ jobs:

- name: Install chromedriver
uses: nanasess/[email protected]

with:
# Optional: do not specify to match Chrome's version
chromedriver-version: '114.0.5735.90'

- name: Install, unit test
run: mvn install -Dmaven.javadoc.skip=true -PpublicRepos -B -V

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ public void start() {

String redisHost = (String) props.get("redis.host");
Integer redisPort = (Integer) props.get("redis.port");
boolean redisEnableTls = props.get("redis.enableTls") != null ? (Boolean) props.get("redis.enableTls") : false;

props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_HARD_PROPERTY, "100");
props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_SOFT_PROPERTY, "50");

RunConfig.deployModules(vertx, Server.class, props, success -> {
if (success) {
redisClient = new RedisClient(vertx, new RedisOptions().setConnectionString("redis://" + redisHost + ":" + redisPort));
String protocol = redisEnableTls ? "rediss://" : "redis://";
redisClient = new RedisClient(vertx, new RedisOptions().setConnectionString(protocol + redisHost + ":" + redisPort));
redisApi = RedisAPI.api(redisClient);
RedisProvider redisProvider = () -> Future.succeededFuture(redisApi);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,17 @@ public RunConfig build(Vertx vertx, RedisProvider redisProvider, Class verticleC
* Builds redis properties configuration.
*/
public static Map<String, Object> buildRedisProps(String redisHost, int redisPort) {
return buildRedisProps(redisHost, redisPort, false);
}

/**
* Builds redis properties configuration.
*/
public static Map<String, Object> buildRedisProps(String redisHost, int redisPort, boolean redisEnableTls) {
final Map<String, Object> props = new HashMap<>();
props.put("redis.host", redisHost);
props.put("redis.port", redisPort);
props.put("redis.enableTls", redisEnableTls);
props.put("redis.encoding", "UTF-8");
return props;
}
Expand All @@ -393,9 +401,17 @@ public static Map<String, Object> buildRedisProps(String redisHost, int redisPor
* Builds a standard mod redis configuration.
*/
public static JsonObject buildModRedisConfig(String redisHost, int redisPort) {
return buildModRedisConfig(redisHost, redisPort, false);
}

/**
* Builds a standard mod redis configuration.
*/
public static JsonObject buildModRedisConfig(String redisHost, int redisPort, boolean redisEnableTls) {
JsonObject config = new JsonObject();
config.put("host", redisHost);
config.put("port", redisPort);
config.put("enableTls", redisEnableTls);
config.put("encoding", "UTF-8");
return config;
}
Expand Down Expand Up @@ -480,7 +496,8 @@ public static void deployModules(final Vertx vertx, Class verticleClass, Map<Str
final Logger log = LoggerFactory.getLogger(verticleClass);
String redisHost = (String) props.get("redis.host");
Integer redisPort = (Integer) props.get("redis.port");
log.info("deploying redis module with host:" + redisHost + " port:" + redisPort);
boolean redisEnableTls = props.get("redis.enableTls") != null ? (Boolean) props.get("redis.enableTls") : false;
log.info("deploying redis module with host: {}, port: {}, TLS: {}", redisHost, redisPort, redisEnableTls);

// redisques module
vertx.deployVerticle("org.swisspush.redisques.RedisQues", new DeploymentOptions().setConfig(RunConfig.buildRedisquesConfig()).setInstances(4), event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ public static void setupBeforeClass(TestContext context) {

String redisHost = (String) props.get("redis.host");
Integer redisPort = (Integer) props.get("redis.port");
boolean redisEnableTls = props.get("redis.enableTls") != null ? (Boolean) props.get("redis.enableTls") : false;

props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_HARD_PROPERTY, "100");
props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_SOFT_PROPERTY, "4");

RunConfig.deployModules(vertx, AbstractTest.class, props, success -> {
if (success) {
RedisClient redisClient = new RedisClient(vertx, new RedisOptions().setConnectionString("redis://" + redisHost + ":" + redisPort));
String protocol = redisEnableTls ? "rediss://" : "redis://";
RedisClient redisClient = new RedisClient(vertx, new RedisOptions().setConnectionString(protocol + redisHost + ":" + redisPort));
RedisAPI redisAPI = RedisAPI.api(redisClient);
RedisProvider redisProvider = () -> Future.succeededFuture(redisAPI);

Expand Down

0 comments on commit d20cd24

Please sign in to comment.