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

fixes #1084 update the DefaultConfigLoader to get the values.yml from… #1085

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions security/src/test/java/com/networknt/security/JwtIssuerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ public void sidecarReferenceBootstrap() throws Exception {
System.out.println("***Reference Long lived Bootstrap token for config server and controller: " + jwt);
}

/**
* This token is used to connect to the light-config-server with serviceId 0100 for testing with a service specific for a client.
* @throws Exception
*/
@Test
public void sidecarReferenceBootstrapWithServiceId() throws Exception {
JwtClaims claims = ClaimsUtil.getTestCcClaimsScopeService("f7d42348-c647-4efb-a52d-4c5787421e72", "A8E73740C0041C03D67C3A951AA1D7533C8F9F2FB57D7BA107210B9BC9E06DA2", "com.networknt.petstore-1.0.0");
claims.setExpirationTimeMinutesInTheFuture(5256000);
String jwt = JwtIssuer.getJwt(claims);
System.out.println("***Reference Long lived Bootstrap token for config server and controller: " + jwt);
}

/**
* This token is used to connect to the light-config-server with serviceId example-service for unit test populated configs.
* @throws Exception
Expand Down
18 changes: 7 additions & 11 deletions server/src/main/java/com/networknt/server/DefaultConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.networknt.client.ClientConfig;
import com.networknt.client.Http2Client;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.monad.Failure;
import com.networknt.status.Status;
import com.networknt.utility.StringUtils;
Expand Down Expand Up @@ -147,8 +148,8 @@ public void init() {
try {
String configPath = getConfigServerPath();

// This is the method in the future to load values.yml from the config server
// loadConfigs(configPath);
// This is the method to load values.yml from the config server
loadConfigs(configPath);

loadFiles(configPath, CONFIG_SERVER_CERTS_CONTEXT_ROOT);

Expand Down Expand Up @@ -186,10 +187,7 @@ private void loadConfigs(String configPath) {
String configServerConfigsPath = CONFIG_SERVER_CONFIGS_CONTEXT_ROOT + configPath;
//get service configs and put them in config cache
Map<String, Object> serviceConfigs = getServiceConfigs(configServerConfigsPath);

//set the environment value (the one used to fetch configs) in the serviceConfigs going into configCache
serviceConfigs.put(ENV_PROPERTY_KEY, lightEnv);
logger.debug("serviceConfigs received from Config Server: {}", serviceConfigs);
if(logger.isDebugEnabled()) logger.debug("serviceConfigs received from Config Server: ", JsonMapper.toJson(serviceConfigs));

// pass serviceConfigs through Config.yaml's load method so that it can decrypt any encrypted values
DumperOptions options = new DumperOptions();
Expand All @@ -212,8 +210,7 @@ private void loadFiles(String configPath, String contextRoot) {
String configServerFilesPath = contextRoot + configPath;
//get service files and put them in config dir
Map<String, Object> serviceFiles = getServiceConfigs(configServerFilesPath);
logger.debug("{} files loaded from config sever.", serviceFiles.size());
logger.debug("loadFiles: {}", serviceFiles);
if(logger.isDebugEnabled()) logger.debug("loadFiles:", JsonMapper.toJson(serviceFiles));
try {
Path filePath = Paths.get(targetConfigsDirectory);
if (!Files.exists(filePath)) {
Expand Down Expand Up @@ -260,7 +257,7 @@ private Map<String, Object> getServiceConfigs(String configServerPath) {

Map<String, Object> configs = new HashMap<>();

logger.debug("Calling Config Server endpoint:host{}:path{}", configServerUri, configServerPath);
if(logger.isDebugEnabled()) logger.debug("Calling Config Server endpoint:host{}:path{}", configServerUri, configServerPath);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(configServerUri.trim() + configServerPath.trim()))
.header(Headers.AUTHORIZATION_STRING, authorization)
Expand All @@ -274,8 +271,7 @@ private Map<String, Object> getServiceConfigs(String configServerPath) {
logger.error("Failed to load configs from config server" + statusCode + ":" + body);
throw new Exception("Failed to load configs from config server: " + statusCode);
} else {
Map<String, Object> responseMap = (Map<String, Object>) mapper.readValue(body, new TypeReference<Map<String, Object>>() {});
configs = (Map<String, Object>) responseMap.get("configProperties");
configs = mapper.readValue(body, new TypeReference<Map<String, Object>>() {});
}
} catch (Exception e) {
logger.error("Exception while calling config server:", e);
Expand Down