Skip to content

Commit

Permalink
Bygg Redis-URI selv
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga committed Jan 16, 2025
1 parent 5675876 commit 823feea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ object Routes {

fun main() {
val rapid = RapidApplication.create(System.getenv())
val aivenRedisConnection = RedisConnection(Env.Redis.aivenUri)
val aivenRedisConnection =
RedisConnection(
host = Env.Redis.host,
port = Env.Redis.port,
username = Env.Redis.username,
password = Env.Redis.password,
)
val redisConnection = RedisConnection(Env.Redis.url)

embeddedServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
object Auth {
val discoveryUrl: String = "IDPORTEN_WELL_KNOWN_URL".fromEnv()
val acceptedAudience: List<String> = "IDPORTEN_AUDIENCE".fromEnv().let(::listOf)
val discoveryUrl = "IDPORTEN_WELL_KNOWN_URL".fromEnv()
val acceptedAudience = "IDPORTEN_AUDIENCE".fromEnv().let(::listOf)
}

object Redis {
val aivenUri: String = "REDIS_URI_INNTEKTSMELDING".fromEnv()
val url: String = "REDIS_URL".fromEnv()
val host = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val port = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val username = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val password = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()

val url = "REDIS_URL".fromEnv()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package no.nav.helsearbeidsgiver.felles.rapidsrivers.redis

import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.sync.RedisCommands
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull

class RedisConnection(
redisUri: String,
) {
constructor(
host: String,
port: Int,
username: String,
password: String,
) : this(
RedisURI
.builder()
.withSsl(true)
.withHost(host)
.withPort(port)
.withAuthentication(username, password)
.withDatabase(0)
.build()
.toURI()
.toString(),
)

private val client: RedisClient = RedisClient.create(redisUri)
private val connection: StatefulRedisConnection<String, String> = client.connect()
private val syncCommands: RedisCommands<String, String> = connection.sync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-hent-forespoersel-service".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUri)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.trengerservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUri = "REDIS_URI_INNTEKTSMELDING".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}

0 comments on commit 823feea

Please sign in to comment.