Skip to content

Commit 81ffa8b

Browse files
committed
Fix indentation
1 parent 048809e commit 81ffa8b

26 files changed

+385
-388
lines changed

src/main/kotlin/no/nav/syfo/Environment.kt

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,54 @@ fun getEnvironment(): Environment {
1616
objectMapper.readValue(firstExistingFile(localEnvironmentPropertiesPath, defaultlocalEnvironmentPropertiesPath), Environment::class.java)
1717
} else {
1818
Environment(
19-
getEnvVar("APPLICATION_PORT", "8080").toInt(),
20-
getEnvVar("APPLICATION_THREADS", "1").toInt(),
21-
getEnvVar("APPLICATION_NAME", "syfooversiktsrv"),
22-
getEnvVar("AADDISCOVERY_URL"),
23-
getEnvVar("JWKKEYS_URL", "https://login.microsoftonline.com/common/discovery/keys"),
24-
getEnvVar("JWT_ISSUER"),
25-
getEnvVar("SYFOTILGANGSKONTROLL_URL", "http://syfo-tilgangskontroll"),
26-
getEnvVar("SYFOVEILEDER_URL", "http://syfoveileder"),
27-
getEnvVar("DATABASE_NAME", "syfooversiktsrv"),
28-
getEnvVar("SYFOOVERSIKTSRV_DB_URL"),
29-
getEnvVar("MOUNT_PATH_VAULT"),
30-
getEnvVar("OVERSIKTHENDELSE_OPPFOLGINGSTILFELLE_TOPIC", "aapen-syfo-oversikthendelse-tilfelle-v1"),
31-
getEnvVar("KAFKA_BOOTSTRAP_SERVERS_URL"),
32-
getEnvVar("CLIENT_ID")
19+
getEnvVar("APPLICATION_PORT", "8080").toInt(),
20+
getEnvVar("APPLICATION_THREADS", "1").toInt(),
21+
getEnvVar("APPLICATION_NAME", "syfooversiktsrv"),
22+
getEnvVar("AADDISCOVERY_URL"),
23+
getEnvVar("JWKKEYS_URL", "https://login.microsoftonline.com/common/discovery/keys"),
24+
getEnvVar("JWT_ISSUER"),
25+
getEnvVar("SYFOTILGANGSKONTROLL_URL", "http://syfo-tilgangskontroll"),
26+
getEnvVar("SYFOVEILEDER_URL", "http://syfoveileder"),
27+
getEnvVar("DATABASE_NAME", "syfooversiktsrv"),
28+
getEnvVar("SYFOOVERSIKTSRV_DB_URL"),
29+
getEnvVar("MOUNT_PATH_VAULT"),
30+
getEnvVar("OVERSIKTHENDELSE_OPPFOLGINGSTILFELLE_TOPIC", "aapen-syfo-oversikthendelse-tilfelle-v1"),
31+
getEnvVar("KAFKA_BOOTSTRAP_SERVERS_URL"),
32+
getEnvVar("CLIENT_ID")
3333
)
3434
}
3535
}
3636

3737
val appIsRunningLocally: Boolean = System.getenv("NAIS_CLUSTER_NAME").isNullOrEmpty()
3838

3939
data class Environment(
40-
val applicationPort: Int,
41-
val applicationThreads: Int,
42-
val applicationName: String,
43-
val aadDiscoveryUrl: String,
44-
val jwkKeysUrl: String,
45-
val jwtIssuer: String,
46-
val syfotilgangskontrollUrl: String,
47-
val syfoveilederUrl: String,
48-
val databaseName: String,
49-
val syfooversiktsrvDBURL: String,
50-
val mountPathVault: String,
51-
val oversikthendelseOppfolgingstilfelleTopic: String,
52-
override val kafkaBootstrapServers: String,
53-
val clientid: String
40+
val applicationPort: Int,
41+
val applicationThreads: Int,
42+
val applicationName: String,
43+
val aadDiscoveryUrl: String,
44+
val jwkKeysUrl: String,
45+
val jwtIssuer: String,
46+
val syfotilgangskontrollUrl: String,
47+
val syfoveilederUrl: String,
48+
val databaseName: String,
49+
val syfooversiktsrvDBURL: String,
50+
val mountPathVault: String,
51+
val oversikthendelseOppfolgingstilfelleTopic: String,
52+
override val kafkaBootstrapServers: String,
53+
val clientid: String
5454
) : KafkaConfig
5555

5656
data class VaultSecrets(
57-
val serviceuserUsername: String,
58-
val serviceuserPassword: String
57+
val serviceuserUsername: String,
58+
val serviceuserPassword: String
5959
) : KafkaCredentials {
6060
override val kafkaUsername: String = serviceuserUsername
6161
override val kafkaPassword: String = serviceuserPassword
6262
}
6363

6464
fun getEnvVar(varName: String, defaultValue: String? = null) =
65-
System.getenv(varName) ?: defaultValue ?: throw RuntimeException("Missing required variable \"$varName\"")
65+
System.getenv(varName) ?: defaultValue ?: throw RuntimeException("Missing required variable \"$varName\"")
6666

6767
private fun firstExistingFile(vararg paths: String) = paths
68-
.map(::File)
69-
.first(File::exists)
68+
.map(::File)
69+
.first(File::exists)

src/main/kotlin/no/nav/syfo/SyfooversiktApplication.kt

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ import java.util.*
4040
import java.util.concurrent.Executors
4141
import java.util.concurrent.TimeUnit
4242

43-
44-
data class ApplicationState(var running: Boolean = true, var initialized: Boolean = false)
43+
data class ApplicationState(
44+
var running: Boolean = true,
45+
var initialized: Boolean = false
46+
)
4547

4648
val LOG: org.slf4j.Logger = LoggerFactory.getLogger("no.nav.syfo.SyfooversiktApplicationKt")
4749

@@ -85,10 +87,10 @@ val env: Environment = getEnvironment()
8587
fun Application.init() {
8688
isDev {
8789
database = DevDatabase(DbConfig(
88-
jdbcUrl = "jdbc:postgresql://localhost:5432/syfooversiktsrv_dev",
89-
databaseName = "syfooversiktsrv_dev",
90-
password = "password",
91-
username = "username")
90+
jdbcUrl = "jdbc:postgresql://localhost:5432/syfooversiktsrv_dev",
91+
databaseName = "syfooversiktsrv_dev",
92+
password = "password",
93+
username = "username")
9294
)
9395

9496
state.running = true
@@ -100,11 +102,11 @@ fun Application.init() {
100102
val newCredentials = vaultCredentialService.getNewCredentials(env.mountPathVault, env.databaseName, Role.USER)
101103

102104
database = ProdDatabase(DbConfig(
103-
jdbcUrl = env.syfooversiktsrvDBURL,
104-
username = newCredentials.username,
105-
password = newCredentials.password,
106-
databaseName = env.databaseName,
107-
runMigrationsOninit = false)) { prodDatabase ->
105+
jdbcUrl = env.syfooversiktsrvDBURL,
106+
username = newCredentials.username,
107+
password = newCredentials.password,
108+
databaseName = env.databaseName,
109+
runMigrationsOninit = false)) { prodDatabase ->
108110

109111
// i prod må vi kjøre flyway migrations med et eget sett brukernavn/passord
110112
vaultCredentialService.getNewCredentials(env.mountPathVault, env.databaseName, Role.ADMIN).let {
@@ -115,7 +117,6 @@ fun Application.init() {
115117
prodDatabase.updateCredentials(username = it.username, password = it.password)
116118
}
117119

118-
119120
state.running = true
120121
}
121122

@@ -143,13 +144,12 @@ fun Application.kafkaModule() {
143144
}
144145

145146
isProd {
146-
147147
val oversiktHendelseService = OversiktHendelseService(database)
148148
val oversikthendelstilfelleService = OversikthendelstilfelleService(database)
149149

150150
launch(backgroundTasksContext) {
151151
val vaultSecrets =
152-
objectMapper.readValue<VaultSecrets>(Paths.get("/var/run/secrets/nais.io/vault/credentials.json").toFile())
152+
objectMapper.readValue<VaultSecrets>(Paths.get("/var/run/secrets/nais.io/vault/credentials.json").toFile())
153153
setupKafka(vaultSecrets, oversiktHendelseService, oversikthendelstilfelleService)
154154
}
155155
}
@@ -178,18 +178,18 @@ fun Application.serverModule() {
178178
install(Authentication) {
179179
val wellKnown = getWellKnown(env.aadDiscoveryUrl)
180180
val jwkProvider = JwkProviderBuilder(URL(wellKnown.jwks_uri))
181-
.cached(10, 24, TimeUnit.HOURS)
182-
.rateLimited(10, 1, TimeUnit.MINUTES)
183-
.build()
181+
.cached(10, 24, TimeUnit.HOURS)
182+
.rateLimited(10, 1, TimeUnit.MINUTES)
183+
.build()
184184
jwt(name = "jwt") {
185185
verifier(jwkProvider, wellKnown.issuer)
186186
validate { credentials ->
187187
if (!credentials.payload.audience.contains(env.clientid)) {
188188
log.warn(
189-
"Auth: Unexpected audience for jwt {}, {}, {}",
190-
StructuredArguments.keyValue("issuer", credentials.payload.issuer),
191-
StructuredArguments.keyValue("audience", credentials.payload.audience),
192-
StructuredArguments.keyValue("expectedAudience", env.clientid)
189+
"Auth: Unexpected audience for jwt {}, {}, {}",
190+
StructuredArguments.keyValue("issuer", credentials.payload.issuer),
191+
StructuredArguments.keyValue("audience", credentials.payload.audience),
192+
StructuredArguments.keyValue("expectedAudience", env.clientid)
193193
)
194194
null
195195
} else {
@@ -215,7 +215,6 @@ fun Application.serverModule() {
215215
}
216216
}
217217

218-
219218
isProd {
220219
intercept(ApplicationCallPipeline.Call) {
221220
if (call.request.uri.contains(Regex("is_alive|is_ready|prometheus"))) {
@@ -248,14 +247,13 @@ fun Application.serverModule() {
248247

249248

250249
fun CoroutineScope.createListener(applicationState: ApplicationState, action: suspend CoroutineScope.() -> Unit): Job =
251-
launch {
252-
try {
253-
action()
254-
} finally {
255-
applicationState.running = false
256-
}
250+
launch {
251+
try {
252+
action()
253+
} finally {
254+
applicationState.running = false
257255
}
258-
256+
}
259257

260258
val Application.envKind get() = environment.config.property("ktor.environment").getString()
261259

src/main/kotlin/no/nav/syfo/api/Pod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import io.ktor.routing.get
88
import no.nav.syfo.ApplicationState
99

1010
fun Routing.registerPodApi(
11-
applicationState: ApplicationState
11+
applicationState: ApplicationState
1212
) {
1313
get("/is_alive") {
1414
if (applicationState.running) {

src/main/kotlin/no/nav/syfo/api/Prometheus.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.prometheus.client.exporter.common.TextFormat
1010
import io.prometheus.client.hotspot.DefaultExports
1111

1212
fun Routing.registerPrometheusApi(
13-
collectorRegistry: CollectorRegistry = CollectorRegistry.defaultRegistry
13+
collectorRegistry: CollectorRegistry = CollectorRegistry.defaultRegistry
1414
) {
1515
DefaultExports.initialize()
1616

src/main/kotlin/no/nav/syfo/auth/TokenAuth.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ fun getDecodedTokenFromCookie(cookies: RequestCookies): DecodedJWT? {
3535
}
3636

3737
data class VeilederTokenPayload(
38-
val navIdent: String,
39-
val navn: String,
40-
val epost: String
38+
val navIdent: String,
39+
val navn: String,
40+
val epost: String
4141
)
4242

4343
fun getVeilederTokenPayload(token: String): VeilederTokenPayload {
4444
val decodedJWT = JWT.decode(token)
4545
val navIdent: String = decodedJWT.claims["NAVident"]?.asString()
46-
?: throw Error("Missing NAVident in private claims")
46+
?: throw Error("Missing NAVident in private claims")
4747
val navn: String = decodedJWT.claims["name"]?.asString() ?: throw Error("Missing name in private claims")
4848
val email = decodedJWT.claims["unique_name"]?.asString() ?: throw Error("Missing unique_name in private claims")
4949
return VeilederTokenPayload(navIdent, navn, email)
@@ -56,10 +56,10 @@ fun isInvalidToken(cookies: RequestCookies): Boolean {
5656
if (decodedToken != null) {
5757
return if (!decodedToken.audience.contains(env.clientid)) {
5858
log.warn(
59-
"Auth: Unexpected audience for jwt {}, {}, {}",
60-
StructuredArguments.keyValue("issuer", decodedToken.issuer),
61-
StructuredArguments.keyValue("audience", decodedToken.audience),
62-
StructuredArguments.keyValue("expectedAudience", env.clientid)
59+
"Auth: Unexpected audience for jwt {}, {}, {}",
60+
StructuredArguments.keyValue("issuer", decodedToken.issuer),
61+
StructuredArguments.keyValue("audience", decodedToken.audience),
62+
StructuredArguments.keyValue("expectedAudience", env.clientid)
6363
)
6464
true
6565
} else {
@@ -74,9 +74,9 @@ fun isInvalidToken(cookies: RequestCookies): Boolean {
7474
fun verifyToken(token: String, env: Environment): DecodedJWT {
7575
val wellKnown = getWellKnown(env.aadDiscoveryUrl)
7676
val jwkProvider = JwkProviderBuilder(URL(wellKnown.jwks_uri))
77-
.cached(10, 24, TimeUnit.HOURS)
78-
.rateLimited(10, 1, TimeUnit.MINUTES)
79-
.build()
77+
.cached(10, 24, TimeUnit.HOURS)
78+
.rateLimited(10, 1, TimeUnit.MINUTES)
79+
.build()
8080

8181
val jwt = JWT.decode(token)
8282
val jwk = jwkProvider.get(jwt.keyId)
@@ -95,9 +95,9 @@ fun verifyToken(token: String, env: Environment): DecodedJWT {
9595
}
9696

9797
val verifier = JWT.require(algorithm) // signature
98-
.withIssuer(env.jwtIssuer) // iss
99-
.withAudience(env.clientid) // aud
100-
.build()
98+
.withIssuer(env.jwtIssuer) // iss
99+
.withAudience(env.clientid) // aud
100+
.build()
101101

102102
return verifier.verify(token)
103103
}

0 commit comments

Comments
 (0)