Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ constructor(
val writer_endpoint: RedisNodeConfig,
val reader_endpoint: RedisNodeConfig? = null,
@Redact val redis_auth_password: String,
val redis_auth_username: String? = null,
val use_ssl: Boolean = true,
val timeout_ms: Int = DEFAULT_TIMEOUT_MS,
val connection_pool: RedisConnectionPoolConfig = RedisConnectionPoolConfig(),
Expand Down Expand Up @@ -136,6 +137,7 @@ constructor(
val client_name: String? = null,
val configuration_endpoint: RedisNodeConfig,
@Redact val redis_auth_password: String,
val redis_auth_username: String? = null,
val use_ssl: Boolean = true,
val timeout_ms: Int = DEFAULT_TIMEOUT_MS,
val connection_pool: RedisConnectionPoolConfig = RedisConnectionPoolConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ internal constructor(
redisUri {
withHost(hostname.takeIf { it.isNotBlank() } ?: "localhost")
withPort(port)
withPassword(clusterGroupConfig.redis_auth_password.toCharArray())
val username = clusterGroupConfig.redis_auth_username
val password = clusterGroupConfig.redis_auth_password.toCharArray()
if (username != null) {
withAuthentication(username, password)
} else {
withPassword(password)
}
withSsl(clusterGroupConfig.use_ssl)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ internal constructor(
withHost(hostname.takeIf { it.isNotBlank() } ?: "localhost")
withPort(port)
}
withPassword(replicationGroupConfig.redis_auth_password.toCharArray())
val username = replicationGroupConfig.redis_auth_username
val password = replicationGroupConfig.redis_auth_password.toCharArray()
if (username != null) {
withAuthentication(username, password)
} else {
withPassword(password)
}
withSsl(replicationGroupConfig.use_ssl)
}

Expand Down Expand Up @@ -119,6 +125,7 @@ internal constructor(
codec = codec,
useSsl = use_ssl,
password = redis_auth_password.takeIf { it.isNotBlank() },
username = redis_auth_username,
annotation = qualifier,
)
)
Expand All @@ -136,6 +143,7 @@ internal constructor(
codec = codec,
useSsl = use_ssl,
password = redis_auth_password.takeIf { it.isNotBlank() },
username = redis_auth_username,
annotation = qualifier,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal class StatefulRedisConnectionProviderModule<K : Any, V : Any, T : State
private val codec: RedisCodec<K, V>,
private val useSsl: Boolean,
private val password: String?,
private val username: String?,
private val annotation: Annotation?,
) : KAbstractModule() {

Expand All @@ -66,7 +67,13 @@ internal class StatefulRedisConnectionProviderModule<K : Any, V : Any, T : State
withPort(port)
}
withSsl(useSsl)
password?.let { withPassword(password.toCharArray()) }
password?.let {
if (username != null) {
withAuthentication(username, password.toCharArray())
} else {
withPassword(password.toCharArray())
}
}
}

val connectionProviderKey = connectionProviderType.toKey(annotation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package misk.redis.lettuce

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

/**
* Unit tests for Redis configuration classes.
*/
internal class RedisConfigTest {

@Test
fun `RedisReplicationGroupConfig with username`() {
val config = RedisReplicationGroupConfig(
client_name = "test-client",
writer_endpoint = RedisNodeConfig(hostname = "localhost", port = 6379),
redis_auth_password = "secret-password",
redis_auth_username = "my-username",
use_ssl = true,
)

assertEquals("my-username", config.redis_auth_username)
assertEquals("secret-password", config.redis_auth_password)
}

@Test
fun `RedisReplicationGroupConfig without username defaults to null`() {
val config = RedisReplicationGroupConfig(
writer_endpoint = RedisNodeConfig(hostname = "localhost", port = 6379),
redis_auth_password = "secret-password",
)

assertNull(config.redis_auth_username)
}

@Test
fun `RedisClusterGroupConfig with username`() {
val config = RedisClusterGroupConfig(
client_name = "test-cluster",
configuration_endpoint = RedisNodeConfig(hostname = "cluster.example.com", port = 6379),
redis_auth_password = "cluster-password",
redis_auth_username = "cluster-username",
use_ssl = true,
)

assertEquals("cluster-username", config.redis_auth_username)
assertEquals("cluster-password", config.redis_auth_password)
}

@Test
fun `RedisClusterGroupConfig without username defaults to null`() {
val config = RedisClusterGroupConfig(
configuration_endpoint = RedisNodeConfig(hostname = "cluster.example.com", port = 6379),
redis_auth_password = "cluster-password",
)

assertNull(config.redis_auth_username)
}
}
Loading