diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java index f440219081..674a8ff490 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java @@ -16,6 +16,9 @@ package org.springframework.boot.cloud; +import java.util.Arrays; +import java.util.List; + import org.springframework.boot.context.properties.bind.Binder; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; @@ -138,14 +141,12 @@ public enum CloudPlatform { */ AZURE_APP_SERVICE { - private static final String WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME"; - - private static final String WEBSITES_ENABLE_APP_SERVICE_STORAGE = "WEBSITES_ENABLE_APP_SERVICE_STORAGE"; + private final List azureEnvVariables = Arrays.asList("WEBSITE_SITE_NAME", "WEBSITE_INSTANCE_ID", + "WEBSITE_RESOURCE_GROUP", "WEBSITE_SKU"); @Override public boolean isDetected(Environment environment) { - return environment.containsProperty(WEBSITE_SITE_NAME) - && environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE); + return this.azureEnvVariables.stream().allMatch(environment::containsProperty); } }; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java index 8172589016..884057e21f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java @@ -133,10 +133,12 @@ class CloudPlatformTests { } @Test - void getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService() { + void getActiveWhenHasAllAzureEnvVariablesShouldReturnAzureAppService() { Map envVars = new HashMap<>(); envVars.put("WEBSITE_SITE_NAME", "---"); - envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"); + envVars.put("WEBSITE_INSTANCE_ID", "1234"); + envVars.put("WEBSITE_RESOURCE_GROUP", "test"); + envVars.put("WEBSITE_SKU", "1234"); Environment environment = getEnvironmentWithEnvVariables(envVars); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE); @@ -144,16 +146,45 @@ class CloudPlatformTests { } @Test - void getActiveWhenHasWebsiteSiteNameAndNoWebsitesEnableAppServiceStorageShouldNotReturnAzureAppService() { - Environment environment = getEnvironmentWithEnvVariables(Collections.singletonMap("WEBSITE_SITE_NAME", "---")); + void getActiveWhenHasMissingWebsiteSiteNameShouldNotReturnAzureAppService() { + Map envVars = new HashMap<>(); + envVars.put("WEBSITE_INSTANCE_ID", "1234"); + envVars.put("WEBSITE_RESOURCE_GROUP", "test"); + envVars.put("WEBSITE_SKU", "1234"); + Environment environment = getEnvironmentWithEnvVariables(envVars); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isNull(); } @Test - void getActiveWhenHasWebsitesEnableAppServiceStorageAndNoWebsiteSiteNameShouldNotReturnAzureAppService() { - Environment environment = getEnvironmentWithEnvVariables( - Collections.singletonMap("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false")); + void getActiveWhenHasMissingWebsiteInstanceIdShouldNotReturnAzureAppService() { + Map envVars = new HashMap<>(); + envVars.put("WEBSITE_SITE_NAME", "---"); + envVars.put("WEBSITE_RESOURCE_GROUP", "test"); + envVars.put("WEBSITE_SKU", "1234"); + Environment environment = getEnvironmentWithEnvVariables(envVars); + CloudPlatform platform = CloudPlatform.getActive(environment); + assertThat(platform).isNull(); + } + + @Test + void getActiveWhenHasMissingWebsiteResourceGroupShouldNotReturnAzureAppService() { + Map envVars = new HashMap<>(); + envVars.put("WEBSITE_SITE_NAME", "---"); + envVars.put("WEBSITE_INSTANCE_ID", "1234"); + envVars.put("WEBSITE_SKU", "1234"); + Environment environment = getEnvironmentWithEnvVariables(envVars); + CloudPlatform platform = CloudPlatform.getActive(environment); + assertThat(platform).isNull(); + } + + @Test + void getActiveWhenHasMissingWebsiteSkuShouldNotReturnAzureAppService() { + Map envVars = new HashMap<>(); + envVars.put("WEBSITE_SITE_NAME", "---"); + envVars.put("WEBSITE_INSTANCE_ID", "1234"); + envVars.put("WEBSITE_RESOURCE_GROUP", "test"); + Environment environment = getEnvironmentWithEnvVariables(envVars); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isNull(); }