Skip to content

Commit 4d510d3

Browse files
committed
Merge pull request #25829 from jdubois
* gh-25829: Polish "Add detection of Azure App Service to CloudPlatform" Add detection of Azure App Service to CloudPlatform Closes gh-25829
2 parents 660dc5f + 4d31182 commit 4d510d3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -130,6 +130,23 @@ private boolean isAutoDetected(EnumerablePropertySource<?> environmentPropertySo
130130
return false;
131131
}
132132

133+
},
134+
135+
/**
136+
* Azure App Service platform.
137+
*/
138+
AZURE_APP_SERVICE {
139+
140+
private static final String WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME";
141+
142+
private static final String WEBSITES_ENABLE_APP_SERVICE_STORAGE = "WEBSITES_ENABLE_APP_SERVICE_STORAGE";
143+
144+
@Override
145+
public boolean isDetected(Environment environment) {
146+
return environment.containsProperty(WEBSITE_SITE_NAME)
147+
&& environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE);
148+
}
149+
133150
};
134151

135152
private static final String PROPERTY_NAME = "spring.main.cloud-platform";

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,6 @@ void getActiveWhenNotInCloudShouldReturnNull() {
5050
Environment environment = new MockEnvironment();
5151
CloudPlatform platform = CloudPlatform.getActive(environment);
5252
assertThat(platform).isNull();
53-
5453
}
5554

5655
@Test
@@ -131,6 +130,32 @@ void getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes() {
131130
assertThat(platform).isNull();
132131
}
133132

133+
@Test
134+
void getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService() {
135+
Map<String, Object> envVars = new HashMap<>();
136+
envVars.put("WEBSITE_SITE_NAME", "---");
137+
envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false");
138+
Environment environment = getEnvironmentWithEnvVariables(envVars);
139+
CloudPlatform platform = CloudPlatform.getActive(environment);
140+
assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE);
141+
assertThat(platform.isActive(environment)).isTrue();
142+
}
143+
144+
@Test
145+
void getActiveWhenHasWebsiteSiteNameAndNoWebsitesEnableAppServiceStorageShouldNotReturnAzureAppService() {
146+
Environment environment = getEnvironmentWithEnvVariables(Collections.singletonMap("WEBSITE_SITE_NAME", "---"));
147+
CloudPlatform platform = CloudPlatform.getActive(environment);
148+
assertThat(platform).isNull();
149+
}
150+
151+
@Test
152+
void getActiveWhenHasWebsitesEnableAppServiceStorageAndNoWebsiteNameShouldNotReturnAzureAppService() {
153+
Environment environment = getEnvironmentWithEnvVariables(
154+
Collections.singletonMap("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "---"));
155+
CloudPlatform platform = CloudPlatform.getActive(environment);
156+
assertThat(platform).isNull();
157+
}
158+
134159
@Test
135160
void getActiveWhenHasEnforcedCloudPlatform() {
136161
Environment environment = getEnvironmentWithEnvVariables(

0 commit comments

Comments
 (0)