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

Spring cloud azure refactor global properties #25239

Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -2297,7 +2297,7 @@
</Match>

<Match>
<Class name="com.azure.spring.cloud.autoconfigure.jms.AzureServiceBusJmsProperties"/>
<Class name="com.azure.spring.cloud.autoconfigure.jms.properties.AzureServiceBusJmsProperties"/>
<Field name="pricingTier"/>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.spring.cloud.actuate.cosmos.CosmosHealthIndicator;
import com.azure.spring.cloud.autoconfigure.cosmos.AzureCosmosAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.cosmos.AzureCosmosProperties;
import com.azure.spring.cloud.autoconfigure.cosmos.properties.AzureCosmosProperties;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
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.core.properties.AzureProperties;
import com.azure.spring.core.properties.AzurePropertiesUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

Expand All @@ -24,6 +28,28 @@ public AzureServiceConfigurationBase(AzureGlobalProperties azureProperties) {

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.data.appconfiguration.ConfigurationClient;
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
import com.azure.spring.cloud.autoconfigure.AzureServiceConfigurationBase;
import com.azure.spring.cloud.autoconfigure.appconfiguration.properties.AzureAppConfigurationProperties;
import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnAnyProperty;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.service.appconfiguration.ConfigurationClientBuilderFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

import com.azure.data.appconfiguration.ConfigurationServiceVersion;
import com.azure.spring.cloud.autoconfigure.properties.AbstractAzureHttpCP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

package com.azure.spring.cloud.autoconfigure.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.logging.Log;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -22,18 +22,28 @@
import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLOUD;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_HTTP_LOG_DETAIL_LEVEL;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_PASSWORD;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_READ_TIMEOUT;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_RETRY_COUNT;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_SUBSCRIPTION_ID;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_TENANT_ID;
import static com.azure.core.util.Configuration.PROPERTY_AZURE_USERNAME;
import static com.azure.core.util.Configuration.PROPERTY_NO_PROXY;

/**
* An EnvironmentPostProcessor to convert environment variables predefined by Azure Core and Azure SDKs to Azure Spring
* properties, and add a property source for them as well.
*/
public class AzureGlobalConfigurationEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {

private static final Logger LOGGER = LoggerFactory.getLogger(AzureGlobalConfigurationEnvironmentPostProcessor.class);
private final Log logger;

public AzureGlobalConfigurationEnvironmentPostProcessor(Log logger) {
this.logger = logger;
AzureCoreEnvMapping.setLogger(logger);
}

@Override
public int getOrder() {
Expand Down Expand Up @@ -63,21 +73,25 @@ enum AzureCoreEnvMapping {

// TODO (xiada): PROPERTY_AZURE_LOG_LEVEL, how to set this to env?

httpLogLevel(PROPERTY_AZURE_HTTP_LOG_DETAIL_LEVEL, "client.logging.level"),
maxRetry(PROPERTY_AZURE_REQUEST_RETRY_COUNT, "retry.max-attempts"),

httpLogLevel(PROPERTY_AZURE_HTTP_LOG_DETAIL_LEVEL, "client.http.logging.level"),

httpConnectTimeout(PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT, "client.http.connect-timeout", convertMillisToDuration()),

httpReadTimeout(PROPERTY_AZURE_REQUEST_READ_TIMEOUT, "client.http.read-timeout", convertMillisToDuration()),

httpWriteTimeout(PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT, "client.http.write-timeout", convertMillisToDuration()),

httpResponseTimeout(PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT, "client.http.response-timeout", convertMillisToDuration()),

maxRetry(PROPERTY_AZURE_REQUEST_RETRY_COUNT, "retry.max-attempts");
httpNoProxy(PROPERTY_NO_PROXY, "proxy.http.non-proxy-hosts");

// TODO (xiada): we can't configure http at global level:
// PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT,
// PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT,
// PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT,
// PROPERTY_AZURE_REQUEST_READ_TIMEOUT,
// PROPERTY_NO_PROXY

// TODO (xiada): how to set this proxy?
// proxy(PROPERTY_HTTP_PROXY, PROPERTY_HTTPS_PROXY)


private static Log logger;
private final String coreEnvName;
private final String springPropertyName;
private final Function<String, String> converter;
Expand All @@ -91,11 +105,30 @@ enum AzureCoreEnvMapping {
this.springPropertyName = "spring.cloud.azure." + springPropertyName;
this.converter = converter;
}

private static Function<String, String> convertMillisToDuration() {
saragluna marked this conversation as resolved.
Show resolved Hide resolved
return ms -> {
try {
return Duration.ofMillis(Integer.parseInt(ms)).toString();
} catch (Exception ignore) {
if (logger != null) {
logger.debug("The millisecond value " + ms + " is malformed.");
}
return null;
}
};
}

public static void setLogger(Log logger) {
AzureCoreEnvMapping.logger = logger;
}

}

enum AzureSdkEnvMapping {
keyVaultSecretEndpoint("AZURE_KEYVAULT_ENDPOINT", "keyvault.secret.endpoint"),
keyVaultCertificateEndpoint("AZURE_KEYVAULT_ENDPOINT", "keyvault.certificate.endpoint");
keyVaultCertificateEndpoint("AZURE_KEYVAULT_ENDPOINT", "keyvault.certificate.endpoint"),
eventHubsConnectionString("AZURE_EVENT_HUBS_CONNECTION_STRING", "eventhubs.connection-string");

private final String sdkEnvName;
private final String springPropertyName;
Expand Down Expand Up @@ -132,7 +165,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
if (!source.isEmpty()) {
environment.getPropertySources().addLast(new AzureCoreEnvPropertySource("Azure Core/SDK", source));
} else {
LOGGER.debug("No env predefined by Azure Core/SDKs are set, skip adding the AzureCoreEnvPropertySource.");
logger.debug("No env predefined by Azure Core/SDKs are set, skip adding the AzureCoreEnvPropertySource.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.spring.cloud.autoconfigure.AzureServiceConfigurationBase;
import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnAnyProperty;
import com.azure.spring.cloud.autoconfigure.cosmos.properties.AzureCosmosProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.service.cosmos.CosmosClientBuilderFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

import com.azure.cosmos.ConnectionMode;
import com.azure.cosmos.ConsistencyLevel;
Expand All @@ -10,8 +10,8 @@
import com.azure.cosmos.ThrottlingRetryOptions;
import com.azure.cosmos.models.CosmosPermissionProperties;
import com.azure.spring.cloud.autoconfigure.properties.core.AbstractAzureServiceCP;
import com.azure.spring.core.properties.client.ClientProperties;
import com.azure.spring.core.properties.proxy.HttpProxyProperties;
import com.azure.spring.cloud.autoconfigure.properties.core.client.ClientCP;
import com.azure.spring.cloud.autoconfigure.properties.core.proxy.HttpProxyCP;
import com.azure.spring.service.cosmos.CosmosProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.validation.annotation.Validated;
Expand All @@ -30,10 +30,10 @@ public class AzureCosmosProperties extends AbstractAzureServiceCP implements Cos
public static final String PREFIX = "spring.cloud.azure.cosmos";

@NestedConfigurationProperty
private final HttpProxyProperties proxy = new HttpProxyProperties();
private final HttpProxyCP proxy = new HttpProxyCP();

@NestedConfigurationProperty
private final ClientProperties client = new ClientProperties();
private final ClientCP client = new ClientCP();

@NotEmpty
@Pattern(regexp = "http[s]{0,1}://.*.documents.azure.com.*")
Expand Down Expand Up @@ -73,12 +73,12 @@ public class AzureCosmosProperties extends AbstractAzureServiceCP implements Cos
private boolean populateQueryMetrics;

@Override
public HttpProxyProperties getProxy() {
public HttpProxyCP getProxy() {
return proxy;
}

@Override
public ClientProperties getClient() {
public ClientCP getClient() {
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.spring.cloud.autoconfigure.data.cosmos;

import com.azure.spring.cloud.autoconfigure.cosmos.AzureCosmosProperties;
import com.azure.spring.cloud.autoconfigure.cosmos.properties.AzureCosmosProperties;
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration;
import com.azure.spring.data.cosmos.config.CosmosConfig;
import com.azure.spring.data.cosmos.core.CosmosTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

import com.azure.spring.cloud.autoconfigure.storage.blob.AzureStorageBlobProperties;
import com.azure.spring.cloud.autoconfigure.storage.blob.properties.AzureStorageBlobProperties;
import com.azure.spring.core.properties.AzurePropertiesUtils;
import com.azure.spring.service.eventhubs.properties.EventHubConsumerDescriptor;
import com.azure.spring.service.eventhubs.properties.EventHubNamespaceDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.jms;

import com.azure.spring.cloud.autoconfigure.jms.properties.AzureServiceBusJmsProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.jms;

import com.azure.spring.cloud.autoconfigure.jms.properties.AzureServiceBusJmsProperties;
import com.azure.spring.core.connectionstring.implementation.ServiceBusConnectionString;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.jms;

import com.azure.spring.cloud.autoconfigure.jms.properties.AzureServiceBusJmsProperties;
import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactory;
import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactorySettings;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.jms.support.QosSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.security.keyvault.certificates.CertificateClient;
import com.azure.security.keyvault.certificates.CertificateClientBuilder;
import com.azure.spring.cloud.autoconfigure.AzureServiceConfigurationBase;
import com.azure.spring.cloud.autoconfigure.keyvault.certificates.properties.AzureKeyVaultCertificateProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.service.keyvault.certificates.CertificateClientBuilderFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.keyvault.certificates;
package com.azure.spring.cloud.autoconfigure.keyvault.certificates.properties;

import com.azure.security.keyvault.certificates.CertificateServiceVersion;
import com.azure.spring.cloud.autoconfigure.keyvault.AzureKeyVaultProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.common.AzureKeyVaultProperties;
import com.azure.spring.service.keyvault.certificates.KeyVaultCertificateProperties;

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

package com.azure.spring.cloud.autoconfigure.keyvault;
package com.azure.spring.cloud.autoconfigure.keyvault.common;

import com.azure.spring.cloud.autoconfigure.properties.AbstractAzureHttpCP;

Expand All @@ -10,7 +10,6 @@
*/
public class AzureKeyVaultProperties extends AbstractAzureHttpCP {

// TODO (xiada): the default vault url
private String endpoint;

public String getEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.security.keyvault.secrets.SecretClient;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultPropertySourceProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultSecretProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.properties.AzureKeyVaultSecretProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.core.properties.AzurePropertiesUtils;
import com.azure.spring.service.keyvault.secrets.SecretClientBuilderFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.security.keyvault.secrets.SecretClientBuilder;
import com.azure.spring.cloud.autoconfigure.AzureServiceConfigurationBase;
import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnAnyProperty;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.properties.AzureKeyVaultSecretProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.service.keyvault.secrets.SecretClientBuilderFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.keyvault.secrets;
package com.azure.spring.cloud.autoconfigure.keyvault.secrets.properties;

import com.azure.security.keyvault.secrets.SecretServiceVersion;
import com.azure.spring.cloud.autoconfigure.keyvault.AzureKeyVaultProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.common.AzureKeyVaultProperties;
import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultPropertySourceProperties;
import com.azure.spring.service.keyvault.secrets.KeyVaultSecretProperties;

import java.util.ArrayList;
Expand Down
Loading