From 3d7ff8888fd47b8456fa2d0fa7d194754be98854 Mon Sep 17 00:00:00 2001 From: Ilnar Agliamzianov Date: Wed, 20 Nov 2024 15:06:51 +0200 Subject: [PATCH] Add methods to toggle web sockets in app services --- .../toolkit/lib/appservice/AppServiceAppBase.java | 10 ++++++++++ .../toolkit/lib/appservice/function/FunctionApp.java | 5 +++++ .../appservice/function/FunctionAppDeploymentSlot.java | 6 ++++++ .../azure/toolkit/lib/appservice/webapp/WebApp.java | 5 +++++ .../lib/appservice/webapp/WebAppDeploymentSlot.java | 6 ++++++ 5 files changed, 32 insertions(+) diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/AppServiceAppBase.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/AppServiceAppBase.java index 39ae2af39e..79394dbf10 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/AppServiceAppBase.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/AppServiceAppBase.java @@ -279,4 +279,14 @@ public IdentityConfiguration getIdentityConfiguration() { public void updateIdentityConfiguration(@Nonnull final IdentityConfiguration configuration) { throw new AzureToolkitRuntimeException("not supported"); } + + public void enableWebSockets() { + toggleWebSockets(true); + } + + public void disableWebSockets() { + toggleWebSockets(false); + } + + protected abstract void toggleWebSockets(boolean enabled); } diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionApp.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionApp.java index 21e8865839..b98c5cdeb2 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionApp.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionApp.java @@ -287,4 +287,9 @@ public void updateIdentityConfiguration(final @NotNull IdentityConfiguration con AzureMessager.getMessager().info(String.format("Updating identity configuration for function app %s...", this.getName())); update.apply(); } + + @Override + protected void toggleWebSockets(final boolean enabled) { + doModify(() -> Objects.requireNonNull(getRemote()).update().withWebSocketsEnabled(enabled).apply(), Status.UPDATING); + } } diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppDeploymentSlot.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppDeploymentSlot.java index dfc9929ef2..018e4d8915 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppDeploymentSlot.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppDeploymentSlot.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; public class FunctionAppDeploymentSlot extends FunctionAppBase { @@ -93,4 +94,9 @@ protected String getRemoteDebugPort() { } throw new AzureToolkitRuntimeException("Could not found free port to enable remote debug."); } + + @Override + protected void toggleWebSockets(final boolean enabled) { + doModify(() -> Objects.requireNonNull(getRemote()).update().withWebSocketsEnabled(enabled).apply(), Status.UPDATING); + } } diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebApp.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebApp.java index 6b6ad74bc5..e220f7e6de 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebApp.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebApp.java @@ -101,4 +101,9 @@ public void updateIdentityConfiguration(final @NotNull IdentityConfiguration con AzureMessager.getMessager().info(String.format("Updating identity configuration for web app %s...", this.getName())); update.apply(); } + + @Override + protected void toggleWebSockets(final boolean enabled) { + doModify(() -> Objects.requireNonNull(getRemote()).update().withWebSocketsEnabled(enabled).apply(), Status.UPDATING); + } } diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebAppDeploymentSlot.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebAppDeploymentSlot.java index 1b5f6050bb..fe01cb5d20 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebAppDeploymentSlot.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/webapp/WebAppDeploymentSlot.java @@ -12,6 +12,7 @@ import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; +import java.util.Objects; public class WebAppDeploymentSlot extends WebAppBase { @@ -35,4 +36,9 @@ protected WebAppDeploymentSlot(@Nonnull WebDeploymentSlotBasic remote, @Nonnull public List> getSubModules() { return Collections.emptyList(); } + + @Override + protected void toggleWebSockets(final boolean enabled) { + doModify(() -> Objects.requireNonNull(getRemote()).update().withWebSocketsEnabled(enabled).apply(), Status.UPDATING); + } }