Skip to content

Commit 7a25359

Browse files
committed
rydder litt i config
1 parent 7515cde commit 7a25359

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/main/kotlin/no/nav/hjelpemidler/Application.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ fun main() {
6969
}
7070
install(Authentication) {
7171
token("oebsToken") {
72-
validate(requireNotNull(Configuration.application["OEBSTOKEN"]) {
73-
"OEBSTOKEN mangler"
74-
})
72+
validate(Configuration.oebsToken)
7573
}
7674
}
7775
val context = Context(rapidApp)

src/main/kotlin/no/nav/hjelpemidler/Configuration.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.natpryce.konfig.overriding
88
import com.natpryce.konfig.stringType
99

1010
internal object Configuration {
11-
1211
private val prodProperties = ConfigurationMap(
1312
Profile.PROD.entry(),
1413

@@ -37,7 +36,12 @@ internal object Configuration {
3736
Profile.LOCAL.entry(),
3837

3938
"HTTP_PORT" to "8085",
40-
"OEBSTOKEN" to "abc",
39+
40+
"NAIS_APP_NAME" to "hm-oebs-listener",
41+
"NAIS_CLUSTER_NAME" to "local",
42+
"NAIS_NAMESPACE" to "teamdigihot",
43+
44+
"OEBSTOKEN" to "token",
4145

4246
"kafka.aiven.consumer" to "hm-oebs-listener-v1",
4347
"kafka.aiven.topic" to "teamdigihot.hm-soknadsbehandling-v1",
@@ -48,7 +52,7 @@ internal object Configuration {
4852
"KAFKA_TRUSTSTORE_PATH" to "",
4953
"KAFKA_CREDSTORE_PASSWORD" to "",
5054

51-
"SENSU_URL" to "https://test",
55+
"SENSU_URL" to "https://test/sensu",
5256
"SLACK_HOOK" to "https://test/slack"
5357
)
5458

@@ -73,14 +77,16 @@ internal object Configuration {
7377
"HTTP_PORT" to get("HTTP_PORT"),
7478
) + System.getenv().filter { it.key.startsWith("NAIS_") }
7579

76-
val application: Map<String, String> = mapOf(
77-
"APP_PROFILE" to get("application.profile"),
78-
"SENSU_URL" to get("SENSU_URL"),
79-
"OEBSTOKEN" to get("OEBSTOKEN"),
80-
"SLACK_HOOK" to get("SLACK_HOOK"),
81-
) + System.getenv().filter { it.key.startsWith("NAIS_") }
80+
val application = get("NAIS_APP_NAME")
81+
val cluster = get("NAIS_CLUSTER_NAME")
82+
val namespace = get("NAIS_NAMESPACE")
8283

8384
val profile: Profile = get("application.profile").let { Profile.valueOf(it) }
85+
val sensuUrl = get("SENSU_URL")
86+
val oebsToken = get("OEBSTOKEN")
87+
val slackHook = get("SLACK_HOOK")
88+
val ntfyUrl = "https://ntfy.sh"
89+
val ntfyTopic = "teamdigihot.hm-oebs-listener"
8490

8591
enum class Profile {
8692
PROD, DEV, LOCAL;

src/main/kotlin/no/nav/hjelpemidler/Ntfy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Ntfy {
2525
}
2626

2727
fun publish(notification: Notification) = runBlocking(Dispatchers.IO) {
28-
val response = client.post("https://ntfy.sh") {
28+
val response = client.post(Configuration.ntfyUrl) {
2929
contentType(ContentType.Application.Json)
3030
setBody(notification)
3131
}
@@ -36,7 +36,7 @@ object Ntfy {
3636
}
3737

3838
data class Notification(
39-
val topic: String = "teamdigihot.hm-oebs-listener",
39+
val topic: String = Configuration.ntfyTopic,
4040
val title: String? = null,
4141
val message: String? = null,
4242
val priority: Priority = Priority.DEFAULT,

src/main/kotlin/no/nav/hjelpemidler/Slack.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object Slack {
2323
}
2424
}
2525

26-
fun post(url: String = Configuration.application["SLACK_HOOK"]!!, text: String, channel: String) =
26+
fun post(url: String = Configuration.slackHook, text: String, channel: String) =
2727
runBlocking(Dispatchers.IO) {
2828
val response = client
2929
.post(url) {

src/main/kotlin/no/nav/hjelpemidler/metrics/SensuMetrics.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package no.nav.hjelpemidler.metrics
22

3+
import mu.KotlinLogging
34
import no.nav.helse.rapids_rivers.MessageContext
45
import no.nav.hjelpemidler.Configuration
56
import org.influxdb.dto.Point
6-
import org.slf4j.LoggerFactory
77
import java.net.URI
88
import java.net.http.HttpClient
99
import java.net.http.HttpRequest
@@ -15,8 +15,8 @@ import java.util.concurrent.TimeUnit
1515
class SensuMetrics(messageContext: MessageContext) {
1616
private val kafkaMetrics = KafkaMetrics(messageContext)
1717

18-
private val log = LoggerFactory.getLogger(SensuMetrics::class.java)
19-
private val sensuURL = Configuration.application["SENSU_URL"] ?: "http://localhost/unconfigured"
18+
private val log = KotlinLogging.logger {}
19+
private val sensuUrl = Configuration.sensuUrl
2020
private val sensuName = "hm-oebs-listener-events"
2121

2222
private val httpClient = HttpClient.newBuilder()
@@ -101,7 +101,7 @@ class SensuMetrics(messageContext: MessageContext) {
101101
val body = HttpRequest.BodyPublishers.ofString(sensuEvent.json)
102102
val request = HttpRequest.newBuilder()
103103
.POST(body)
104-
.uri(URI.create(sensuURL))
104+
.uri(URI.create(sensuUrl))
105105
.setHeader("User-Agent", "Java 11 HttpClient Bot") // add request header
106106
.header("Content-Type", "application/json")
107107
.header("X-Correlation-ID", UUID.randomUUID().toString())
@@ -126,9 +126,9 @@ class SensuMetrics(messageContext: MessageContext) {
126126

127127
companion object {
128128
private val DEFAULT_TAGS: Map<String, String> = mapOf(
129-
"application" to (Configuration.application["NAIS_APP_NAME"] ?: "hm-oebs-listener"),
130-
"cluster" to (Configuration.application["NAIS_CLUSTER_NAME"] ?: "dev-fss"),
131-
"namespace" to (Configuration.application["NAIS_NAMESPACE"] ?: "teamdigihot")
129+
"application" to Configuration.application,
130+
"cluster" to Configuration.cluster,
131+
"namespace" to Configuration.namespace,
132132
)
133133

134134
private const val SOKNADER = "hm-oebs-listener"

0 commit comments

Comments
 (0)