From 55f63b28f090fbefec6d9cb5b21ef43413b3f92f Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Tue, 30 Mar 2021 13:01:32 +0200 Subject: [PATCH 1/7] Add Azure platform support --- .../springframework/boot/cloud/CloudPlatform.java | 12 ++++++++++++ .../boot/cloud/CloudPlatformTests.java | 7 +++++++ 2 files changed, 19 insertions(+) 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 c4f61b2a87cd..afdfc4dff13f 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 @@ -45,6 +45,18 @@ public boolean isDetected(Environment environment) { }, + /** + * Azure App Service platform. + */ + AZURE { + + @Override + public boolean isDetected(Environment environment) { + return environment.containsProperty("WEBSITE_SITE_NAME"); + } + + }, + /** * Cloud Foundry platform. */ 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 36bc7903f385..2926cc9a81f3 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 @@ -50,7 +50,14 @@ void getActiveWhenNotInCloudShouldReturnNull() { Environment environment = new MockEnvironment(); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isNull(); + } + @Test + void getActiveWhenHasDynoShouldReturnAzure() { + Environment environment = new MockEnvironment().withProperty("WEBSITE_SITE_NAME", "---"); + CloudPlatform platform = CloudPlatform.getActive(environment); + assertThat(platform).isEqualTo(CloudPlatform.AZURE); + assertThat(platform.isActive(environment)).isTrue(); } @Test From aa684d4d59de4bc2ec165baefa7f4fad719cf39b Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 31 Mar 2021 09:08:01 +0200 Subject: [PATCH 2/7] Correct name of the test --- .../java/org/springframework/boot/cloud/CloudPlatformTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2926cc9a81f3..aab623808995 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 @@ -53,7 +53,7 @@ void getActiveWhenNotInCloudShouldReturnNull() { } @Test - void getActiveWhenHasDynoShouldReturnAzure() { + void getActiveWhenHasWebsiteSiteNameShouldReturnAzureAppService() { Environment environment = new MockEnvironment().withProperty("WEBSITE_SITE_NAME", "---"); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isEqualTo(CloudPlatform.AZURE); From 3d6c992341cd6415fc3839078269c1210b79ef9b Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 31 Mar 2021 09:08:24 +0200 Subject: [PATCH 3/7] Refactor "AZURE" to "AZURE_APP_SERVICE" --- .../main/java/org/springframework/boot/cloud/CloudPlatform.java | 2 +- .../java/org/springframework/boot/cloud/CloudPlatformTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 afdfc4dff13f..99414e0f34e6 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 @@ -48,7 +48,7 @@ public boolean isDetected(Environment environment) { /** * Azure App Service platform. */ - AZURE { + AZURE_APP_SERVICE { @Override public boolean isDetected(Environment environment) { 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 aab623808995..bd5c44d88569 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 @@ -56,7 +56,7 @@ void getActiveWhenNotInCloudShouldReturnNull() { void getActiveWhenHasWebsiteSiteNameShouldReturnAzureAppService() { Environment environment = new MockEnvironment().withProperty("WEBSITE_SITE_NAME", "---"); CloudPlatform platform = CloudPlatform.getActive(environment); - assertThat(platform).isEqualTo(CloudPlatform.AZURE); + assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE); assertThat(platform.isActive(environment)).isTrue(); } From 85e37cad75014172bdacda306f361e194bfec696 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 31 Mar 2021 17:00:56 +0200 Subject: [PATCH 4/7] test a second environment variable for Azure App Service --- .../springframework/boot/cloud/CloudPlatform.java | 13 +++++++------ .../boot/cloud/CloudPlatformTests.java | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) 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 99414e0f34e6..819246fe4a9e 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 @@ -17,11 +17,7 @@ package org.springframework.boot.cloud; import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.EnumerablePropertySource; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertySource; -import org.springframework.core.env.StandardEnvironment; +import org.springframework.core.env.*; /** * Simple detection for well known cloud platforms. Detection can be forced using the @@ -50,9 +46,14 @@ public boolean isDetected(Environment environment) { */ 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"; + @Override public boolean isDetected(Environment environment) { - return environment.containsProperty("WEBSITE_SITE_NAME"); + return environment.containsProperty(WEBSITE_SITE_NAME) && + environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE); } }, 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 bd5c44d88569..3b53d5a03c82 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 @@ -54,7 +54,10 @@ void getActiveWhenNotInCloudShouldReturnNull() { @Test void getActiveWhenHasWebsiteSiteNameShouldReturnAzureAppService() { - Environment environment = new MockEnvironment().withProperty("WEBSITE_SITE_NAME", "---"); + Map envVars = new HashMap<>(); + envVars.put("WEBSITE_SITE_NAME", "---"); + envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"); + Environment environment = getEnvironmentWithEnvVariables(envVars); CloudPlatform platform = CloudPlatform.getActive(environment); assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE); assertThat(platform.isActive(environment)).isTrue(); From 26e59364d1ef013a4bd9dfd5485673d944f83f79 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 31 Mar 2021 17:35:47 +0200 Subject: [PATCH 5/7] Fix formatting --- .../java/org/springframework/boot/cloud/CloudPlatform.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 819246fe4a9e..763f7a83c476 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 @@ -52,8 +52,8 @@ public boolean isDetected(Environment environment) { @Override public boolean isDetected(Environment environment) { - return environment.containsProperty(WEBSITE_SITE_NAME) && - environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE); + return environment.containsProperty(WEBSITE_SITE_NAME) + && environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE); } }, From ed3b04bc736ac5a4595ac223982fec6cf1810c81 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Thu, 1 Apr 2021 22:20:12 +0200 Subject: [PATCH 6/7] Revert imports following @wilkinsona review --- .../java/org/springframework/boot/cloud/CloudPlatform.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 763f7a83c476..bae1ed64ab84 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 @@ -17,7 +17,11 @@ package org.springframework.boot.cloud; import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.core.env.*; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertySource; +import org.springframework.core.env.StandardEnvironment; /** * Simple detection for well known cloud platforms. Detection can be forced using the From b0a4009663aeb6222b659c169c3d33aa37382fed Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Thu, 1 Apr 2021 22:20:34 +0200 Subject: [PATCH 7/7] Add unit tests following @wilkinsona review --- .../boot/cloud/CloudPlatformTests.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 3b53d5a03c82..1d50f3082ca4 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 @@ -53,7 +53,7 @@ void getActiveWhenNotInCloudShouldReturnNull() { } @Test - void getActiveWhenHasWebsiteSiteNameShouldReturnAzureAppService() { + void getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService() { Map envVars = new HashMap<>(); envVars.put("WEBSITE_SITE_NAME", "---"); envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"); @@ -63,6 +63,22 @@ void getActiveWhenHasWebsiteSiteNameShouldReturnAzureAppService() { assertThat(platform.isActive(environment)).isTrue(); } + @Test + void getActiveWhenHasWebsiteSiteNameShouldReturnNull() { + Environment environment = getEnvironmentWithEnvVariables( + Collections.singletonMap("WEBSITE_SITE_NAME", "---")); + CloudPlatform platform = CloudPlatform.getActive(environment); + assertThat(platform).isNull(); + } + + @Test + void getActiveWhenHasWebsitesEnableAppServiceStorageShouldReturnNull() { + Environment environment = getEnvironmentWithEnvVariables( + Collections.singletonMap("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "---")); + CloudPlatform platform = CloudPlatform.getActive(environment); + assertThat(platform).isNull(); + } + @Test void getActiveWhenHasVcapApplicationShouldReturnCloudFoundry() { Environment environment = new MockEnvironment().withProperty("VCAP_APPLICATION", "---");