feat:support config empty protection. (#1585)

Co-authored-by: Haotian Zhang <skyebefreeman@qq.com>
pull/1590/head
Fishtail 3 months ago committed by GitHub
parent 2bac402116
commit 041b5a37dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,4 +2,4 @@
--- ---
- [fix: add gateway context config example.](https://github.com/Tencent/spring-cloud-tencent/pull/1563) - [fix: add gateway context config example.](https://github.com/Tencent/spring-cloud-tencent/pull/1563)
- [feat:support config empty protection.](https://github.com/Tencent/spring-cloud-tencent/pull/1585)

@ -80,11 +80,12 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
} }
private void initDataSource(ConfigurationImpl configuration) { private void initDataSource(ConfigurationImpl configuration) {
ConnectorConfigImpl connectorConfig = configuration.getConfigFile().getServerConnector();
// set connector type // set connector type
configuration.getConfigFile().getServerConnector().setConnectorType(polarisConfigProperties.getDataSource()); connectorConfig.setConnectorType(polarisConfigProperties.getDataSource());
if (StringUtils.equalsIgnoreCase(polarisConfigProperties.getDataSource(), LOCAL_FILE_CONNECTOR_TYPE)) { if (StringUtils.equalsIgnoreCase(polarisConfigProperties.getDataSource(), LOCAL_FILE_CONNECTOR_TYPE)) {
String localFileRootPath = polarisConfigProperties.getLocalFileRootPath(); String localFileRootPath = polarisConfigProperties.getLocalFileRootPath();
configuration.getConfigFile().getServerConnector().setPersistDir(localFileRootPath); connectorConfig.setPersistDir(localFileRootPath);
LOGGER.info("[SCT] Run spring cloud tencent config with local data source. localFileRootPath = {}", localFileRootPath); LOGGER.info("[SCT] Run spring cloud tencent config with local data source. localFileRootPath = {}", localFileRootPath);
return; return;
} }
@ -110,13 +111,15 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
checkAddressAccessible(configAddresses); checkAddressAccessible(configAddresses);
} }
configuration.getConfigFile().getServerConnector().setAddresses(configAddresses); connectorConfig.setAddresses(configAddresses);
if (StringUtils.isNotEmpty(polarisConfigProperties.getToken())) { if (StringUtils.isNotEmpty(polarisConfigProperties.getToken())) {
ConnectorConfigImpl connectorConfig = configuration.getConfigFile().getServerConnector();
connectorConfig.setToken(polarisConfigProperties.getToken()); connectorConfig.setToken(polarisConfigProperties.getToken());
} }
connectorConfig.setEmptyProtectionEnable(polarisConfigProperties.isEmptyProtectionEnabled());
connectorConfig.setEmptyProtectionExpiredInterval(polarisConfigProperties.getEmptyProtectionExpiredInterval());
LOGGER.info("[SCT] Run spring cloud tencent config in polaris data source."); LOGGER.info("[SCT] Run spring cloud tencent config in polaris data source.");
} }

@ -100,6 +100,17 @@ public class PolarisConfigProperties {
*/ */
private boolean checkAddress = true; private boolean checkAddress = true;
/**
* if empty protection is enabled.
*/
private boolean emptyProtectionEnabled = true;
/**
* interval of empty protection. 7 days by default.
*/
private long emptyProtectionExpiredInterval = 7 * 24 * 3600 * 1000L;
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
@ -204,6 +215,22 @@ public class PolarisConfigProperties {
this.checkAddress = checkAddress; this.checkAddress = checkAddress;
} }
public boolean isEmptyProtectionEnabled() {
return emptyProtectionEnabled;
}
public void setEmptyProtectionEnabled(boolean emptyProtectionEnabled) {
this.emptyProtectionEnabled = emptyProtectionEnabled;
}
public long getEmptyProtectionExpiredInterval() {
return emptyProtectionExpiredInterval;
}
public void setEmptyProtectionExpiredInterval(long emptyProtectionExpiredInterval) {
this.emptyProtectionExpiredInterval = emptyProtectionExpiredInterval;
}
@Override @Override
public String toString() { public String toString() {
return "PolarisConfigProperties{" + return "PolarisConfigProperties{" +
@ -220,6 +247,8 @@ public class PolarisConfigProperties {
", localFileRootPath='" + localFileRootPath + '\'' + ", localFileRootPath='" + localFileRootPath + '\'' +
", internalEnabled=" + internalEnabled + ", internalEnabled=" + internalEnabled +
", checkAddress=" + checkAddress + ", checkAddress=" + checkAddress +
", emptyProtectionEnabled=" + emptyProtectionEnabled +
", emptyProtectionExpiredInterval=" + emptyProtectionExpiredInterval +
'}'; '}';
} }
} }

@ -74,7 +74,7 @@
<revision>2.0.2.0-2022.0.5-SNAPSHOT</revision> <revision>2.0.2.0-2022.0.5-SNAPSHOT</revision>
<!-- Polaris SDK version --> <!-- Polaris SDK version -->
<polaris.version>2.0.1.0</polaris.version> <polaris.version>2.0.2.0-SNAPSHOT</polaris.version>
<!-- Dependencies --> <!-- Dependencies -->
<springdoc.version>2.2.0</springdoc.version> <springdoc.version>2.2.0</springdoc.version>

Loading…
Cancel
Save