Skip to content

Commit 98a1017

Browse files
jduboiswilkinsona
authored andcommitted
Add detection of Azure App Service to CloudPlatform
See gh-25829
1 parent 660dc5f commit 98a1017

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ public boolean isDetected(Environment environment) {
4545

4646
},
4747

48+
/**
49+
* Azure App Service platform.
50+
*/
51+
AZURE_APP_SERVICE {
52+
53+
private static final String WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME";
54+
55+
private static final String WEBSITES_ENABLE_APP_SERVICE_STORAGE = "WEBSITES_ENABLE_APP_SERVICE_STORAGE";
56+
57+
@Override
58+
public boolean isDetected(Environment environment) {
59+
return environment.containsProperty(WEBSITE_SITE_NAME)
60+
&& environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE);
61+
}
62+
63+
},
64+
4865
/**
4966
* Cloud Foundry platform.
5067
*/

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,33 @@ void getActiveWhenNotInCloudShouldReturnNull() {
5050
Environment environment = new MockEnvironment();
5151
CloudPlatform platform = CloudPlatform.getActive(environment);
5252
assertThat(platform).isNull();
53+
}
54+
55+
@Test
56+
void getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService() {
57+
Map<String, Object> envVars = new HashMap<>();
58+
envVars.put("WEBSITE_SITE_NAME", "---");
59+
envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false");
60+
Environment environment = getEnvironmentWithEnvVariables(envVars);
61+
CloudPlatform platform = CloudPlatform.getActive(environment);
62+
assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE);
63+
assertThat(platform.isActive(environment)).isTrue();
64+
}
65+
66+
@Test
67+
void getActiveWhenHasWebsiteSiteNameShouldReturnNull() {
68+
Environment environment = getEnvironmentWithEnvVariables(
69+
Collections.singletonMap("WEBSITE_SITE_NAME", "---"));
70+
CloudPlatform platform = CloudPlatform.getActive(environment);
71+
assertThat(platform).isNull();
72+
}
5373

74+
@Test
75+
void getActiveWhenHasWebsitesEnableAppServiceStorageShouldReturnNull() {
76+
Environment environment = getEnvironmentWithEnvVariables(
77+
Collections.singletonMap("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "---"));
78+
CloudPlatform platform = CloudPlatform.getActive(environment);
79+
assertThat(platform).isNull();
5480
}
5581

5682
@Test

0 commit comments

Comments
 (0)