/*
* ================================================================================
* Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2019-2020 China Mobile. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private String configServicePropertiesKey =
ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_PROPERTIES_KEY;
+ private String springConfigServicePropertiesKey =
+ ConfigBindingServiceConstants.SPRING_CONFIG_BINDING_SERVICE_PROPERTIES_KEY;
+
@Override
public void postProcessEnvironment(final ConfigurableEnvironment environment,
final SpringApplication application) {
*/
public String parseTcaConfig(JsonObject jsonObject) {
- JsonElement jsonConfig = jsonObject.get(ConfigBindingServiceConstants.CONFIG);
+ Optional<String> configServiceJsonOptional = Optional.of(jsonObject.toString());
+
+ JsonElement jsonPolicyConfig = jsonObject.get(ConfigBindingServiceConstants.POLICIES);
- Optional<String> configServiceJsonOptional = Optional.of(jsonConfig.toString());
+ String policies = null;
+ if (jsonPolicyConfig != null) {
+ policies = jsonPolicyConfig.getAsJsonObject().getAsJsonArray(ConfigBindingServiceConstants.ITEMS).get(0)
+ .getAsJsonObject().get(ConfigBindingServiceConstants.TCAPOLICY).toString();
+ }
// convert fetch config binding service json string to Map of property key and
// values
Map<String, Object> configPropertiesMap = configServiceJsonOptional
.map(new JsonStringToMapFunction(configServicePropertiesKey)).orElse(Collections.emptyMap());
+ if (policies != null) {
+ configPropertiesMap.put(ConfigBindingServiceConstants.POLICY, policies);
+ }
if (configPropertiesMap.isEmpty()) {
-
logger.warn("No properties found in config binding service");
} else {
-
// remove config service key prefix on spring reserved property key prefixes
final Set<String> springKeyPrefixes =
ConfigBindingServiceConstants.getSpringReservedPropertiesKeyPrefixes();
final Set<String> springKeys = springKeyPrefixes.stream()
- .map(springKeyPrefix -> configServicePropertiesKey + "." + springKeyPrefix)
+ .map(springKeyPrefix -> springConfigServicePropertiesKey + "." + springKeyPrefix)
.collect(Collectors.toSet());
filterKeyMap = configPropertiesMap.entrySet().stream()
.collect(Collectors.toMap((Map.Entry<String, Object> e) -> springKeys.stream()
.anyMatch(springKey -> e.getKey().startsWith(springKey))
- ? e.getKey().substring(configServicePropertiesKey.toCharArray().length + 1)
+ ? e.getKey().substring(springConfigServicePropertiesKey.toCharArray().length + 1)
: e.getKey(),
Map.Entry::getValue));
.info("Adding property from config service in spring context: {} -> {}", key, value));
MutablePropertySources sources = env.getPropertySources();
addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
-
+
}
return configServiceJsonOptional.get();
}