remove unsafe-operator and nullable parameter

This commit is contained in:
az 2023-02-16 18:24:07 +01:00
parent 05e648abe6
commit eb04e84007
2 changed files with 14 additions and 11 deletions

View file

@ -17,7 +17,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
DefaultConfigFileRepository().assertExists(cli.configFileName)
val k3sConfigReprovision = k3sConfig.copy(reprovision = cli.reprovision || k3sConfig.reprovision)
val applicationFile = DefaultApplicationFileRepository(cli.applicationFileName).getFile()
val applicationFile = cli.applicationFileName?.let { DefaultApplicationFileRepository(cli.applicationFileName).getFile() }
provisionK3s(k3sConfigReprovision, grafanaConfigResolved, applicationFile)
} else {
provisionGrafana(cli.onlyModules, grafanaConfigResolved)
@ -30,7 +30,8 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
fun Prov.provisionK3s(
k3sConfig: K3sConfig,
grafanaConfigResolved: GrafanaAgentConfigResolved? = null,
applicationFile: ApplicationFile? = null) = task {
applicationFile: ApplicationFile? = null
) = task {
if (k3sConfig.reprovision) {
deprovisionK3sInfra()
@ -64,7 +65,8 @@ fun Prov.provisionK3s(
private fun Prov.provisionGrafana(
onlyModules: List<String>?,
grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
grafanaConfigResolved: GrafanaAgentConfigResolved?
) = task {
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) {

View file

@ -5,17 +5,18 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.check
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFile
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
import java.io.File
class DefaultApplicationFileRepository(val applicationFileName: ApplicationFileName?) : ApplicationFileRepository {
private fun assertExists(applicationFileName: String?) {
if (applicationFileName != null && !checkLocalFile(applicationFileName)) {
class DefaultApplicationFileRepository(val applicationFileName: ApplicationFileName) : ApplicationFileRepository {
private fun assertExists(applicationFileName: String) {
if (!checkLocalFile(applicationFileName)) {
throw RuntimeException("Application file not found. Please check if path is correct.")
}
}
override fun getFile(): ApplicationFile {
assertExists(applicationFileName!!.fullyQualifiedName())
assertExists(applicationFileName.fullyQualifiedName())
val applicationFileContents = getLocalFileContent(applicationFileName.fullyQualifiedName())
val applicationFile = ApplicationFile(applicationFileName, applicationFileContents)