GR3
This commit is contained in:
@@ -80,7 +80,7 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean exist(String key) {
|
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;
|
Map<String, Object> m = this;
|
||||||
int keyLen = keys.length;
|
int keyLen = keys.length;
|
||||||
for (int i = 0; i < keyLen; i++) {
|
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 {
|
public boolean ipInRange(String ip, String range) throws AddressStringException {
|
||||||
IPAddress ipAddress = new IPAddressString(ip).toAddress();
|
IPAddress ipAddress = new IPAddressString(ip).toAddress();
|
||||||
IPAddress rangeAddress = new IPAddressString(range).getAddress();
|
IPAddress rangeAddress = new IPAddressString(range).getAddress();
|
||||||
@@ -282,9 +296,12 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
|||||||
.map(
|
.map(
|
||||||
bodyDataBuffer -> {
|
bodyDataBuffer -> {
|
||||||
if (bodyDataBuffer == NettyDataBufferUtils.EMPTY_DATA_BUFFER) {
|
if (bodyDataBuffer == NettyDataBufferUtils.EMPTY_DATA_BUFFER) {
|
||||||
return null;
|
return ReactorUtils.NULL;
|
||||||
} else {
|
} else {
|
||||||
String json = bodyDataBuffer.toString(StandardCharsets.UTF_8).trim();
|
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) {
|
if (json.charAt(0) == Consts.S.LEFT_SQUARE_BRACKET) {
|
||||||
List<Object> bodyMap = JacksonUtils.readValue(json, new TypeReference<List<Object>>(){});
|
List<Object> bodyMap = JacksonUtils.readValue(json, new TypeReference<List<Object>>(){});
|
||||||
ognlRoot.put(body, bodyMap);
|
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>>(){});
|
Map<String, Object> bodyMap = JacksonUtils.readValue(json, new TypeReference<Map<String, Object>>(){});
|
||||||
ognlRoot.put(body, bodyMap);
|
ognlRoot.put(body, bodyMap);
|
||||||
}
|
}
|
||||||
return null;
|
return ReactorUtils.NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -307,7 +324,7 @@ public class GrayReleasePlugin extends RequestBodyPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("request {} ognl root: {}", request.getId(), ognlRoot);
|
LOGGER.debug("request {} ognl root: {}", request.getId(), JacksonUtils.writeValueAsString(ognlRoot));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ognlRoot;
|
return ognlRoot;
|
||||||
|
|||||||
@@ -29,14 +29,22 @@ public class GrayReleasePluginTests {
|
|||||||
)
|
)
|
||||||
.webFilter(
|
.webFilter(
|
||||||
(exchange, chain) -> {
|
(exchange, chain) -> {
|
||||||
|
|
||||||
GrayReleasePlugin grayReleasePlugin = new GrayReleasePlugin();
|
GrayReleasePlugin grayReleasePlugin = new GrayReleasePlugin();
|
||||||
Map<String, Object> config = new HashMap<>();
|
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("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("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(WebUtils.IGNORE_PLUGIN, Consts.S.EMPTY);
|
||||||
exchange.getAttributes().put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
|
exchange.getAttributes().put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
|
||||||
exchange.getAttributes().put("oi@", "11.238.145.181");
|
exchange.getAttributes().put("oi@", "11.238.145.181");
|
||||||
@@ -46,15 +54,15 @@ public class GrayReleasePluginTests {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
client.get()
|
client.post()
|
||||||
.uri("/proxy/aservice/apath")
|
.uri("/proxy/aservice/apath/xxx")
|
||||||
//.header("h1", "v1")
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.bodyValue("{\"user\":\"henry\",\"tools\":{\"gun\":\"ak\"}}")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectBody(String.class).value(
|
.expectBody(String.class).value(
|
||||||
v -> {
|
v -> {
|
||||||
System.err.println("body:\n" + v);
|
System.err.println("body:\n" + v);
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user