Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-4610] Add SSL support for RedisIO #8161

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public abstract class RedisConnectionConfiguration implements Serializable {

abstract int timeout();

abstract boolean ssl();

abstract Builder builder();

@AutoValue.Builder
Expand All @@ -54,6 +56,8 @@ abstract static class Builder {

abstract Builder setTimeout(int timeout);

abstract Builder setSsl(boolean ssl);

abstract RedisConnectionConfiguration build();
}

Expand All @@ -62,6 +66,7 @@ public static RedisConnectionConfiguration create() {
.setHost(Protocol.DEFAULT_HOST)
.setPort(Protocol.DEFAULT_PORT)
.setTimeout(Protocol.DEFAULT_TIMEOUT)
.setSsl(false)
.build();
}

Expand All @@ -70,6 +75,7 @@ public static RedisConnectionConfiguration create(String host, int port) {
.setHost(host)
.setPort(port)
.setTimeout(Protocol.DEFAULT_TIMEOUT)
.setSsl(false)
.build();
}

Expand Down Expand Up @@ -99,9 +105,14 @@ public RedisConnectionConfiguration withTimeout(int timeout) {
return builder().setTimeout(timeout).build();
}

/** Enable SSL connection to Redis server. */
public RedisConnectionConfiguration enableSSL() {
return builder().setSsl(true).build();
}

/** Connect to the Redis instance. */
public Jedis connect() {
Jedis jedis = new Jedis(host(), port(), timeout());
Jedis jedis = new Jedis(host(), port(), timeout(), ssl());
if (auth() != null) {
jedis.auth(auth());
}
Expand All @@ -113,5 +124,6 @@ public void populateDisplayData(DisplayData.Builder builder) {
builder.add(DisplayData.item("host", host()));
builder.add(DisplayData.item("port", port()));
builder.addIfNotNull(DisplayData.item("timeout", timeout()));
builder.add(DisplayData.item("ssl", ssl()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public void testReadBuildsCorrectly() {
Assert.assertEquals(111, read.connectionConfiguration().port());
Assert.assertEquals("pass", read.connectionConfiguration().auth());
Assert.assertEquals(5, read.connectionConfiguration().timeout());
Assert.assertEquals(false, read.connectionConfiguration().ssl());
}

@Test
Expand All @@ -258,6 +259,7 @@ public void testWriteBuildsCorrectly() {
Assert.assertEquals(111, write.connectionConfiguration().port());
Assert.assertEquals("pass", write.connectionConfiguration().auth());
Assert.assertEquals(5, write.connectionConfiguration().timeout());
Assert.assertEquals(false, write.connectionConfiguration().ssl());
Assert.assertEquals(Method.APPEND, write.method());
}

Expand Down