diff --git a/ingress-proxy/src/main/java/com/networknt/proxy/ExternalServiceConfig.java b/ingress-proxy/src/main/java/com/networknt/proxy/ExternalServiceConfig.java index 97a3be552c..561dbe2253 100644 --- a/ingress-proxy/src/main/java/com/networknt/proxy/ExternalServiceConfig.java +++ b/ingress-proxy/src/main/java/com/networknt/proxy/ExternalServiceConfig.java @@ -2,6 +2,7 @@ import com.networknt.config.Config; import com.networknt.config.ConfigException; +import com.networknt.config.JsonMapper; import com.networknt.handler.config.UrlRewriteRule; import java.util.ArrayList; @@ -129,15 +130,29 @@ public List getUrlRewriteRules() { public void setUrlRewriteRules() { this.urlRewriteRules = new ArrayList<>(); - if (mappedConfig.get("urlRewriteRules") !=null && mappedConfig.get("urlRewriteRules") instanceof String) { - urlRewriteRules.add(UrlRewriteRule.convertToUrlRewriteRule((String)mappedConfig.get("urlRewriteRules"))); - } else { - List rules = (List)mappedConfig.get("urlRewriteRules"); - if(rules != null) { + if(mappedConfig.get("urlRewriteRules") != null) { + if (mappedConfig.get("urlRewriteRules") instanceof String) { + String s = (String)mappedConfig.get("urlRewriteRules"); + s = s.trim(); + // There are two formats for the urlRewriteRules. One is a string separated by a space + // and the other is a list of strings separated by a space in JSON list format. + if(s.startsWith("[")) { + // multiple rules + List rules = (List) JsonMapper.fromJson(s, List.class); + for (String rule : rules) { + urlRewriteRules.add(UrlRewriteRule.convertToUrlRewriteRule(rule)); + } + } else { + // single rule + urlRewriteRules.add(UrlRewriteRule.convertToUrlRewriteRule(s)); + } + } else if (mappedConfig.get("urlRewriteRules") instanceof List) { + List rules = (List)mappedConfig.get("urlRewriteRules"); for (String s : rules) { urlRewriteRules.add(UrlRewriteRule.convertToUrlRewriteRule(s)); } } + } } @@ -150,12 +165,26 @@ private void setConfigList() { Object object = mappedConfig.get(PATH_HOST_MAPPINGS); pathHostMappings = new ArrayList<>(); if(object instanceof String) { - // there is only one path to host available, split the string for path and host. - String[] parts = ((String)object).split(" "); - if(parts.length != 2) { - throw new ConfigException("path host entry must have two elements separated by a space."); + String s = (String)object; + s = s.trim(); + if(s.startsWith("[")) { + // multiple path to host mappings + List mappings = (List) JsonMapper.fromJson(s, List.class); + for (String mapping : mappings) { + String[] parts = mapping.split(" "); + if(parts.length != 2) { + throw new ConfigException("path host entry must have two elements separated by a space."); + } + pathHostMappings.add(parts); + } + } else { + // there is only one path to host available, split the string for path and host. + String[] parts = s.split(" "); + if(parts.length != 2) { + throw new ConfigException("path host entry must have two elements separated by a space."); + } + pathHostMappings.add(parts); } - pathHostMappings.add(parts); } else if (object instanceof List) { List maps = (List)object; for(String s: maps) { diff --git a/ingress-proxy/src/test/resources/config/values.yml b/ingress-proxy/src/test/resources/config/values.yml index 61c53df0ad..d8e4cb6cf1 100644 --- a/ingress-proxy/src/test/resources/config/values.yml +++ b/ingress-proxy/src/test/resources/config/values.yml @@ -84,8 +84,9 @@ conquest.pathPrefixAuths: [{"pathPrefix":"/conquest","authIssuer":"example","aut # external-service.yml externalService.enabled: true -externalService.pathHostMappings: - - /sharepoint https://sharepoint.microsoft.com - - /get https://postman-echo.com - - /post https://postman-echo.com - - /abc https://abc.com +externalService.pathHostMappings: "[\"/sharepoint https://sharepoint.microsoft.com\",\"/get https://postman-echo.com\",\"/post https://postman-echo.com\",\"/abc https://abc.com\"]" +#externalService.pathHostMappings: +# - /sharepoint https://sharepoint.microsoft.com +# - /get https://postman-echo.com +# - /post https://postman-echo.com +# - /abc https://abc.com