Skip to content

Commit

Permalink
1.1.4 Release
Browse files Browse the repository at this point in the history
Cleanup, log4j props file not needed anymore when isLocal is false

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
  • Loading branch information
jnmoyne committed Oct 5, 2023
1 parent cc2f975 commit 1b46efc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 116 deletions.
71 changes: 13 additions & 58 deletions load_balanced/src/main/scala/natsconnector/NatsConfig.scala
Expand Up @@ -428,71 +428,23 @@ class NatsConfig(isSource: Boolean) {
builder.authHandler(Nats.credentials(System.getenv("NATS_CREDS")));
}

val tlsAlgo = if (System.getenv("NATS_TLS_ALGO") != null && System.getenv("NATS_TLS_ALGO") != "") {
System.getenv("NATS_TLS_ALGO")
} else "SunX509"

val instanceType = if (System.getenv("NATS_TLS_STORE_TYPE") != null && System.getenv("NATS_TLS_STORE_TYPE") != "") {
System.getenv("NATS_TLS_STORE_TYPE")
} else "JKS"
if (System.getenv("NATS_TLS_ALGO") != null && System.getenv("NATS_TLS_ALGO") != "") {
builder.tlsAlgorithm(System.getenv("NATS_TLS_ALGO"))
}

if (System.getenv("NATS_TLS_TRUST_STORE") != null && System.getenv("NATS_TLS_TRUST_STORE") != "") {
// val trustStorePassword = if (System.getenv("NATS_TLS_TRUST_STORE_PASSWORD") != null) {
// System.getenv("NATS_TLS_TRUST_STORE_PASSWORD").toCharArray
// } else "".toCharArray

// val ctx = javax.net.ssl.SSLContext.getInstance(Options.DEFAULT_SSL_PROTOCOL)
//
// val trustStore = KeyStore.getInstance(instanceType)
// val inputTrustF = new BufferedInputStream(Files.newInputStream(Paths.get(System.getenv("NATS_TLS_TRUST_STORE"))))
// try {
// trustStore.load(inputTrustF, trustStorePassword)
// } catch {
// case e: Exception => System.out.println("Exception " + e.getMessage)
// } finally {
// if (inputTrustF != null) inputTrustF.close()
// }
//
// val tmsFactory = TrustManagerFactory.getInstance(tlsAlgo)
// tmsFactory.init(trustStore)
// val tms = tmsFactory.getTrustManagers

builder.truststorePath(System.getenv("NATS_TLS_TRUST_STORE"));
if (System.getenv("NATS_TLS_TRUST_STORE_PASSWORD") != null) {
builder.truststorePassword(System.getenv("NATS_TLS_TRUST_STORE_PASSWORD").toCharArray)
}
}

if (System.getenv("NATS_TLS_KEY_STORE") != null) {
if (System.getenv("NATS_TLS_KEY_STORE_PASSWORD") != null) {
builder.keystorePassword(System.getenv("NATS_TLS_KEY_STORE_PASSWORD").toCharArray)
}


/* val keyStore = KeyStore.getInstance(instanceType)
val inputKeyF = new BufferedInputStream(Files.newInputStream(Paths.get(System.getenv("NATS_TLS_KEY_STORE"))))
try {
keyStore.load(inputKeyF, keyStorePassword)
} catch {
case e: Exception => System.out.println("Exception " + e.getMessage)
} finally {
if (inputKeyF != null) {
inputKeyF.close()
}
}
val kmsFactory = KeyManagerFactory.getInstance(tlsAlgo)
kmsFactory.init(keyStore, keyStorePassword)
val kms = kmsFactory.getKeyManagers
ctx.init(kms, tms, new SecureRandom())
builder.sslContext(ctx)*/
builder.keystorePath(System.getenv("NATS_TLS_KEY_STORE"));

} else {
// ctx.init(null, tms, new SecureRandom())
// builder.sslContext(ctx)
if (System.getenv("NATS_TLS_KEY_STORE") != null) {
if (System.getenv("NATS_TLS_KEY_STORE_PASSWORD") != null) {
builder.keystorePassword(System.getenv("NATS_TLS_KEY_STORE_PASSWORD").toCharArray)
}
builder.keystorePath(System.getenv("NATS_TLS_KEY_STORE"));
}

if (this.userName.isDefined) {
Expand All @@ -506,9 +458,12 @@ class NatsConfig(isSource: Boolean) {
object NatsLogger {
val logger = {
val logger: Logger = Logger.getLogger("NATSCON =>")
val log4JPropertyFile = if (System.getenv("LOG_PROP_PATH") != null) System.getenv("LOG_PROP_PATH") else "src/test/resources/log4j.properties"
val p = new Properties()
p.load(new FileInputStream(log4JPropertyFile))

if (System.getenv("LOG_PROP_PATH") != null) {
p.load(new FileInputStream(System.getenv("LOG_PROP_PATH")))
}

PropertyConfigurator.configure(p)
logger
}
Expand Down
Binary file not shown.
71 changes: 13 additions & 58 deletions partitioned/src/main/scala/natsconnector/NatsConfig.scala
Expand Up @@ -246,71 +246,23 @@ class NatsConfig(isSource:Boolean) {
builder.authHandler(Nats.credentials(System.getenv("NATS_CREDS")));
}

val tlsAlgo = if (System.getenv("NATS_TLS_ALGO") != null && System.getenv("NATS_TLS_ALGO") != "") {
System.getenv("NATS_TLS_ALGO")
} else "SunX509"

val instanceType = if (System.getenv("NATS_TLS_STORE_TYPE") != null && System.getenv("NATS_TLS_STORE_TYPE") != "") {
System.getenv("NATS_TLS_STORE_TYPE")
} else "JKS"
if (System.getenv("NATS_TLS_ALGO") != null && System.getenv("NATS_TLS_ALGO") != "") {
builder.tlsAlgorithm(System.getenv("NATS_TLS_ALGO"))
}

if (System.getenv("NATS_TLS_TRUST_STORE") != null && System.getenv("NATS_TLS_TRUST_STORE") != "") {
// val trustStorePassword = if (System.getenv("NATS_TLS_TRUST_STORE_PASSWORD") != null) {
// System.getenv("NATS_TLS_TRUST_STORE_PASSWORD").toCharArray
// } else "".toCharArray

// val ctx = javax.net.ssl.SSLContext.getInstance(Options.DEFAULT_SSL_PROTOCOL)
//
// val trustStore = KeyStore.getInstance(instanceType)
// val inputTrustF = new BufferedInputStream(Files.newInputStream(Paths.get(System.getenv("NATS_TLS_TRUST_STORE"))))
// try {
// trustStore.load(inputTrustF, trustStorePassword)
// } catch {
// case e: Exception => System.out.println("Exception " + e.getMessage)
// } finally {
// if (inputTrustF != null) inputTrustF.close()
// }
//
// val tmsFactory = TrustManagerFactory.getInstance(tlsAlgo)
// tmsFactory.init(trustStore)
// val tms = tmsFactory.getTrustManagers

builder.truststorePath(System.getenv("NATS_TLS_TRUST_STORE"));
if (System.getenv("NATS_TLS_TRUST_STORE_PASSWORD") != null) {
builder.truststorePassword(System.getenv("NATS_TLS_TRUST_STORE_PASSWORD").toCharArray)
}
}

if (System.getenv("NATS_TLS_KEY_STORE") != null) {
if (System.getenv("NATS_TLS_KEY_STORE_PASSWORD") != null) {
builder.keystorePassword(System.getenv("NATS_TLS_KEY_STORE_PASSWORD").toCharArray)
}


/* val keyStore = KeyStore.getInstance(instanceType)
val inputKeyF = new BufferedInputStream(Files.newInputStream(Paths.get(System.getenv("NATS_TLS_KEY_STORE"))))
try {
keyStore.load(inputKeyF, keyStorePassword)
} catch {
case e: Exception => System.out.println("Exception " + e.getMessage)
} finally {
if (inputKeyF != null) {
inputKeyF.close()
}
}
val kmsFactory = KeyManagerFactory.getInstance(tlsAlgo)
kmsFactory.init(keyStore, keyStorePassword)
val kms = kmsFactory.getKeyManagers
ctx.init(kms, tms, new SecureRandom())
builder.sslContext(ctx)*/
builder.keystorePath(System.getenv("NATS_TLS_KEY_STORE"));

} else {
// ctx.init(null, tms, new SecureRandom())
// builder.sslContext(ctx)
if (System.getenv("NATS_TLS_KEY_STORE") != null) {
if (System.getenv("NATS_TLS_KEY_STORE_PASSWORD") != null) {
builder.keystorePassword(System.getenv("NATS_TLS_KEY_STORE_PASSWORD").toCharArray)
}
builder.keystorePath(System.getenv("NATS_TLS_KEY_STORE"));
}

if (this.userName.isDefined) {
Expand All @@ -327,9 +279,12 @@ case class NatsMsg(val subject:String, val dateTime:String, val content:String)
object NatsLogger {
val logger = {
val logger: Logger = Logger.getLogger("NATSCON =>")
val log4JPropertyFile = if (System.getenv("LOG_PROP_PATH") != null) System.getenv("LOG_PROP_PATH") else "src/test/resources/log4j.properties"
val p = new Properties()
p.load(new FileInputStream(log4JPropertyFile))

if (System.getenv("LOG_PROP_PATH") != null) {
p.load(new FileInputStream(System.getenv("LOG_PROP_PATH")))
}

PropertyConfigurator.configure(p)
logger
}
Expand Down
Binary file not shown.

0 comments on commit 1b46efc

Please sign in to comment.