-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skrev om NaisEnv fra enum til interface, endret navn til RuntimeEnvir…
…onment
- Loading branch information
Showing
16 changed files
with
124 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/NaisEnv.kt
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package no.nav.paw.config.env | ||
|
||
sealed interface RuntimeEnvironment | ||
|
||
data object Local : RuntimeEnvironment | ||
|
||
sealed interface Nais : RuntimeEnvironment { | ||
val clusterName: String | ||
val namespace: String | ||
val appName: String | ||
val appImage: String | ||
} | ||
sealed interface DevGcp : Nais | ||
|
||
sealed interface ProdGcp : Nais | ||
|
||
|
||
private class DevGCPImpl( | ||
override val clusterName: String, | ||
override val namespace: String, | ||
override val appName: String, | ||
override val appImage: String | ||
) : DevGcp | ||
|
||
private class ProdGCPImpl( | ||
override val clusterName: String, | ||
override val namespace: String, | ||
override val appName: String, | ||
override val appImage: String | ||
) : ProdGcp | ||
|
||
const val NAIS_PROD_CLUSER_NAME = "prod-gcp" | ||
const val NAIS_DEV_CLUSER_NAME = "dev-gcp" | ||
|
||
val currentRuntimeEnvironment: RuntimeEnvironment = currentRuntimeEnvironment() | ||
|
||
private fun currentRuntimeEnvironment(): RuntimeEnvironment { | ||
val namespace = { currentNamespace ?: error("NAIS_NAMESPACE is not set") } | ||
val appName = { currentAppName ?: error("NAIS_APP_NAME is not set") } | ||
val appImage = { currentAppImage ?: error("NAIS_APP_IMAGE is not set") } | ||
return when (val clusterName = System.getenv("NAIS_CLUSTER_NAME")) { | ||
NAIS_PROD_CLUSER_NAME -> ProdGCPImpl(clusterName, namespace(), appName(), appImage()) | ||
NAIS_DEV_CLUSER_NAME -> DevGCPImpl(clusterName, namespace(), appName(), appImage()) | ||
else -> Local | ||
} | ||
} | ||
|
||
private val currentAppImage: String? get() = System.getenv("NAIS_APP_IMAGE") // F.eks. europe-north1-docker.pkg.dev/nais-management-233d/paw/paw-microfrontend-toggler:24.06.27.57-1 | ||
|
||
private val currentAppName: String? get() = System.getenv("NAIS_APP_NAME") // F.eks. paw-microfrontend-toggler | ||
|
||
private val currentNamespace: String? get() = System.getenv("NAIS_NAMESPACE") |
21 changes: 21 additions & 0 deletions
21
lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironmentExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package no.nav.paw.config.env | ||
|
||
fun RuntimeEnvironment.namespaceOrDefaultForLocal(default: String = "local-namespace") = when (this) { | ||
is Nais -> namespace | ||
else -> default | ||
} | ||
|
||
fun RuntimeEnvironment.clusterNameOrDefaultForLocal(default: String = "local") = when (this) { | ||
is Nais -> clusterName | ||
else -> default | ||
} | ||
|
||
fun RuntimeEnvironment.appNameOrDefaultForLocal(default: String = "local-app") = when (this) { | ||
is Nais -> appName | ||
else -> default | ||
} | ||
|
||
fun RuntimeEnvironment.appImageOrDefaultForLocal(default: String = "local-image") = when (this) { | ||
is Nais -> appImage | ||
else -> default | ||
} |
Oops, something went wrong.