|
|
|
@ -25,6 +25,7 @@ import java.util.Objects;
|
|
|
|
|
import com.tencent.cloud.polaris.config.ConfigurationModifier;
|
|
|
|
|
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
|
|
|
|
|
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
|
|
|
|
|
import com.tencent.cloud.polaris.context.ModifyAddress;
|
|
|
|
|
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
|
|
|
|
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
|
|
|
|
@ -118,6 +119,15 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
polarisConfigProperties = new PolarisConfigProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PolarisCryptoConfigProperties polarisCryptoConfigProperties = loadPolarisConfigProperties(
|
|
|
|
|
resolverContext,
|
|
|
|
|
PolarisCryptoConfigProperties.class,
|
|
|
|
|
POLARIS_PREFIX + ".config.crypto"
|
|
|
|
|
);
|
|
|
|
|
if (Objects.isNull(polarisCryptoConfigProperties)) {
|
|
|
|
|
polarisCryptoConfigProperties = new PolarisCryptoConfigProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PolarisContextProperties polarisContextProperties = loadPolarisConfigProperties(
|
|
|
|
|
resolverContext,
|
|
|
|
|
PolarisContextProperties.class,
|
|
|
|
@ -128,11 +138,14 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prepare and init earlier Polaris SDKContext to pull config files from remote.
|
|
|
|
|
prepareAndInitEarlierPolarisSdkContext(resolverContext, polarisConfigProperties, polarisContextProperties);
|
|
|
|
|
prepareAndInitEarlierPolarisSdkContext(resolverContext, polarisConfigProperties, polarisCryptoConfigProperties, polarisContextProperties);
|
|
|
|
|
|
|
|
|
|
bootstrapContext.registerIfAbsent(PolarisConfigProperties.class,
|
|
|
|
|
BootstrapRegistry.InstanceSupplier.of(polarisConfigProperties));
|
|
|
|
|
|
|
|
|
|
bootstrapContext.registerIfAbsent(PolarisCryptoConfigProperties.class,
|
|
|
|
|
BootstrapRegistry.InstanceSupplier.of(polarisCryptoConfigProperties));
|
|
|
|
|
|
|
|
|
|
bootstrapContext.registerIfAbsent(PolarisContextProperties.class,
|
|
|
|
|
BootstrapRegistry.InstanceSupplier.of(polarisContextProperties));
|
|
|
|
|
|
|
|
|
@ -152,7 +165,7 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return loadConfigDataResources(resolverContext,
|
|
|
|
|
location, profiles, polarisConfigProperties, polarisContextProperties);
|
|
|
|
|
location, profiles, polarisConfigProperties, polarisCryptoConfigProperties, polarisContextProperties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -189,6 +202,7 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
ConfigDataLocation location,
|
|
|
|
|
Profiles profiles,
|
|
|
|
|
PolarisConfigProperties polarisConfigProperties,
|
|
|
|
|
PolarisCryptoConfigProperties polarisCryptoConfigProperties,
|
|
|
|
|
PolarisContextProperties polarisContextProperties) {
|
|
|
|
|
List<PolarisConfigDataResource> result = new ArrayList<>();
|
|
|
|
|
boolean optional = location.isOptional();
|
|
|
|
@ -209,6 +223,7 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
}
|
|
|
|
|
PolarisConfigDataResource polarisConfigDataResource = new PolarisConfigDataResource(
|
|
|
|
|
polarisConfigProperties,
|
|
|
|
|
polarisCryptoConfigProperties,
|
|
|
|
|
polarisContextProperties,
|
|
|
|
|
profiles, optional,
|
|
|
|
|
fileName, groupName, serviceName
|
|
|
|
@ -246,12 +261,12 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void prepareAndInitEarlierPolarisSdkContext(ConfigDataLocationResolverContext resolverContext,
|
|
|
|
|
PolarisConfigProperties polarisConfigProperties,
|
|
|
|
|
PolarisConfigProperties polarisConfigProperties, PolarisCryptoConfigProperties polarisCryptoConfigProperties,
|
|
|
|
|
PolarisContextProperties polarisContextProperties) {
|
|
|
|
|
ConfigurableBootstrapContext bootstrapContext = resolverContext.getBootstrapContext();
|
|
|
|
|
if (!bootstrapContext.isRegistered(SDKContext.class)) {
|
|
|
|
|
SDKContext sdkContext = sdkContext(resolverContext,
|
|
|
|
|
polarisConfigProperties, polarisContextProperties);
|
|
|
|
|
polarisConfigProperties, polarisCryptoConfigProperties, polarisContextProperties);
|
|
|
|
|
sdkContext.init();
|
|
|
|
|
bootstrapContext.register(SDKContext.class, BootstrapRegistry.InstanceSupplier.of(sdkContext));
|
|
|
|
|
}
|
|
|
|
@ -259,9 +274,9 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SDKContext sdkContext(ConfigDataLocationResolverContext resolverContext,
|
|
|
|
|
PolarisConfigProperties polarisConfigProperties,
|
|
|
|
|
PolarisConfigProperties polarisConfigProperties, PolarisCryptoConfigProperties polarisCryptoConfigProperties,
|
|
|
|
|
PolarisContextProperties polarisContextProperties) {
|
|
|
|
|
List<PolarisConfigModifier> modifierList = modifierList(polarisConfigProperties, polarisContextProperties);
|
|
|
|
|
List<PolarisConfigModifier> modifierList = modifierList(polarisConfigProperties, polarisCryptoConfigProperties, polarisContextProperties);
|
|
|
|
|
return SDKContext.initContextByConfig(polarisContextProperties.configuration(modifierList, () -> {
|
|
|
|
|
return loadPolarisConfigProperties(resolverContext, String.class, "spring.cloud.client.ip-address");
|
|
|
|
|
}, () -> {
|
|
|
|
@ -270,13 +285,14 @@ public class PolarisConfigDataLocationResolver implements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<PolarisConfigModifier> modifierList(PolarisConfigProperties polarisConfigProperties,
|
|
|
|
|
PolarisCryptoConfigProperties polarisCryptoConfigProperties,
|
|
|
|
|
PolarisContextProperties polarisContextProperties) {
|
|
|
|
|
// add ModifyAddress and ConfigurationModifier to load SDKContext
|
|
|
|
|
List<PolarisConfigModifier> modifierList = new ArrayList<>();
|
|
|
|
|
ModifyAddress modifyAddress = new ModifyAddress(polarisContextProperties);
|
|
|
|
|
|
|
|
|
|
ConfigurationModifier configurationModifier = new ConfigurationModifier(polarisConfigProperties,
|
|
|
|
|
polarisContextProperties);
|
|
|
|
|
polarisCryptoConfigProperties, polarisContextProperties);
|
|
|
|
|
modifierList.add(modifyAddress);
|
|
|
|
|
modifierList.add(configurationModifier);
|
|
|
|
|
return modifierList;
|
|
|
|
|