Skip to content

Commit de15e2b

Browse files
committed
Main must have body
1 parent 2e95370 commit de15e2b

File tree

2 files changed

+75
-73
lines changed

2 files changed

+75
-73
lines changed

dp-inntekt-api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repositories {
99

1010
application {
1111
applicationName = "dp-inntekt-api"
12-
mainClassName = "no.nav.dagpenger.inntekt.InntektApiKt"
12+
mainClassName = "no.nav.dagpenger.inntekt.ApplicationKt"
1313
}
1414

1515
val grpcVersion = "1.29.0"

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/Application.kt

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,84 +25,86 @@ import no.nav.dagpenger.oidc.StsOidcClient
2525
private val LOGGER = KotlinLogging.logger {}
2626
private val config = Configuration()
2727

28-
fun main() = runBlocking {
29-
migrate(config)
30-
DefaultExports.initialize()
28+
fun main() {
29+
runBlocking {
30+
migrate(config)
31+
DefaultExports.initialize()
3132

32-
val dataSource = dataSourceFrom(config)
33-
val authApiKeyVerifier = AuthApiKeyVerifier(
34-
apiKeyVerifier = ApiKeyVerifier(config.application.apiSecret),
35-
clients = config.application.allowedApiKeys
36-
)
37-
val postgresInntektStore = PostgresInntektStore(dataSource)
38-
val stsOidcClient = StsOidcClient(
39-
config.application.oicdStsUrl,
40-
config.application.username,
41-
config.application.password
42-
)
43-
val inntektskomponentHttpClient = InntektskomponentHttpClient(
44-
config.application.hentinntektListeUrl,
45-
stsOidcClient
46-
)
47-
val cachedInntektsGetter = BehandlingsInntektsGetter(inntektskomponentHttpClient, postgresInntektStore)
48-
val oppslagClient = OppslagClient(config.application.oppslagUrl, stsOidcClient)
49-
val jwkProvider = JwkProviderBuilder(URL(config.application.jwksUrl))
50-
.cached(10, 24, TimeUnit.HOURS)
51-
.rateLimited(10, 1, TimeUnit.MINUTES)
52-
.build()
33+
val dataSource = dataSourceFrom(config)
34+
val authApiKeyVerifier = AuthApiKeyVerifier(
35+
apiKeyVerifier = ApiKeyVerifier(config.application.apiSecret),
36+
clients = config.application.allowedApiKeys
37+
)
38+
val postgresInntektStore = PostgresInntektStore(dataSource)
39+
val stsOidcClient = StsOidcClient(
40+
config.application.oicdStsUrl,
41+
config.application.username,
42+
config.application.password
43+
)
44+
val inntektskomponentHttpClient = InntektskomponentHttpClient(
45+
config.application.hentinntektListeUrl,
46+
stsOidcClient
47+
)
48+
val cachedInntektsGetter = BehandlingsInntektsGetter(inntektskomponentHttpClient, postgresInntektStore)
49+
val oppslagClient = OppslagClient(config.application.oppslagUrl, stsOidcClient)
50+
val jwkProvider = JwkProviderBuilder(URL(config.application.jwksUrl))
51+
.cached(10, 24, TimeUnit.HOURS)
52+
.rateLimited(10, 1, TimeUnit.MINUTES)
53+
.build()
5354

54-
// Marks inntekt as used
55-
val subsumsjonBruktDataConsumer =
56-
KafkaSubsumsjonBruktDataConsumer(config, postgresInntektStore).apply {
57-
listen()
58-
}.also {
59-
Runtime.getRuntime().addShutdownHook(Thread {
60-
it.stop()
61-
})
62-
}
55+
// Marks inntekt as used
56+
val subsumsjonBruktDataConsumer =
57+
KafkaSubsumsjonBruktDataConsumer(config, postgresInntektStore).apply {
58+
listen()
59+
}.also {
60+
Runtime.getRuntime().addShutdownHook(Thread {
61+
it.stop()
62+
})
63+
}
6364

64-
// Provides a gRPC server for getting inntekt
65-
InntektGrpcServer(
66-
port = 50051,
67-
inntektStore = postgresInntektStore,
68-
apiKeyVerifier = authApiKeyVerifier
69-
).also {
70-
launch {
71-
it.start()
72-
it.blockUntilShutdown()
65+
// Provides a gRPC server for getting inntekt
66+
InntektGrpcServer(
67+
port = 50051,
68+
inntektStore = postgresInntektStore,
69+
apiKeyVerifier = authApiKeyVerifier
70+
).also {
71+
launch {
72+
it.start()
73+
it.blockUntilShutdown()
74+
}
7375
}
74-
}
7576

76-
// Provides a HTTP API for getting inntekt
77-
embeddedServer(Netty, port = config.application.httpPort) {
78-
inntektApi(
79-
inntektskomponentHttpClient,
80-
postgresInntektStore,
81-
cachedInntektsGetter,
82-
oppslagClient,
83-
authApiKeyVerifier,
84-
jwkProvider,
85-
listOf(
86-
postgresInntektStore as HealthCheck,
87-
subsumsjonBruktDataConsumer as HealthCheck
77+
// Provides a HTTP API for getting inntekt
78+
embeddedServer(Netty, port = config.application.httpPort) {
79+
inntektApi(
80+
inntektskomponentHttpClient,
81+
postgresInntektStore,
82+
cachedInntektsGetter,
83+
oppslagClient,
84+
authApiKeyVerifier,
85+
jwkProvider,
86+
listOf(
87+
postgresInntektStore as HealthCheck,
88+
subsumsjonBruktDataConsumer as HealthCheck
89+
)
8890
)
89-
)
90-
}.start().also {
91-
Runtime.getRuntime().addShutdownHook(Thread {
92-
it.stop(5, 60, TimeUnit.SECONDS)
93-
})
94-
}
95-
96-
// Cleans up unused inntekt on a regular interbal
97-
Vaktmester(dataSource).also {
98-
fixedRateTimer(
99-
name = "vaktmester",
100-
initialDelay = TimeUnit.MINUTES.toMillis(10),
101-
period = TimeUnit.HOURS.toMillis(12),
102-
action = {
103-
LOGGER.info { "Vaktmesteren rydder" }
104-
it.rydd()
105-
LOGGER.info { "Vaktmesteren er ferdig... for denne gang" }
91+
}.start().also {
92+
Runtime.getRuntime().addShutdownHook(Thread {
93+
it.stop(5, 60, TimeUnit.SECONDS)
10694
})
95+
}
96+
97+
// Cleans up unused inntekt on a regular interbal
98+
Vaktmester(dataSource).also {
99+
fixedRateTimer(
100+
name = "vaktmester",
101+
initialDelay = TimeUnit.MINUTES.toMillis(10),
102+
period = TimeUnit.HOURS.toMillis(12),
103+
action = {
104+
LOGGER.info { "Vaktmesteren rydder" }
105+
it.rydd()
106+
LOGGER.info { "Vaktmesteren er ferdig... for denne gang" }
107+
})
108+
}
107109
}
108110
}

0 commit comments

Comments
 (0)