Skip to content

Commit 99c3148

Browse files
MartinMekknavelgen
andcommitted
🐛 Bruk riktig navn på env variabler
Flytt fraEnv ut av hver modul for å gjøre oppsettet mer oversikt over environmentavhengigheter. Det er også dr det gir mening å vite noe om environment. Co-authored-by: Svein Elgstøen <[email protected]>
1 parent 5997de5 commit 99c3148

File tree

9 files changed

+66
-90
lines changed

9 files changed

+66
-90
lines changed

Diff for: deploy/dev.yml

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ spec:
117117
value: "http://spleis-api"
118118
- name: BRUK_DUMMY_FOR_KONTAKT_OG_RESERVASJONSREGISTERET
119119
value: "true"
120-
- name: TILLATT_UAUTENTISERT_INTROSPECTION
121-
value: "true"
122120
- name: TILLAT_GODKJENNING_UTEN_BESLUTTERTILGANG
123121
value: "true"
124122
- name: TILLAT_GODKJENNING_AV_EGEN_SAK

Diff for: spesialist-api/src/main/kotlin/no/nav/helse/spesialist/api/AzureConfig.kt

-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ data class AzureConfig(
1212
val jwkProvider: JwkProvider,
1313
val tokenEndpoint: String,
1414
) {
15-
companion object {
16-
fun fraEnv(env: Map<String, String>) =
17-
AzureConfig(
18-
clientId = env.getValue("AZURE_APP_CLIENT_ID"),
19-
issuerUrl = env.getValue("AZURE_OPENID_CONFIG_ISSUER"),
20-
jwkProviderUri = env.getValue("AZURE_OPENID_CONFIG_JWKS_URI"),
21-
tokenEndpoint = env.getValue("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT"),
22-
)
23-
}
24-
2515
constructor(
2616
clientId: String,
2717
issuerUrl: String,

Diff for: spesialist-bootstrap/src/main/kotlin/no/nav/helse/spesialist/bootstrap/Configuration.kt

+1-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package no.nav.helse.spesialist.bootstrap
33
import no.nav.helse.bootstrap.EnvironmentToggles
44
import no.nav.helse.modell.automatisering.Stikkprøver
55
import no.nav.helse.spesialist.api.AzureConfig
6-
import no.nav.helse.spesialist.api.bootstrap.SpeilTilgangsgrupper
76
import no.nav.helse.spesialist.api.bootstrap.Tilgangsgrupper
87
import no.nav.helse.spesialist.client.entraid.EntraIDAccessTokenGenerator
98
import no.nav.helse.spesialist.client.krr.KRRClientReservasjonshenter
@@ -21,20 +20,4 @@ data class Configuration(
2120
val tilgangsgrupper: Tilgangsgrupper,
2221
val environmentToggles: EnvironmentToggles,
2322
val stikkprøver: Stikkprøver,
24-
) {
25-
companion object {
26-
fun fraEnv(env: Map<String, String>): Configuration =
27-
Configuration(
28-
azureConfig = AzureConfig.fraEnv(env),
29-
accessTokenGeneratorConfig = EntraIDAccessTokenGenerator.Configuration.fraEnv(env),
30-
spleisClientConfig = SpleisClient.Configuration.fraEnv(env),
31-
krrConfig = KRRClientReservasjonshenter.Configuration.fraEnv(env),
32-
dbConfig = DBModule.Configuration.fraEnv(env),
33-
unleashFeatureToggles = UnleashFeatureToggles.Configuration.fraEnv(env),
34-
versjonAvKode = env.getValue("NAIS_APP_IMAGE"),
35-
tilgangsgrupper = SpeilTilgangsgrupper(env),
36-
environmentToggles = EnvironmentTogglesImpl(env),
37-
stikkprøver = Stikkprøver.fraEnv(env),
38-
)
39-
}
40-
}
23+
)

Diff for: spesialist-bootstrap/src/main/kotlin/no/nav/helse/spesialist/bootstrap/RapidApp.kt

+60-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ import no.nav.helse.mediator.TilgangskontrollørForReservasjon
2222
import no.nav.helse.mediator.dokument.DokumentMediator
2323
import no.nav.helse.mediator.oppgave.ApiOppgaveService
2424
import no.nav.helse.mediator.oppgave.OppgaveService
25+
import no.nav.helse.modell.automatisering.Stikkprøver
2526
import no.nav.helse.modell.stoppautomatiskbehandling.StansAutomatiskBehandlinghåndtererImpl
2627
import no.nav.helse.modell.varsel.VarselRepository
2728
import no.nav.helse.rapids_rivers.RapidApplication
29+
import no.nav.helse.spesialist.api.AzureConfig
30+
import no.nav.helse.spesialist.api.bootstrap.SpeilTilgangsgrupper
2831
import no.nav.helse.spesialist.api.graphql.settOppGraphQLApi
2932
import no.nav.helse.spesialist.application.Reservasjonshenter
3033
import no.nav.helse.spesialist.client.entraid.EntraIDAccessTokenGenerator
@@ -36,13 +39,62 @@ import no.nav.helse.spesialist.db.FlywayMigrator
3639
import no.nav.helse.spesialist.db.bootstrap.DBModule
3740
import org.slf4j.LoggerFactory
3841
import java.lang.management.ManagementFactory
42+
import java.net.URI
3943

4044
fun main() {
45+
val env = System.getenv()
4146
RapidApp.start(
42-
configuration = Configuration.fraEnv(System.getenv()),
47+
configuration =
48+
Configuration(
49+
azureConfig =
50+
AzureConfig(
51+
clientId = env.getValue("AZURE_APP_CLIENT_ID"),
52+
issuerUrl = env.getValue("AZURE_OPENID_CONFIG_ISSUER"),
53+
jwkProviderUri = env.getValue("AZURE_OPENID_CONFIG_JWKS_URI"),
54+
tokenEndpoint = env.getValue("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT"),
55+
),
56+
accessTokenGeneratorConfig =
57+
EntraIDAccessTokenGenerator.Configuration(
58+
clientId = env.getValue("AZURE_APP_CLIENT_ID"),
59+
tokenEndpoint = env.getValue("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT"),
60+
privateJwk = env.getValue("AZURE_APP_JWK"),
61+
),
62+
spleisClientConfig =
63+
SpleisClient.Configuration(
64+
spleisUrl = URI.create(env.getValue("SPLEIS_API_URL")),
65+
spleisClientId = env.getValue("SPLEIS_CLIENT_ID"),
66+
),
67+
krrConfig =
68+
KRRClientReservasjonshenter.Configuration(
69+
apiUrl = env.getValue("KONTAKT_OG_RESERVASJONSREGISTERET_API_URL"),
70+
scope = env.getValue("KONTAKT_OG_RESERVASJONSREGISTERET_SCOPE"),
71+
),
72+
dbConfig =
73+
DBModule.Configuration(
74+
jdbcUrl =
75+
"jdbc:postgresql://" +
76+
env.getValue("DATABASE_HOST") +
77+
":" +
78+
env.getValue("DATABASE_PORT") +
79+
"/" +
80+
env.getValue("DATABASE_DATABASE"),
81+
username = env.getValue("DATABASE_USERNAME"),
82+
password = env.getValue("DATABASE_PASSWORD"),
83+
),
84+
unleashFeatureToggles =
85+
UnleashFeatureToggles.Configuration(
86+
apiKey = env.getValue("UNLEASH_SERVER_API_TOKEN"),
87+
apiUrl = env.getValue("UNLEASH_SERVER_API_URL"),
88+
apiEnv = env.getValue("UNLEASH_SERVER_API_ENV"),
89+
),
90+
versjonAvKode = env.getValue("NAIS_APP_IMAGE"),
91+
tilgangsgrupper = SpeilTilgangsgrupper(env),
92+
environmentToggles = EnvironmentTogglesImpl(env),
93+
stikkprøver = Stikkprøver.fraEnv(env),
94+
),
4395
rapidsConnection =
4496
RapidApplication.create(
45-
env = System.getenv(),
97+
env = env,
4698
meterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT).also(Metrics.globalRegistry::add),
4799
builder = {
48100
withKtorModule {
@@ -97,7 +149,12 @@ object RapidApp {
97149
Kommandofabrikk(
98150
oppgaveService = { oppgaveService },
99151
godkjenningMediator = GodkjenningMediator(daos.opptegnelseDao),
100-
subsumsjonsmelderProvider = { Subsumsjonsmelder(configuration.versjonAvKode, meldingPubliserer) },
152+
subsumsjonsmelderProvider = {
153+
Subsumsjonsmelder(
154+
configuration.versjonAvKode,
155+
meldingPubliserer,
156+
)
157+
},
101158
stikkprøver = configuration.stikkprøver,
102159
featureToggles = featureToggles,
103160
),

Diff for: spesialist-bootstrap/src/main/kotlin/no/nav/helse/spesialist/bootstrap/UnleashFeatureToggles.kt

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ class UnleashFeatureToggles(configuration: Configuration) : FeatureToggles {
1010
val apiKey: String,
1111
val apiUrl: String,
1212
val apiEnv: String,
13-
) {
14-
companion object {
15-
fun fraEnv(env: Map<String, String>) =
16-
Configuration(
17-
apiKey = requireNotNull(env["UNLEASH_SERVER_API_TOKEN"]),
18-
apiUrl = requireNotNull(env["UNLEASH_SERVER_API_URL"]),
19-
apiEnv = requireNotNull(env["UNLEASH_SERVER_API_ENV"]),
20-
)
21-
}
22-
}
13+
)
2314

2415
private val config: UnleashConfig =
2516
UnleashConfig.builder()

Diff for: spesialist-client-entra-id/src/main/kotlin/no/nav/helse/spesialist/client/entraid/EntraIDAccessTokenGenerator.kt

+1-10
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ class EntraIDAccessTokenGenerator(private val configuration: Configuration) : Ac
3737
val clientId: String,
3838
val tokenEndpoint: String,
3939
val privateJwk: String,
40-
) {
41-
companion object {
42-
fun fraEnv(env: Map<String, String>) =
43-
Configuration(
44-
clientId = env.getValue("AZURE_APP_CLIENT_ID"),
45-
tokenEndpoint = env.getValue("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT"),
46-
privateJwk = env.getValue("AZURE_APP_JWK"),
47-
)
48-
}
49-
}
40+
)
5041

5142
private val log = LoggerFactory.getLogger(EntraIDAccessTokenGenerator::class.java)
5243
private val sikkerLogg = LoggerFactory.getLogger("tjenestekall")

Diff for: spesialist-client-krr/src/main/kotlin/no/nav/helse/spesialist/client/krr/KRRClientReservasjonshenter.kt

+1-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,7 @@ class KRRClientReservasjonshenter(
4444
data class Configuration(
4545
val apiUrl: String,
4646
val scope: String,
47-
) {
48-
companion object {
49-
fun fraEnv(env: Map<String, String>) =
50-
Configuration(
51-
apiUrl = env.getValue("KONTAKT_OG_RESERVASJONSREGISTERET_API_URL"),
52-
scope = env.getValue("KONTAKT_OG_RESERVASJONSREGISTERET_SCOPE"),
53-
)
54-
}
55-
}
47+
)
5648

5749
private val logg: Logger = LoggerFactory.getLogger(this.javaClass)
5850
private val sikkerLogg: Logger = LoggerFactory.getLogger("tjenestekall")

Diff for: spesialist-client-spleis/src/main/kotlin/no/nav/helse/spesialist/client/spleis/SpleisClient.kt

+1-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ class SpleisClient(
3737
data class Configuration(
3838
val spleisUrl: URI,
3939
val spleisClientId: String,
40-
) {
41-
companion object {
42-
fun fraEnv(env: Map<String, String>) =
43-
Configuration(
44-
spleisUrl = URI.create(env.getValue("SPL_CLIENT_URL")),
45-
spleisClientId = env.getValue("SPL_CLIENT_ID"),
46-
)
47-
}
48-
}
40+
)
4941

5042
private val serializer: GraphQLClientSerializer =
5143
GraphQLClientJacksonSerializer(

Diff for: spesialist-db/src/main/kotlin/no/nav/helse/spesialist/db/bootstrap/DBModule.kt

+1-19
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,7 @@ class DBModule(configuration: Configuration) {
1010
val jdbcUrl: String,
1111
val username: String,
1212
val password: String,
13-
) {
14-
companion object {
15-
fun fraEnv(env: Map<String, String>): Configuration {
16-
return Configuration(
17-
jdbcUrl =
18-
"jdbc:postgresql://" +
19-
env.getRequired("DATABASE_HOST") +
20-
":" +
21-
env.getRequired("DATABASE_PORT") +
22-
"/" +
23-
env.getRequired("DATABASE_DATABASE"),
24-
username = env.getRequired("DATABASE_USERNAME"),
25-
password = env.getRequired("DATABASE_PASSWORD"),
26-
)
27-
}
28-
29-
private fun Map<String, String>.getRequired(name: String) = this[name] ?: error("$name må settes")
30-
}
31-
}
13+
)
3214

3315
val dataSource = DataSourceBuilder(configuration).build()
3416
val daos = DBDaos(dataSource)

0 commit comments

Comments
 (0)