GR3
This commit is contained in:
@@ -80,7 +80,7 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
||||
}
|
||||
|
||||
public boolean exist(String key) {
|
||||
String[] keys = StringUtils.split(key, Consts.S.COMMA);
|
||||
String[] keys = StringUtils.split(key, Consts.S.DOT);
|
||||
Map<String, Object> m = this;
|
||||
int keyLen = keys.length;
|
||||
for (int i = 0; i < keyLen; i++) {
|
||||
@@ -141,6 +141,20 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean clientIpInRange(String rangeStartIp, String rangeEndIp) throws AddressStringException {
|
||||
Map<String, Object> cli = (Map<String, Object>) get(client);
|
||||
if (cli == null) {
|
||||
return false;
|
||||
} else {
|
||||
String pi = (String) cli.get(ip);
|
||||
if (pi == null) {
|
||||
return false;
|
||||
} else {
|
||||
return ipInRange(pi, rangeStartIp, rangeEndIp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean ipInRange(String ip, String range) throws AddressStringException {
|
||||
IPAddress ipAddress = new IPAddressString(ip).toAddress();
|
||||
IPAddress rangeAddress = new IPAddressString(range).getAddress();
|
||||
@@ -282,9 +296,12 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
||||
.map(
|
||||
bodyDataBuffer -> {
|
||||
if (bodyDataBuffer == NettyDataBufferUtils.EMPTY_DATA_BUFFER) {
|
||||
return null;
|
||||
return ReactorUtils.NULL;
|
||||
} else {
|
||||
String json = bodyDataBuffer.toString(StandardCharsets.UTF_8).trim();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("request {} body: {}", request.getId(), json);
|
||||
}
|
||||
if (json.charAt(0) == Consts.S.LEFT_SQUARE_BRACKET) {
|
||||
List<Object> bodyMap = JacksonUtils.readValue(json, new TypeReference<List<Object>>(){});
|
||||
ognlRoot.put(body, bodyMap);
|
||||
@@ -292,7 +309,7 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
||||
Map<String, Object> bodyMap = JacksonUtils.readValue(json, new TypeReference<Map<String, Object>>(){});
|
||||
ognlRoot.put(body, bodyMap);
|
||||
}
|
||||
return null;
|
||||
return ReactorUtils.NULL;
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -307,7 +324,7 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
||||
}
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("request {} ognl root: {}", request.getId(), ognlRoot);
|
||||
LOGGER.debug("request {} ognl root: {}", request.getId(), JacksonUtils.writeValueAsString(ognlRoot));
|
||||
}
|
||||
|
||||
return ognlRoot;
|
||||
|
||||
@@ -29,14 +29,22 @@ public class GrayReleasePluginTests {
|
||||
)
|
||||
.webFilter(
|
||||
(exchange, chain) -> {
|
||||
|
||||
GrayReleasePlugin grayReleasePlugin = new GrayReleasePlugin();
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
config.put("triggerCondition", "method == 'get'");
|
||||
config.put("triggerCondition", " method == 'post' " +
|
||||
" and matches('path','^/apath/x*') " +
|
||||
" and clientIpInRange('11.238.145.180', '11.238.145.182') " +
|
||||
" and exist('body.tools.gun') ");
|
||||
config.put("routeType", 2);
|
||||
config.put("routeConfig", "type: http \n serviceName: bservice");
|
||||
config.put("routeConfig",
|
||||
"type : http \n " +
|
||||
"serviceName : bservice \n " +
|
||||
"path : /bpath/{$1} ");
|
||||
|
||||
// exchange.getAttributes().put("pcsit@", Collections.emptyIterator());
|
||||
exchange.getAttributes().put(WebUtils.ROUTE, new Route());
|
||||
Route route = new Route().path("/apath/**");
|
||||
exchange.getAttributes().put(WebUtils.ROUTE, route);
|
||||
exchange.getAttributes().put(WebUtils.IGNORE_PLUGIN, Consts.S.EMPTY);
|
||||
exchange.getAttributes().put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
|
||||
exchange.getAttributes().put("oi@", "11.238.145.181");
|
||||
@@ -46,15 +54,15 @@ public class GrayReleasePluginTests {
|
||||
)
|
||||
.build();
|
||||
|
||||
client.get()
|
||||
.uri("/proxy/aservice/apath")
|
||||
//.header("h1", "v1")
|
||||
client.post()
|
||||
.uri("/proxy/aservice/apath/xxx")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue("{\"user\":\"henry\",\"tools\":{\"gun\":\"ak\"}}")
|
||||
.exchange()
|
||||
.expectBody(String.class).value(
|
||||
v -> {
|
||||
System.err.println("body:\n" + v);
|
||||
}
|
||||
)
|
||||
;
|
||||
v -> {
|
||||
System.err.println("body:\n" + v);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user