Skip to content

Commit

Permalink
Rework local.settings.json deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Jan 13, 2025
1 parent 01af67c commit cc3350a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.jetbrains.rider.projectView.solution
import com.microsoft.azure.toolkit.intellij.legacy.function.coreTools.FunctionsVersionMsBuildService
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionLocalSettingsService
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionWorkerRuntime
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.getWorkerRuntime
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -67,7 +68,7 @@ suspend fun PublishableProjectModel.getFunctionStack(
val functionLocalSettings = FunctionLocalSettingsService
.getInstance(project)
.getFunctionLocalSettings(this)
val workerRuntime = functionLocalSettings?.values?.workerRuntime ?: FunctionWorkerRuntime.DOTNET_ISOLATED
val workerRuntime = functionLocalSettings?.getWorkerRuntime() ?: FunctionWorkerRuntime.DOTNET_ISOLATED
val azureFunctionVersion = withContext(Dispatchers.EDT) {
FunctionsVersionMsBuildService
.getInstance(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@ import kotlinx.serialization.SerialName
@Serializable
data class FunctionLocalSettings(
@SerialName("IsEncrypted") val isEncrypted: Boolean?,
@SerialName("Values") val values: FunctionValuesModel?,
@SerialName("Values") val values: Map<String, String>?,
@SerialName("Host") val host: FunctionHostModel?,
@SerialName("ConnectionStrings") val connectionStrings: Map<String, String>?
)

@Serializable
data class FunctionValuesModel(
@SerialName("FUNCTIONS_WORKER_RUNTIME") val workerRuntime: FunctionWorkerRuntime?,
@SerialName("AzureWebJobsStorage") val webJobsStorage: String?,
@SerialName("AzureWebJobsDashboard") val webJobsDashboard: String?,
@SerialName("AzureWebJobs.HttpExample.Disabled") val webJobsHttpExampleDisabled: Boolean?,
@SerialName("MyBindingConnection") val bindingConnection: String?
)

@Serializable
Expand All @@ -31,48 +21,22 @@ data class FunctionHostModel(
@SerialName("CORSCredentials") val corsCredentials: Boolean?
)

@Serializable
fun FunctionLocalSettings.getWorkerRuntime(): FunctionWorkerRuntime? {
val runtime = values?.get("FUNCTIONS_WORKER_RUNTIME") ?: return null
return when {
runtime.equals(FunctionWorkerRuntime.DOTNET_ISOLATED.value(), true) -> FunctionWorkerRuntime.DOTNET_ISOLATED
runtime.equals(FunctionWorkerRuntime.DOTNET.value(), true) -> FunctionWorkerRuntime.DOTNET
else -> null
}
}

enum class FunctionWorkerRuntime {
@SerialName("DOTNET") DOTNET {
DOTNET {
override fun value() = "DOTNET"
},
@SerialName("DOTNET-ISOLATED") DOTNET_ISOLATED {
DOTNET_ISOLATED {
override fun value() = "DOTNET-ISOLATED"
};

abstract fun value(): String
}
//
//data class FunctionLocalSettings(
// @SerializedName("IsEncrypted") val isEncrypted: Boolean?,
// @SerializedName("Values") val values: FunctionValuesModel?,
// @SerializedName("Host") val host: FunctionHostModel?,
// @SerializedName("ConnectionStrings") val connectionStrings: Map<String, String>?
//)
//
//data class FunctionValuesModel(
// @SerializedName("FUNCTIONS_WORKER_RUNTIME") val workerRuntime: FunctionWorkerRuntime?,
// @SerializedName("AzureWebJobsStorage") val webJobsStorage: String?,
// @SerializedName("AzureWebJobsDashboard") val webJobsDashboard: String?,
// @SerializedName("AzureWebJobs.HttpExample.Disabled") val webJobsHttpExampleDisabled: Boolean?,
// @SerializedName("MyBindingConnection") val bindingConnection: String?
//)
//
//data class FunctionHostModel(
// @SerializedName("LocalHttpPort") val localHttpPort: Int?,
// @SerializedName("CORS") val cors: String?,
// @SerializedName("CORSCredentials") val corsCredentials: Boolean?
//)
//
//enum class FunctionWorkerRuntime {
// @SerializedName(value = "DOTNET", alternate = ["dotnet"])
// DOTNET {
// override fun value() = "DOTNET"
// },
// @SerializedName(value = "DOTNET-ISOLATED", alternate = ["dotnet-isolated"])
// DOTNET_ISOLATED {
// override fun value() = "DOTNET-ISOLATED"
// };
//
// abstract fun value(): String
//}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.microsoft.azure.toolkit.intellij.legacy.function.launchProfiles.getWo
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionLocalSettings
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionLocalSettingsService
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionWorkerRuntime
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.getWorkerRuntime
import kotlinx.coroutines.Dispatchers
import java.io.File

Expand Down Expand Up @@ -337,7 +338,7 @@ class FunctionRunConfigurationViewModel(
readLocalSettingsForProject(runnableProject)

// Disable "Use external console" for Isolated worker
val workerRuntime = functionLocalSettings?.values?.workerRuntime ?: FunctionWorkerRuntime.DOTNET_ISOLATED
val workerRuntime = functionLocalSettings?.getWorkerRuntime() ?: FunctionWorkerRuntime.DOTNET_ISOLATED
val workerRuntimeSupportsExternalConsole = workerRuntime != FunctionWorkerRuntime.DOTNET_ISOLATED
useExternalConsoleEditor.isVisible.set(workerRuntimeSupportsExternalConsole)
useExternalConsoleEditor.isSelected.set(workerRuntimeSupportsExternalConsole && useExternalConsole)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.Functi
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionLocalSettingsService
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.FunctionWorkerRuntime
import com.microsoft.azure.toolkit.intellij.legacy.function.launchProfiles.getProjectLaunchProfileByName
import com.microsoft.azure.toolkit.intellij.legacy.function.localsettings.getWorkerRuntime
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
Expand Down Expand Up @@ -84,11 +85,9 @@ class FunctionRunExecutorFactory(
.getInstance(project)
.getFunctionLocalSettings(projectFilePath)
}
val workerRuntime = if (functionLocalSettings?.values?.workerRuntime == null) {
getFunctionWorkerRuntimeFromBackendOrDefault(projectFilePath)
} else {
functionLocalSettings.values.workerRuntime
}

val workerRuntime = functionLocalSettings?.getWorkerRuntime()
?: getFunctionWorkerRuntimeFromBackendOrDefault(projectFilePath)
LOG.debug { "Worker runtime: $workerRuntime" }

val functionsRuntimeVersion = calculateFunctionsRuntimeVersion(msBuildVersionProperty, workerRuntime)
Expand Down

0 comments on commit cc3350a

Please sign in to comment.