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

Add support SSL/TLS connection (832) #930

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Add support SSL/TLS connection (832) #930

merged 3 commits into from
Feb 8, 2024

Conversation

gkfabs
Copy link
Contributor

@gkfabs gkfabs commented Jan 30, 2024

Closes #832

Hi,

I added support for SSL/TLS

@gkfabs gkfabs requested a review from a team as a code owner January 30, 2024 08:29
@CLAassistant
Copy link

CLAassistant commented Jan 30, 2024

CLA assistant check
All committers have signed the CLA.

Comment on lines 20 to 23
override def toString: String = ssl match {
case true => s"rediss://$host:$port"
case false => s"redis://$host:$port"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
override def toString: String = ssl match {
case true => s"rediss://$host:$port"
case false => s"redis://$host:$port"
}
override def toString: String =
if (ssl) s"rediss://$host:$port" else s"redis://$host:$port"

@@ -101,7 +101,7 @@ object Output {
val host = MultiStringOutput.unsafeDecode(values(0))
val port = LongOutput.unsafeDecode(values(1))
val nodeId = MultiStringOutput.unsafeDecode(values(2))
Node(nodeId, RedisUri(host, port.toInt))
Node(nodeId, RedisUri(host, port.toInt, false, None))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

ZIO.attempt(docker.getServiceHost(s"cluster-node-$n", port)).map(host => RedisUri(host, port))
ZIO
.attempt(docker.getServiceHost(s"cluster-node-$n", port))
.map(host => RedisUri(host, port, false, None))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RedisUri change looks unnecessary (see RedisUri.apply).

@@ -31,7 +31,7 @@ trait BaseSpec extends ZIOSpecDefault {
for {
docker <- ZIO.service[DockerComposeContainer]
hostAndPort <- docker.getHostAndPort(BaseSpec.MasterNode)(6379)
uri = RedisUri(hostAndPort._1, hostAndPort._2)
uri = RedisUri(hostAndPort._1, hostAndPort._2, false, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks unnecessary (see RedisUri.apply).

Comment on lines 24 to 25
ssl: Boolean = false,
sni: Option[String] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the alphabetical ordering.

@@ -161,7 +161,7 @@ private[redis] object ClusterExecutor {
private def redis(address: RedisUri) =
for {
closableScope <- Scope.make
configLayer = ZLayer.succeed(RedisConfig(address.host, address.port))
configLayer = ZLayer.succeed(RedisConfig(address.host, address.port, address.ssl))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened with sni?

Comment on lines 97 to 100
channel <- ssl match {
case true => openTlsChannel(address, sni)
case false => openChannel(address)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
channel <- ssl match {
case true => openTlsChannel(address, sni)
case false => openChannel(address)
}
channel <- if (ssl) openTlsChannel(address, sni) else openChannel(address)

val sslContext = SSLContext.getDefault()
val sslEngine = sslContext.createSSLEngine()
val params = sslEngine.getSSLParameters
sni match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach

rawChannel.finishConnect()
rawChannel.register(selector, SelectionKey.OP_WRITE)
val channelGroup = new AsynchronousTlsChannelGroup()
val channel = new AsynchronousTlsChannel(channelGroup, tlsChannel, rawChannel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this val.

): ZIO[Scope, IOException, AsynchronousTlsChannel] =
ZIO.fromAutoCloseable {
for {
channel <- ZIO.attempt {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd extract the attempt block into a function, something like createChannel

@mijicd mijicd merged commit 2ac2107 into zio:master Feb 8, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support SSL/TLS secure connection
3 participants