@@ -9,73 +9,79 @@ import com.natpryce.konfig.stringType
9
9
10
10
internal object Configuration {
11
11
12
- private fun config () = when (System .getenv(" NAIS_CLUSTER_NAME" ) ? : System .getProperty(" NAIS_CLUSTER_NAME" )) {
13
- " dev-gcp" -> ConfigurationProperties .systemProperties() overriding EnvironmentVariables overriding devProperties
14
- " prod-gcp" -> ConfigurationProperties .systemProperties() overriding EnvironmentVariables overriding prodProperties
15
- else -> {
16
- ConfigurationProperties .systemProperties() overriding EnvironmentVariables overriding localProperties
17
- }
18
- }
19
-
20
12
private val prodProperties = ConfigurationMap (
21
- mapOf (
22
- " HTTP_PORT" to " 8080" ,
13
+ Profile .PROD .pair(),
23
14
24
- " kafka.aiven.topic" to " teamdigihot.hm-soknadsbehandling-v1" ,
25
- " kafka.reset.policy" to " latest" ,
15
+ " HTTP_PORT" to " 8080" ,
26
16
27
- " application.profile" to " prod" ,
28
- " SENSU_URL" to " https://digihot-proxy.prod-fss-pub.nais.io/sensu" ,
29
- )
17
+ " kafka.aiven.topic" to " teamdigihot.hm-soknadsbehandling-v1" ,
18
+ " kafka.reset.policy" to " latest" ,
19
+
20
+ " SENSU_URL" to " https://digihot-proxy.prod-fss-pub.nais.io/sensu" ,
30
21
)
31
22
32
23
private val devProperties = ConfigurationMap (
33
- mapOf (
34
- " HTTP_PORT" to " 8080" ,
24
+ Profile .DEV .pair(),
25
+
26
+ " HTTP_PORT" to " 8080" ,
35
27
36
- " kafka.aiven.topic" to " teamdigihot.hm-soknadsbehandling-v1" ,
37
- " kafka.reset.policy" to " latest" ,
28
+ " kafka.aiven.topic" to " teamdigihot.hm-soknadsbehandling-v1" ,
29
+ " kafka.reset.policy" to " latest" ,
38
30
39
- " application.profile" to " dev" ,
40
- " SENSU_URL" to " https://digihot-proxy.dev-fss-pub.nais.io/sensu" ,
41
- )
31
+ " SENSU_URL" to " https://digihot-proxy.dev-fss-pub.nais.io/sensu" ,
42
32
)
43
33
44
34
private val localProperties = ConfigurationMap (
45
- mapOf (
46
- " HTTP_PORT " to " 8085 " ,
47
- " OEBSTOKEN " to " abc " ,
48
-
49
- " kafka.reset.policy " to " earliest " ,
50
- " KAFKA_TRUSTSTORE_PATH " to " " ,
51
- " KAFKA_CREDSTORE_PASSWORD " to " " ,
52
- " KAFKA_KEYSTORE_PATH " to " " ,
53
- " kafka.brokers " to " host.docker.internal:9092 " ,
54
- " kafka.aiven.topic " to " teamdigihot.hm-soknadsbehandling-v1 " ,
55
- " kafka.reset.policy " to " earliest " ,
56
- " application.profile " to " local " ,
57
- " SENSU_URL " to " https://test " ,
58
- " SLACK_HOOK " to " https://test/slack "
59
- )
35
+ Profile . LOCAL .pair(),
36
+
37
+ " HTTP_PORT " to " 8085 " ,
38
+ " OEBSTOKEN " to " abc " ,
39
+
40
+ " kafka.aiven.topic " to " teamdigihot.hm-soknadsbehandling-v1 " ,
41
+ " kafka.reset.policy " to " earliest " ,
42
+ " kafka.brokers " to " host.docker.internal:9092 " ,
43
+ " kafka.reset.policy " to " earliest " ,
44
+ " KAFKA_KEYSTORE_PATH " to " " ,
45
+ " KAFKA_TRUSTSTORE_PATH " to " " ,
46
+ " KAFKA_CREDSTORE_PASSWORD " to " " ,
47
+
48
+ " SENSU_URL " to " https://test" ,
49
+ " SLACK_HOOK " to " https://test/slack "
60
50
)
61
51
52
+ private val config = when (System .getenv(" NAIS_CLUSTER_NAME" ) ? : System .getProperty(" NAIS_CLUSTER_NAME" )) {
53
+ " dev-gcp" -> ConfigurationProperties .systemProperties() overriding EnvironmentVariables () overriding devProperties
54
+ " prod-gcp" -> ConfigurationProperties .systemProperties() overriding EnvironmentVariables () overriding prodProperties
55
+ else -> ConfigurationProperties .systemProperties() overriding EnvironmentVariables () overriding localProperties
56
+ }
57
+
58
+ operator fun get (name : String ): String = config[Key (name, stringType)]
59
+
62
60
val rapidConfig: Map <String , String > = mapOf (
63
61
" RAPID_KAFKA_CLUSTER" to " gcp" ,
64
62
" RAPID_APP_NAME" to " hm-oebs-listener" ,
65
- " KAFKA_BROKERS" to config()[ Key ( " kafka.brokers" , stringType)] ,
63
+ " KAFKA_BROKERS" to get( " kafka.brokers" ) ,
66
64
" KAFKA_CONSUMER_GROUP_ID" to " hm-oebs-listener-v1" ,
67
- " KAFKA_RAPID_TOPIC" to config()[ Key ( " kafka.aiven.topic" , stringType)] ,
68
- " KAFKA_RESET_POLICY" to config()[ Key ( " kafka.reset.policy" , stringType)] ,
69
- " KAFKA_TRUSTSTORE_PATH " to config()[ Key ( " KAFKA_TRUSTSTORE_PATH " , stringType)] ,
70
- " KAFKA_KEYSTORE_PATH " to config()[ Key ( " KAFKA_KEYSTORE_PATH " , stringType)] ,
71
- " KAFKA_CREDSTORE_PASSWORD" to config()[ Key ( " KAFKA_CREDSTORE_PASSWORD" , stringType)] ,
72
- " HTTP_PORT" to config()[ Key ( " HTTP_PORT" , stringType)] ,
65
+ " KAFKA_RAPID_TOPIC" to get( " kafka.aiven.topic" ) ,
66
+ " KAFKA_RESET_POLICY" to get( " kafka.reset.policy" ) ,
67
+ " KAFKA_KEYSTORE_PATH " to get( " KAFKA_KEYSTORE_PATH " ) ,
68
+ " KAFKA_TRUSTSTORE_PATH " to get( " KAFKA_TRUSTSTORE_PATH " ) ,
69
+ " KAFKA_CREDSTORE_PASSWORD" to get( " KAFKA_CREDSTORE_PASSWORD" ) ,
70
+ " HTTP_PORT" to get( " HTTP_PORT" ) ,
73
71
) + System .getenv().filter { it.key.startsWith(" NAIS_" ) }
74
72
75
73
val application: Map <String , String > = mapOf (
76
- " APP_PROFILE" to config()[ Key ( " application.profile" , stringType)] ,
77
- " SENSU_URL" to config()[ Key ( " SENSU_URL" , stringType)] ,
78
- " OEBSTOKEN" to config()[ Key ( " OEBSTOKEN" , stringType)] ,
79
- " SLACK_HOOK" to config()[ Key ( " SLACK_HOOK" , stringType)] ,
74
+ " APP_PROFILE" to get( " application.profile" ) ,
75
+ " SENSU_URL" to get( " SENSU_URL" ) ,
76
+ " OEBSTOKEN" to get( " OEBSTOKEN" ) ,
77
+ " SLACK_HOOK" to get( " SLACK_HOOK" ) ,
80
78
) + System .getenv().filter { it.key.startsWith(" NAIS_" ) }
79
+
80
+ val profile: Profile = get(" application.profile" ).let { Profile .valueOf(it) }
81
+
82
+ enum class Profile {
83
+ PROD , DEV , LOCAL ;
84
+
85
+ fun pair (): Pair <String , String > = " application.profile" to name
86
+ }
81
87
}
0 commit comments