Skip to content

Commit

Permalink
IS-2765: Bruke felles Aiven-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe committed Nov 14, 2024
1 parent b3c7148 commit 0914f39
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 134 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/redis.yaml

This file was deleted.

7 changes: 3 additions & 4 deletions .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ spec:
rules:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
Expand All @@ -85,19 +84,19 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
tokenx:
enabled: true
envFrom:
- secret: isdialogmote-serviceuser
- secret: isdialogmote-redis-password
- secret: isdialogmote-altinnuser
kafka:
pool: nav-dev
env:
- name: KTOR_ENV
value: production
- name: REDIS_HOST
value: "isdialogmote-redis.teamsykefravr.svc.cluster.local"
- name: DOKARKIV_CLIENT_ID
value: "dev-fss.teamdokumenthandtering.dokarkiv-q1"
- name: DOKARKIV_URL
Expand Down
7 changes: 3 additions & 4 deletions .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ spec:
rules:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
Expand All @@ -85,19 +84,19 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
tokenx:
enabled: true
envFrom:
- secret: isdialogmote-serviceuser
- secret: isdialogmote-redis-password
- secret: isdialogmote-altinnuser
kafka:
pool: nav-prod
env:
- name: KTOR_ENV
value: "production"
- name: REDIS_HOST
value: "isdialogmote-redis.teamsykefravr.svc.cluster.local"
- name: DOKARKIV_CLIENT_ID
value: "prod-fss.teamdokumenthandtering.dokarkiv"
- name: DOKARKIV_URL
Expand Down
33 changes: 0 additions & 33 deletions .nais/redis-config.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions .nais/redisexporter.yaml

This file was deleted.

17 changes: 9 additions & 8 deletions src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ import no.nav.syfo.testdata.reset.kafka.kafkaTestdataResetConsumerConfig
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.KafkaProducer
import org.slf4j.LoggerFactory
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import redis.clients.jedis.*

const val applicationPort = 8080

Expand All @@ -76,14 +74,17 @@ fun main() {
kafkaEsyfovarselConfig(environment.kafka)
),
)

val redisConfig = environment.redisConfig
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
environment.redisHost,
environment.redisPort,
Protocol.DEFAULT_TIMEOUT,
environment.redisSecret
HostAndPort(redisConfig.host, redisConfig.port),
DefaultJedisClientConfig.builder()
.ssl(redisConfig.ssl)
.user(redisConfig.redisUsername)
.password(redisConfig.redisPassword)
.database(redisConfig.redisDB)
.build()
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.nav.syfo.application

import io.ktor.server.application.*
import no.nav.syfo.application.cache.RedisConfig
import java.net.URI
import java.time.LocalDate

data class Environment(
Expand All @@ -27,9 +29,12 @@ data class Environment(
aivenTruststoreLocation = getEnvVar("KAFKA_TRUSTSTORE_PATH"),
aivenKeystoreLocation = getEnvVar("KAFKA_KEYSTORE_PATH"),
),
val redisHost: String = getEnvVar("REDIS_HOST"),
val redisPort: Int = getEnvVar("REDIS_PORT", "6379").toInt(),
val redisSecret: String = getEnvVar("REDIS_PASSWORD"),
val redisConfig: RedisConfig = RedisConfig(
redisUri = URI(getEnvVar("REDIS_URI_CACHE")),
redisDB = 7, // se https://github.com/navikt/istilgangskontroll/blob/master/README.md
redisUsername = getEnvVar("REDIS_USERNAME_CACHE"),
redisPassword = getEnvVar("REDIS_PASSWORD_CACHE"),
),
val isdialogmoteDbHost: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_HOST"),
val isdialogmoteDbPort: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_PORT"),
val isdialogmoteDbName: String = getEnvVar("NAIS_DATABASE_ISDIALOGMOTE_ISDIALOGMOTE_DB_DATABASE"),
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/no/nav/syfo/application/cache/RedisConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package no.nav.syfo.application.cache

import java.net.URI

class RedisConfig(
val redisUri: URI,
val redisDB: Int,
val redisUsername: String,
val redisPassword: String,
val ssl: Boolean = true
) {
val host: String = redisUri.host
val port: Int = redisUri.port
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ class ArbeidstakerBrevApiSpek : Spek({
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
externalMockEnvironment.environment.redisConfig.host,
externalMockEnvironment.environment.redisConfig.port,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
)
val tokendingsClient = TokendingsClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ object NarmesteLederBrevSpek : Spek({
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
externalMockEnvironment.environment.redisConfig.host,
externalMockEnvironment.environment.redisConfig.port,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
)
val tokendingsClient = TokendingsClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ object IdenthendelseServiceSpek : Spek({
redisStore = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
externalMockEnvironment.environment.redisConfig.host,
externalMockEnvironment.environment.redisConfig.port,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
),
),
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/no/nav/syfo/testhelper/TestApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ fun Application.testApiModule(
val cache = RedisStore(
JedisPool(
JedisPoolConfig(),
externalMockEnvironment.environment.redisHost,
externalMockEnvironment.environment.redisPort,
externalMockEnvironment.environment.redisConfig.host,
externalMockEnvironment.environment.redisConfig.port,
Protocol.DEFAULT_TIMEOUT,
externalMockEnvironment.environment.redisSecret
)
)
val tokendingsClient = TokendingsClient(
Expand Down
12 changes: 9 additions & 3 deletions src/test/kotlin/no/nav/syfo/testhelper/TestEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import io.ktor.utils.io.core.*
import no.nav.syfo.application.ApplicationEnvironmentKafka
import no.nav.syfo.application.ApplicationState
import no.nav.syfo.application.Environment
import no.nav.syfo.application.cache.RedisConfig
import java.net.ServerSocket
import java.net.URI
import java.time.LocalDate

fun testEnvironment(
Expand Down Expand Up @@ -44,9 +46,13 @@ fun testEnvironment(
aivenTruststoreLocation = "truststore",
aivenKeystoreLocation = "keystore",
),
redisHost = "localhost",
redisPort = 6599,
redisSecret = "password",
redisConfig = RedisConfig(
redisUri = URI("http://localhost:6379"),
redisDB = 0,
redisUsername = "redisUser",
redisPassword = "redisPassword",
ssl = false,
),
isdialogmoteDbHost = "localhost",
isdialogmoteDbPort = "5432",
isdialogmoteDbName = "isdialogmote_dev",
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/no/nav/syfo/testhelper/TestRedis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import no.nav.syfo.application.Environment
import redis.embedded.RedisServer

fun testRedis(environment: Environment): RedisServer = RedisServer.builder()
.port(environment.redisPort)
.setting("requirepass " + environment.redisSecret)
.port(environment.redisConfig.port)
.build()

0 comments on commit 0914f39

Please sign in to comment.