[ISSUE#5696] Add requestClass to resource properties for grpc resource parser.
This commit is contained in:
liaochuntao 2022-03-23 13:34:10 +08:00 committed by GitHub
commit fabf6d43a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 14 deletions

View File

@ -18,6 +18,9 @@ package com.alibaba.nacos.auth.parser.grpc;
import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.auth.parser.AbstractResourceParser;
import com.alibaba.nacos.plugin.auth.constant.Constants;
import java.util.Properties;
/**
* Abstract Grpc Resource Parser.
@ -25,5 +28,11 @@ import com.alibaba.nacos.auth.parser.AbstractResourceParser;
* @author xiweng.yy
*/
public abstract class AbstractGrpcResourceParser extends AbstractResourceParser<Request> {
@Override
protected Properties getProperties(Request request) {
Properties properties = new Properties();
properties.setProperty(Constants.Resource.REQUEST_CLASS, request.getClass().getSimpleName());
return properties;
}
}

View File

@ -22,7 +22,6 @@ import com.alibaba.nacos.common.utils.ReflectUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import java.util.List;
import java.util.Properties;
/**
* Config Grpc resource parser.
@ -59,9 +58,4 @@ public class ConfigGrpcResourceParser extends AbstractGrpcResourceParser {
.getFieldValue(request, com.alibaba.nacos.api.common.Constants.DATAID, StringUtils.EMPTY);
return StringUtils.isBlank(dataId) ? StringUtils.EMPTY : dataId;
}
@Override
protected Properties getProperties(Request request) {
return new Properties();
}
}

View File

@ -23,8 +23,6 @@ import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.common.utils.ReflectUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import java.util.Properties;
/**
* Naming Grpc resource parser.
*
@ -61,9 +59,4 @@ public class NamingGrpcResourceParser extends AbstractGrpcResourceParser {
}
return StringUtils.isBlank(serviceName) ? StringUtils.EMPTY : serviceName;
}
@Override
protected Properties getProperties(Request request) {
return new Properties();
}
}

View File

@ -50,6 +50,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(MockNamingRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -62,6 +64,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -74,6 +78,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(MockNamingRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -86,6 +92,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -98,6 +106,8 @@ public class NamingGrpcResourceParserTest {
assertEquals(StringUtils.EMPTY, actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(MockNamingRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -110,6 +120,8 @@ public class NamingGrpcResourceParserTest {
assertEquals(StringUtils.EMPTY, actual.getGroup());
assertEquals("testS", actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -122,6 +134,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals(StringUtils.EMPTY, actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(MockNamingRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
@Test
@ -134,6 +148,8 @@ public class NamingGrpcResourceParserTest {
assertEquals("testG", actual.getGroup());
assertEquals(StringUtils.EMPTY, actual.getName());
assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(
com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
private AbstractNamingRequest mockNamingRequest(String testNs, String testG, String testS) {

View File

@ -45,6 +45,8 @@ public class Constants {
public static final String ANY = "*";
public static final String ACTION = "action";
public static final String REQUEST_CLASS = "requestClass";
}
public static class Identity {