Skip to content

Commit

Permalink
fix issues in kv envpostprocessor (#26794)
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna authored Feb 11, 2022
1 parent ea49c19 commit c890bd8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
package com.azure.spring.cloud.autoconfigure;

import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.core.aware.ClientAware;
import com.azure.spring.core.aware.ProxyAware;
import com.azure.spring.core.aware.RetryAware;
import com.azure.spring.cloud.autoconfigure.properties.utils.AzureGlobalPropertiesUtils;
import com.azure.spring.core.properties.AzureProperties;
import com.azure.spring.core.util.AzurePropertiesUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -41,29 +37,6 @@ public AzureServiceConfigurationBase(AzureGlobalProperties azureProperties) {
* @return The Azure Service's properties.
*/
protected <T extends AzureProperties> T loadProperties(AzureGlobalProperties source, T target) {
AzurePropertiesUtils.copyAzureCommonProperties(source, target);

if (target.getClient() instanceof ClientAware.HttpClient) {
BeanUtils.copyProperties(source.getClient().getHttp(), target.getClient());

ClientAware.HttpClient targetClient = (ClientAware.HttpClient) target.getClient();
BeanUtils.copyProperties(source.getClient().getHttp().getLogging(), targetClient.getLogging());
targetClient.getLogging().getAllowedHeaderNames().addAll(source.getClient().getHttp().getLogging().getAllowedHeaderNames());
targetClient.getLogging().getAllowedQueryParamNames().addAll(source.getClient().getHttp().getLogging().getAllowedQueryParamNames());
}

if (target.getClient() instanceof ClientAware.AmqpClient) {
BeanUtils.copyProperties(source.getClient().getAmqp(), target.getClient());
}

if (target.getProxy() instanceof ProxyAware.HttpProxy) {
BeanUtils.copyProperties(source.getProxy().getHttp(), target.getProxy());
}

if (target.getRetry() instanceof RetryAware.HttpRetry) {
BeanUtils.copyProperties(source.getRetry().getHttp(), target.getRetry());
}

return target;
return AzureGlobalPropertiesUtils.loadProperties(source, target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultPropertySourceProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.properties.AzureKeyVaultSecretProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.cloud.autoconfigure.properties.utils.AzureGlobalPropertiesUtils;
import com.azure.spring.core.util.AzurePropertiesUtils;
import com.azure.spring.service.implementation.keyvault.secrets.SecretClientBuilderFactory;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -177,8 +178,7 @@ private AzureKeyVaultSecretProperties loadProperties(Binder binder) {
.orElseGet(AzureGlobalProperties::new);

AzureKeyVaultSecretProperties existingValue = new AzureKeyVaultSecretProperties();
AzurePropertiesUtils.copyAzureCommonProperties(azureProperties, existingValue);

AzureGlobalPropertiesUtils.loadProperties(azureProperties, existingValue);

return binder
.bind(AzureKeyVaultSecretProperties.PREFIX,
Expand All @@ -193,8 +193,8 @@ private AzureKeyVaultSecretProperties loadProperties(Binder binder) {
* @return true if the key vault is enabled, false otherwise.
*/
private boolean isKeyVaultPropertySourceEnabled(AzureKeyVaultSecretProperties properties) {
return (Boolean.TRUE.equals(properties.getPropertySourceEnabled()) || !properties.getPropertySources().isEmpty())
&& Boolean.TRUE.equals(properties.isEnabled());
return properties.isEnabled()
&& (properties.isPropertySourceEnabled() && !properties.getPropertySources().isEmpty());
}

private boolean isKeyVaultClientAvailable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AzureKeyVaultSecretProperties extends AzureKeyVaultProperties imple
/**
* Whether to enable the Key Vault property source.
*/
private Boolean propertySourceEnabled;
private boolean propertySourceEnabled = true;

public SecretServiceVersion getServiceVersion() {
return serviceVersion;
Expand All @@ -46,11 +46,11 @@ public List<AzureKeyVaultPropertySourceProperties> getPropertySources() {
return propertySources;
}

public Boolean getPropertySourceEnabled() {
public boolean isPropertySourceEnabled() {
return propertySourceEnabled;
}

public void setPropertySourceEnabled(Boolean propertySourceEnabled) {
public void setPropertySourceEnabled(boolean propertySourceEnabled) {
this.propertySourceEnabled = propertySourceEnabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.properties.utils;

import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.core.aware.ClientAware;
import com.azure.spring.core.aware.ProxyAware;
import com.azure.spring.core.aware.RetryAware;
import com.azure.spring.core.properties.AzureProperties;
import com.azure.spring.core.util.AzurePropertiesUtils;
import org.springframework.beans.BeanUtils;

/**
* Util class for processor {@link AzureGlobalProperties}.
*/
public final class AzureGlobalPropertiesUtils {

private AzureGlobalPropertiesUtils() {

}

/**
* Load the default value to an Azure Service properties from the global Azure properties.
*
* @param source The global Azure properties.
* @param target The properties of an Azure Service, such as Event Hubs properties. Some common components of the
* service's properties have default value as set to the global properties. For example, the proxy of
* the Event Hubs properties takes the proxy set to the global Azure properties as default.
* @param <T> The type of the properties of an Azure Service.
* @return The Azure Service's properties.
*/
public static <T extends AzureProperties> T loadProperties(AzureGlobalProperties source, T target) {
AzurePropertiesUtils.copyAzureCommonProperties(source, target);

if (target.getClient() instanceof ClientAware.HttpClient) {
BeanUtils.copyProperties(source.getClient().getHttp(), target.getClient());

ClientAware.HttpClient targetClient = (ClientAware.HttpClient) target.getClient();
BeanUtils.copyProperties(source.getClient().getHttp().getLogging(), targetClient.getLogging());
targetClient.getLogging().getAllowedHeaderNames().addAll(source.getClient().getHttp().getLogging().getAllowedHeaderNames());
targetClient.getLogging().getAllowedQueryParamNames().addAll(source.getClient().getHttp().getLogging().getAllowedQueryParamNames());
}

if (target.getClient() instanceof ClientAware.AmqpClient) {
BeanUtils.copyProperties(source.getClient().getAmqp(), target.getClient());
}

if (target.getProxy() instanceof ProxyAware.HttpProxy) {
BeanUtils.copyProperties(source.getProxy().getHttp(), target.getProxy());
}

if (target.getRetry() instanceof RetryAware.HttpRetry) {
BeanUtils.copyProperties(source.getRetry().getHttp(), target.getRetry());
}

return target;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* Configuration properties util classes.
*/
package com.azure.spring.cloud.autoconfigure.properties.utils;

0 comments on commit c890bd8

Please sign in to comment.