forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapping spring legacy props (Azure#23166)
* use file for property mapping * add environmentpostprocessor after kv * map multiple key vault use case
- Loading branch information
Showing
20 changed files
with
819 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...g/azure-spring-boot-starter-keyvault-secrets/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
org.springframework.boot.env.EnvironmentPostProcessor=com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessor | ||
org.springframework.boot.env.EnvironmentPostProcessor=com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessor,\ | ||
com.azure.spring.keyvault.PostLegacyPropertyEnvironmentPostProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../com/azure/spring/autoconfigure/unity/AbstractLegacyPropertyEnvironmentPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.autoconfigure.unity; | ||
|
||
import com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessor; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.env.EnvironmentPostProcessor; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
import java.util.Properties; | ||
|
||
import static com.azure.spring.utils.PropertyLoader.loadPropertiesFromClassPath; | ||
|
||
/** | ||
* Abstract class to convert legacy properties to the current when only legacy properties are configured, | ||
* need to be executed before and after {@link KeyVaultEnvironmentPostProcessor} | ||
* if {@link KeyVaultEnvironmentPostProcessor} is enabled. | ||
*/ | ||
public abstract class AbstractLegacyPropertyEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { | ||
|
||
private static Properties springPropertyMap; | ||
static { | ||
// Load the map of each service's legacy properties and associated current properties from classpath. | ||
springPropertyMap = loadPropertiesFromClassPath("legacy-property-mapping.properties"); | ||
} | ||
|
||
@Override | ||
public abstract int getOrder(); | ||
|
||
@Override | ||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | ||
Properties legacyToCurrentMap = buildLegacyToCurrentPropertyMap(environment); | ||
Properties convertedProperties = convertLegacyToCurrent(environment, legacyToCurrentMap); | ||
setConvertedPropertyToEnvironment(environment, convertedProperties); | ||
} | ||
|
||
protected Properties buildLegacyToCurrentPropertyMap(ConfigurableEnvironment environment) { | ||
Properties legacyToCurrentMap = new Properties(); | ||
legacyToCurrentMap.putAll(springPropertyMap); | ||
return legacyToCurrentMap; | ||
} | ||
|
||
/** | ||
* Convert legacy properties to the current and create new {@link Properties} to store mapped current properties | ||
* if only legacy properties are configured. | ||
* | ||
* @param environment The application environment to load property from. | ||
* @param legacyToCurrentMap A {@link Properties} contains a map of all legacy properties and associated current ones. | ||
* @return A {@link Properties} to store mapped current properties | ||
*/ | ||
protected abstract Properties convertLegacyToCurrent(ConfigurableEnvironment environment, Properties legacyToCurrentMap); | ||
|
||
/** | ||
* Add the mapped current properties to application environment, | ||
* of which the precedence varies in different processors. | ||
* | ||
* @param environment The application environment to load property from. | ||
* @param properties The converted current properties to be configured. | ||
*/ | ||
protected abstract void setConvertedPropertyToEnvironment(ConfigurableEnvironment environment, Properties properties); | ||
} |
166 changes: 0 additions & 166 deletions
166
...main/java/com/azure/spring/autoconfigure/unity/AzurePropertyEnvironmentPostProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.