Skip to content

Commit

Permalink
Leser ORDS config fra Secret-fil uten .sh
Browse files Browse the repository at this point in the history
  • Loading branch information
igorweber committed Dec 19, 2024
1 parent e19e8c7 commit 19abf17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ TOKEN_X_CLIENT_ID
For å kjøre mot f.eks Q1 kan man enten sette riktige miljøvariabler (manuelt eller ved hjelp av bat/bash script) eller midlertidig skrive disse inn i Environment.kt i stedet for defaultValue'er.
For eksempel, for å bruke ORDS i Q1 må man erstatte
```
val ordsUrl: URL = URL(getEnvVar("ORDS_URI", DUMMY_URL)),
val ordsClientId: String = getEnvVar("CLIENT_ID", "cLiEnTiD"),
val ordsClientSecret: String = getEnvVar("CLIENT_SECRET", "cLiEnTsEcReT"),
val ordsUrl: String = ordsSettings["ORDS_URI"] ?: DUMMY_URL,
val ordsClientId: String = ordsSettings["CLIENT_ID"] ?: "cLiEnTiD",
val ordsClientSecret: String = ordsSettings["CLIENT_SECRET"] ?: "cLiEnTsEcReT",
```
med
```
val ordsUrl: URL = URL(getEnvVar("ORDS_URI", "https://arena-ords-q1.dev.adeo.no/arena")),
val ordsClientId: String = getEnvVar("CLIENT_ID", "%CLIENT_ID_FRA_VAULT%"),
val ordsClientSecret: String = getEnvVar("CLIENT_SECRET", "%CLIENT_SECRET_FRA_VAULT%"),
val ordsUrl: String = "https://arena-ords-q1.dev.adeo.no/arena",
val ordsClientId: String = "%CLIENT_ID_FRA_VAULT%",
val ordsClientSecret: String = "%CLIENT_SECRET_FRA_VAULT%",
```
Appen starter på http://localhost:8090. Sjekk for eksempel at ping svarer på http://localhost:8090/meldekortservice/internal/ping.
Swagger er tilgjengelig på http://localhost:8090/meldekortservice/internal/apidocs/index.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package no.nav.meldeplikt.meldekortservice.config
import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import java.io.File
import java.net.URI
import java.net.URL

const val ordsSecretPath = "/var/run/secrets/nais.io/vault/arenaOrds.env"
const val dbUserSecretPath = "/secrets/dbuser/meldekortservicedbuser"
const val dbConfigSecretPath = "/secrets/dbconf/meldekortservicedbconf"
const val DUMMY_URL = "https://dummyurl.nav.no"
Expand All @@ -16,11 +15,16 @@ val DUMMY_TOKEN = JWT.create()
.withClaim("iat", 1616239022)
.sign(Algorithm.none())
.toString()
val ordsSettings: Map<String, String> = File(ordsSecretPath)
.takeIf { it.exists() }
?.readLines()
?.associate { it.substringBefore("=") to it.substringAfter("=") }
?: emptyMap()

data class Environment(
val ordsUrl: URL = URI.create(getEnvVar("ORDS_URI", DUMMY_URL)).toURL(),
val ordsClientId: String = getEnvVar("CLIENT_ID", "cLiEnTiD"),
val ordsClientSecret: String = getEnvVar("CLIENT_SECRET", "cLiEnTsEcReT"),
val ordsUrl: String = ordsSettings["ORDS_URI"] ?: DUMMY_URL,
val ordsClientId: String = ordsSettings["CLIENT_ID"] ?: "cLiEnTiD",
val ordsClientSecret: String = ordsSettings["CLIENT_SECRET"] ?: "cLiEnTsEcReT",

// PostgreSQL
val dbHostPostgreSQL: String = getEnvVar("DB_HOST", "localhost:5434"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import no.nav.meldeplikt.meldekortservice.config.Environment
import no.nav.meldeplikt.meldekortservice.mapper.MeldekortdetaljerMapper
import no.nav.meldeplikt.meldekortservice.model.AccessToken
import no.nav.meldeplikt.meldekortservice.model.ArenaOrdsSkrivemodus
import no.nav.meldeplikt.meldekortservice.model.feil.NoContentException
import no.nav.meldeplikt.meldekortservice.model.feil.OrdsException
import no.nav.meldeplikt.meldekortservice.model.korriger.KopierMeldekortResponse
import no.nav.meldeplikt.meldekortservice.model.meldegruppe.MeldegruppeResponse
Expand All @@ -23,7 +22,6 @@ import no.nav.meldeplikt.meldekortservice.model.meldekortdetaljer.Meldekortdetal
import no.nav.meldeplikt.meldekortservice.model.meldekortdetaljer.arena.Meldekort
import no.nav.meldeplikt.meldekortservice.model.response.OrdsStringResponse
import no.nav.meldeplikt.meldekortservice.utils.*
import java.net.URI
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -198,7 +196,7 @@ class ArenaOrdsService(
defaultLog.debug("Henter ORDS-token")
var token = AccessToken(null, null, null)

if (env.ordsUrl != URI.create(DUMMY_URL).toURL()) {
if (env.ordsUrl != DUMMY_URL) {
runBlocking {
val response = ordsClient.post("${env.ordsUrl}$ARENA_ORDS_TOKEN_PATH?grant_type=client_credentials") {
setupTokenRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import no.nav.meldeplikt.meldekortservice.utils.isCurrentlyRunningOnNais
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.net.URI
import java.time.LocalDate
import kotlin.test.assertEquals

Expand Down Expand Up @@ -430,7 +429,7 @@ class ArenaOrdsServiceTest {
fun `test request retry`() {
var count = 0
val url = "https://not-so-dummyurl.nav.no"
val env = Environment(URI.create(url).toURL())
val env = Environment(url)

val token = AccessToken(
accessToken = DUMMY_TOKEN,
Expand Down

0 comments on commit 19abf17

Please sign in to comment.