Skip to content

Commit

Permalink
cdk-java: move JdbcSSLConnectionUtils to core submodule, refactor Str…
Browse files Browse the repository at this point in the history
…ing constants
  • Loading branch information
stephane-airbyte committed Jul 17, 2024
1 parent 2f738e7 commit ac50449
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.cdk.integrations.source.jdbc
package io.airbyte.cdk.db.jdbc

import com.fasterxml.jackson.databind.JsonNode
import io.airbyte.cdk.db.jdbc.JdbcUtils
import io.airbyte.cdk.db.util.SSLCertificateUtils.keyStoreFromCertificate
import io.airbyte.cdk.db.util.SSLCertificateUtils.keyStoreFromClientCertificate
import io.airbyte.cdk.db.util.SSLCertificateUtils
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.IOException
import java.net.MalformedURLException
Expand Down Expand Up @@ -153,7 +148,7 @@ class JdbcSSLConnectionUtils {
val clientKeyPassword = getOrGeneratePassword(encryption)
try {
val caCertKeyStoreUri =
keyStoreFromCertificate(
SSLCertificateUtils.keyStoreFromCertificate(
encryption[PARAM_CA_CERTIFICATE].asText(),
clientKeyPassword,
null,
Expand Down Expand Up @@ -214,7 +209,7 @@ class JdbcSSLConnectionUtils {
val clientKeyPassword = getOrGeneratePassword(encryption)
try {
val clientCertKeyStoreUri =
keyStoreFromClientCertificate(
SSLCertificateUtils.keyStoreFromClientCertificate(
encryption[PARAM_CLIENT_CERTIFICATE].asText(),
encryption[PARAM_CLIENT_KEY].asText(),
clientKeyPassword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,14 @@ constructor(
const val GLOBAL_HEARTBEAT_INTERVAL_DEFAULT_IN_MILLIS: Long = 2000
const val IDLE_TIMEOUT_KEY: String = "idle_timeout"
const val IDLE_TIMEOUT_DEFAULT_INFINITE: Long = 0
const val TUNNEL_METHOD_KEY = "tunnel_method"

const val TIMEOUT_MILLIS: Int = 15000 // 15 seconds

@JvmStatic
fun getInstance(config: JsonNode, hostKey: List<String>, portKey: List<String>): SshTunnel {
val tunnelMethod =
Jsons.getOptional(config, "tunnel_method", "tunnel_method")
Jsons.getOptional(config, TUNNEL_METHOD_KEY, TUNNEL_METHOD_KEY)
.map { method: JsonNode ->
TunnelMethod.valueOf(method.asText().trim { it <= ' ' })
}
Expand All @@ -429,12 +430,12 @@ constructor(
null,
null,
tunnelMethod,
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "tunnel_host")),
Jsons.getIntOrZero(config, "tunnel_method", "tunnel_port"),
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "tunnel_user")),
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "ssh_key")),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_host")),
Jsons.getIntOrZero(config, TUNNEL_METHOD_KEY, "tunnel_port"),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_user")),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "ssh_key")),
Strings.safeTrim(
Jsons.getStringOrNull(config, "tunnel_method", "tunnel_user_password")
Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_user_password")
),
Strings.safeTrim(Jsons.getStringOrNull(config, hostKey)),
Jsons.getIntOrZero(config, portKey),
Expand Down Expand Up @@ -479,7 +480,7 @@ constructor(
@Throws(Exception::class)
fun getInstance(config: JsonNode, endPointKey: String): SshTunnel {
val tunnelMethod =
Jsons.getOptional(config, "tunnel_method", "tunnel_method")
Jsons.getOptional(config, TUNNEL_METHOD_KEY, TUNNEL_METHOD_KEY)
.map { method: JsonNode ->
TunnelMethod.valueOf(method.asText().trim { it <= ' ' })
}
Expand All @@ -493,12 +494,12 @@ constructor(
endPointKey,
Jsons.getStringOrNull(config, endPointKey),
tunnelMethod,
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "tunnel_host")),
Jsons.getIntOrZero(config, "tunnel_method", "tunnel_port"),
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "tunnel_user")),
Strings.safeTrim(Jsons.getStringOrNull(config, "tunnel_method", "ssh_key")),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_host")),
Jsons.getIntOrZero(config, TUNNEL_METHOD_KEY, "tunnel_port"),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_user")),
Strings.safeTrim(Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "ssh_key")),
Strings.safeTrim(
Jsons.getStringOrNull(config, "tunnel_method", "tunnel_user_password")
Jsons.getStringOrNull(config, TUNNEL_METHOD_KEY, "tunnel_user_password")
),
null,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private val log = KotlinLogging.logger {}
object JsonSchemas {
private const val JSON_SCHEMA_ENUM_KEY = "enum"
private const val JSON_SCHEMA_TYPE_KEY = "type"
private const val JSON_SCHEMA_PROPERTIES_KEY = "properties"
const val JSON_SCHEMA_PROPERTIES_KEY = "properties"
private const val JSON_SCHEMA_ITEMS_KEY = "items"

// all JSONSchema types.
Expand Down

0 comments on commit ac50449

Please sign in to comment.