-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
stheppi
committed
Nov 2, 2023
1 parent
1f7947f
commit 61a7d89
Showing
2 changed files
with
72 additions
and
14 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.../main/scala/com/datamountaineer/streamreactor/connect/redis/sink/JedisClientBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2017-2023 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datamountaineer.streamreactor.connect.redis.sink | ||
|
||
import com.datamountaineer.streamreactor.connect.redis.sink.config.RedisSinkSettings | ||
import redis.clients.jedis.Jedis | ||
|
||
import java.io.File | ||
import java.io.FileNotFoundException | ||
|
||
object JedisClientBuilder { | ||
def createClient(sinkSettings: RedisSinkSettings): Jedis = { | ||
val connection = sinkSettings.connectionInfo | ||
|
||
if (connection.isSslConnection) { | ||
connection.keyStoreFilepath match { | ||
case Some(path) => | ||
if (!new File(path).exists) { | ||
throw new FileNotFoundException(s"Keystore not found in: [$path]") | ||
} | ||
|
||
System.setProperty("javax.net.ssl.keyStorePassword", connection.keyStorePassword.getOrElse("")) | ||
System.setProperty("javax.net.ssl.keyStore", path) | ||
System.setProperty("javax.net.ssl.keyStoreType", connection.keyStoreType.getOrElse("jceks")) | ||
|
||
case None => | ||
} | ||
|
||
connection.trustStoreFilepath match { | ||
case Some(path) => | ||
if (!new File(path).exists) { | ||
throw new FileNotFoundException(s"Truststore not found in: $path") | ||
} | ||
|
||
System.setProperty("javax.net.ssl.trustStorePassword", connection.trustStorePassword.getOrElse("")) | ||
System.setProperty("javax.net.ssl.trustStore", path) | ||
System.setProperty("javax.net.ssl.trustStoreType", connection.trustStoreType.getOrElse("jceks")) | ||
|
||
case None => | ||
} | ||
} | ||
|
||
val jedis = new Jedis(connection.host, connection.port, connection.isSslConnection) | ||
connection.password.foreach(p => jedis.auth(p)) | ||
jedis | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters