Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping spring legacy props #23166

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,14 @@
<Field name="azureProperties"/>
<Bug pattern="URF_UNREAD_FIELD"/>
</Match>

<!-- Field is initialized in postProcessEnvironment function -->
<Match>
<Class name="com.azure.spring.autoconfigure.unity.AbstractLegacyPropertyEnvironmentPostProcessor"/>
<Field name="environment"/>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
</Match>

<!-- The transient fields are not used if deserialization happens. -->
<Match>
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount"/>
Expand Down
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
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.loadProperties;

/**
* 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;
protected ConfigurableEnvironment environment;
static {
// Load the map of each service's legacy properties and associated current properties from classpath.
springPropertyMap = loadProperties("legacy-property-mapping.properties");
}

@Override
public abstract int getOrder();

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
this.environment = environment;
Properties legacyToCurrentMap = buildLegacyToCurrentPropertyMap();
Properties properties = convertLegacyPropertyToCurrent(legacyToCurrentMap);
setConvertedPropertyToEnvironment(properties);
}

protected Properties buildLegacyToCurrentPropertyMap() {
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 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 convertLegacyPropertyToCurrent(Properties legacyToCurrentMap);

/**
* Add the mapped current properties to application environment,
* of which the precedence varies in different processors.
*
* @param properties The converted current properties to be configured.
*/
protected abstract void setConvertedPropertyToEnvironment(Properties properties);
}

This file was deleted.

Loading