mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-08-31 01:39:47 +08:00
refactor(auth): drop tenant from registry resources
This commit is contained in:
@@ -39,15 +39,12 @@ message GrpcSyncRequest {
|
||||
// Owning service name, e.g. dc3-center-manager. Must be stable across restarts.
|
||||
string service_name = 1;
|
||||
|
||||
// Tenant ID the resources are registered under. Use 0 for system-level resources.
|
||||
int64 tenant_id = 2;
|
||||
|
||||
// When true, endpoints that exist in the DB but are absent from the current scan
|
||||
// are soft-deleted (deleted=1). When false, such endpoints are left untouched.
|
||||
bool delete_missing = 3;
|
||||
bool delete_missing = 2;
|
||||
|
||||
// Complete list of endpoints discovered by the registrar on the calling service.
|
||||
repeated GrpcScannedApiDTO apis = 4;
|
||||
repeated GrpcScannedApiDTO apis = 3;
|
||||
}
|
||||
|
||||
// A single scanned HTTP endpoint.
|
||||
|
||||
+10
-16
@@ -101,12 +101,11 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
throw new IllegalArgumentException("serviceName is required");
|
||||
}
|
||||
String serviceName = command.getServiceName();
|
||||
long tenantId = Objects.requireNonNullElse(command.getTenantId(), 0L);
|
||||
List<ResourceRegistryScannedApi> scanned = Objects.requireNonNullElse(command.getApis(), List.of());
|
||||
|
||||
resourceRegistryLockMapper.advisoryLock(serviceName);
|
||||
|
||||
Map<String, ApiDO> existingByCode = loadExisting(serviceName, tenantId);
|
||||
Map<String, ApiDO> existingByCode = loadExisting(serviceName);
|
||||
Map<String, ResourceRegistryScannedApi> scannedByCode = indexScanned(scanned, serviceName);
|
||||
|
||||
int inserted = 0;
|
||||
@@ -125,7 +124,7 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
ResourceRegistryScannedApi spec = entry.getValue();
|
||||
ApiDO existing = existingByCode.remove(apiCode);
|
||||
if (Objects.isNull(existing)) {
|
||||
ApiDO newApi = buildApiDO(spec, apiCode, serviceName, tenantId);
|
||||
ApiDO newApi = buildApiDO(spec, apiCode, serviceName);
|
||||
apisToInsert.add(newApi);
|
||||
continue;
|
||||
}
|
||||
@@ -140,7 +139,7 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
if (!apisToInsert.isEmpty()) {
|
||||
apiManager.saveBatch(apisToInsert);
|
||||
for (ApiDO api : apisToInsert) {
|
||||
resourcesToInsert.add(buildResourceDO(api, tenantId));
|
||||
resourcesToInsert.add(buildResourceDO(api));
|
||||
}
|
||||
resourceManager.saveBatch(resourcesToInsert);
|
||||
inserted = apisToInsert.size();
|
||||
@@ -149,12 +148,12 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
if (!apisToUpdate.isEmpty()) {
|
||||
apiManager.updateBatchById(apisToUpdate);
|
||||
Map<Long, ResourceDO> resourceByEntityId = loadResourcesByEntityIds(
|
||||
apisToUpdate.stream().map(ApiDO::getId).toList(), tenantId);
|
||||
apisToUpdate.stream().map(ApiDO::getId).toList());
|
||||
List<ResourceDO> resourcesToBackfill = new ArrayList<>();
|
||||
for (ApiDO api : apisToUpdate) {
|
||||
ResourceDO resourceDO = resourceByEntityId.get(api.getId());
|
||||
if (Objects.isNull(resourceDO)) {
|
||||
resourcesToBackfill.add(buildResourceDO(api, tenantId));
|
||||
resourcesToBackfill.add(buildResourceDO(api));
|
||||
} else {
|
||||
applyResourceUpdates(resourceDO, api);
|
||||
resourcesToUpdate.add(resourceDO);
|
||||
@@ -176,7 +175,6 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
apiManager.removeByIds(apiIdsToDelete);
|
||||
List<Long> resourceIds = resourceManager.list(Wrappers.<ResourceDO>lambdaQuery()
|
||||
.eq(ResourceDO::getResourceTypeFlag, ResourceTypeFlagEnum.API.getIndex())
|
||||
.eq(ResourceDO::getTenantId, tenantId)
|
||||
.in(ResourceDO::getEntityId, apiIdsToDelete))
|
||||
.stream().map(ResourceDO::getId).toList();
|
||||
if (!resourceIds.isEmpty()) {
|
||||
@@ -196,10 +194,9 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
.build();
|
||||
}
|
||||
|
||||
private Map<String, ApiDO> loadExisting(String serviceName, long tenantId) {
|
||||
private Map<String, ApiDO> loadExisting(String serviceName) {
|
||||
List<ApiDO> existing = apiManager.list(Wrappers.<ApiDO>lambdaQuery()
|
||||
.eq(ApiDO::getServiceName, serviceName)
|
||||
.eq(ApiDO::getTenantId, tenantId));
|
||||
.eq(ApiDO::getServiceName, serviceName));
|
||||
Map<String, ApiDO> map = new HashMap<>(existing.size());
|
||||
for (ApiDO api : existing) {
|
||||
map.put(api.getApiCode(), api);
|
||||
@@ -207,13 +204,12 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<Long, ResourceDO> loadResourcesByEntityIds(List<Long> entityIds, long tenantId) {
|
||||
private Map<Long, ResourceDO> loadResourcesByEntityIds(List<Long> entityIds) {
|
||||
if (entityIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<ResourceDO> rows = resourceManager.list(Wrappers.<ResourceDO>lambdaQuery()
|
||||
.eq(ResourceDO::getResourceTypeFlag, ResourceTypeFlagEnum.API.getIndex())
|
||||
.eq(ResourceDO::getTenantId, tenantId)
|
||||
.in(ResourceDO::getEntityId, entityIds));
|
||||
Map<Long, ResourceDO> map = new HashMap<>(rows.size());
|
||||
for (ResourceDO row : rows) {
|
||||
@@ -231,7 +227,7 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
return map;
|
||||
}
|
||||
|
||||
private ApiDO buildApiDO(ResourceRegistryScannedApi spec, String apiCode, String serviceName, long tenantId) {
|
||||
private ApiDO buildApiDO(ResourceRegistryScannedApi spec, String apiCode, String serviceName) {
|
||||
ApiDO api = new ApiDO();
|
||||
api.setServiceName(serviceName);
|
||||
api.setApiTypeFlag(methodToTypeFlag(spec.getMethod()).getIndex());
|
||||
@@ -239,12 +235,11 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
api.setApiCode(apiCode);
|
||||
api.setApiExt(buildApiExt(spec));
|
||||
api.setEnableFlag(EnableFlagEnum.ENABLE.getIndex());
|
||||
api.setTenantId(tenantId);
|
||||
api.setRemark(Objects.requireNonNullElse(spec.getRemark(), ""));
|
||||
return api;
|
||||
}
|
||||
|
||||
private ResourceDO buildResourceDO(ApiDO api, long tenantId) {
|
||||
private ResourceDO buildResourceDO(ApiDO api) {
|
||||
ResourceDO resource = new ResourceDO();
|
||||
resource.setParentResourceId(0L);
|
||||
resource.setResourceName(api.getApiName());
|
||||
@@ -254,7 +249,6 @@ public class ResourceRegistrySyncServiceImpl implements ResourceRegistrySyncServ
|
||||
resource.setEntityId(api.getId());
|
||||
resource.setResourceExt(new JsonExt());
|
||||
resource.setEnableFlag(EnableFlagEnum.ENABLE.getIndex());
|
||||
resource.setTenantId(tenantId);
|
||||
resource.setRemark(Objects.requireNonNullElse(api.getRemark(), ""));
|
||||
return resource;
|
||||
}
|
||||
|
||||
-4
@@ -67,8 +67,4 @@ public class ApiBO extends BaseBO {
|
||||
*/
|
||||
private EnableFlagEnum enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
-4
@@ -78,8 +78,4 @@ public class MenuBO extends BaseBO {
|
||||
*/
|
||||
private EnableFlagEnum enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
-4
@@ -85,8 +85,4 @@ public class ResourceBO extends BaseBO {
|
||||
*/
|
||||
private EnableFlagEnum enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
-5
@@ -41,11 +41,6 @@ public class ResourceRegistrySyncCommand {
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* Tenant ID the resources are registered under. Use 0 for system-level resources.
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* When true, endpoints that exist in the DB but are absent from the current scan
|
||||
* are soft-deleted. When false, such endpoints are left untouched.
|
||||
|
||||
-1
@@ -54,7 +54,6 @@ public interface ApiBuilder {
|
||||
* @param entityVO EntityVO
|
||||
* @return EntityBO
|
||||
*/
|
||||
@Mapping(target = "tenantId", ignore = true)
|
||||
ApiBO buildBOByVO(ApiVO entityVO);
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -55,7 +55,6 @@ public interface MenuBuilder {
|
||||
* @param entityVO EntityVO
|
||||
* @return EntityBO
|
||||
*/
|
||||
@Mapping(target = "tenantId", ignore = true)
|
||||
MenuBO buildBOByVO(MenuVO entityVO);
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -55,7 +55,6 @@ public interface ResourceBuilder {
|
||||
* @param entityVO EntityVO
|
||||
* @return EntityBO
|
||||
*/
|
||||
@Mapping(target = "tenantId", ignore = true)
|
||||
ResourceBO buildBOByVO(ResourceVO entityVO);
|
||||
|
||||
/**
|
||||
|
||||
-6
@@ -88,12 +88,6 @@ public class ApiDO implements Serializable {
|
||||
@TableField("enable_flag")
|
||||
private Byte enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
@TableField("tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
-6
@@ -100,12 +100,6 @@ public class MenuDO implements Serializable {
|
||||
@TableField("enable_flag")
|
||||
private Byte enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
@TableField("tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
-6
@@ -100,12 +100,6 @@ public class ResourceDO implements Serializable {
|
||||
@TableField("enable_flag")
|
||||
private Byte enableFlag;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
@TableField("tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
+1
-6
@@ -43,12 +43,7 @@ public class ApiQuery implements Serializable {
|
||||
|
||||
private Pages page;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Owning service name, populated by resource registrar
|
||||
|
||||
+1
-6
@@ -43,12 +43,7 @@ public class MenuQuery implements Serializable {
|
||||
|
||||
private Pages page;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Type
|
||||
|
||||
+1
-6
@@ -43,12 +43,7 @@ public class ResourceQuery implements Serializable {
|
||||
|
||||
private Pages page;
|
||||
|
||||
/**
|
||||
* Tenant ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Name
|
||||
|
||||
-1
@@ -67,7 +67,6 @@ public class ResourceRegistryServer extends ResourceRegistryApiGrpc.ResourceRegi
|
||||
try {
|
||||
ResourceRegistrySyncCommand command = ResourceRegistrySyncCommand.builder()
|
||||
.serviceName(request.getServiceName())
|
||||
.tenantId(request.getTenantId())
|
||||
.deleteMissing(request.getDeleteMissing())
|
||||
.apis(toScannedApis(request.getApisList()))
|
||||
.build();
|
||||
|
||||
-2
@@ -120,7 +120,6 @@ public class ApiServiceImpl implements ApiService {
|
||||
wrapper.eq(StringUtils.isNotEmpty(entityQuery.getServiceName()), ApiDO::getServiceName, entityQuery.getServiceName());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getApiTypeFlag()), ApiDO::getApiTypeFlag, entityQuery.getApiTypeFlag());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getEnableFlag()), ApiDO::getEnableFlag, entityQuery.getEnableFlag());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getTenantId()), ApiDO::getTenantId, entityQuery.getTenantId());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -137,7 +136,6 @@ public class ApiServiceImpl implements ApiService {
|
||||
wrapper.eq(ApiDO::getApiTypeFlag, entityBO.getApiTypeFlag());
|
||||
wrapper.eq(ApiDO::getApiName, entityBO.getApiName());
|
||||
wrapper.eq(ApiDO::getApiCode, entityBO.getApiCode());
|
||||
wrapper.eq(ApiDO::getTenantId, entityBO.getTenantId());
|
||||
wrapper.last(QueryWrapperConstant.LIMIT_ONE);
|
||||
ApiDO one = apiManager.getOne(wrapper);
|
||||
if (Objects.isNull(one)) {
|
||||
|
||||
-2
@@ -120,7 +120,6 @@ public class MenuServiceImpl implements MenuService {
|
||||
private LambdaQueryWrapper<MenuDO> fuzzyQuery(MenuQuery entityQuery) {
|
||||
LambdaQueryWrapper<MenuDO> wrapper = Wrappers.<MenuDO>query().lambda();
|
||||
wrapper.like(StringUtils.isNotEmpty(entityQuery.getMenuName()), MenuDO::getMenuName, entityQuery.getMenuName());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getTenantId()), MenuDO::getTenantId, entityQuery.getTenantId());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -138,7 +137,6 @@ public class MenuServiceImpl implements MenuService {
|
||||
wrapper.eq(MenuDO::getMenuTypeFlag, entityBO.getMenuTypeFlag());
|
||||
wrapper.eq(MenuDO::getMenuName, entityBO.getMenuName());
|
||||
wrapper.eq(MenuDO::getMenuCode, entityBO.getMenuCode());
|
||||
wrapper.eq(MenuDO::getTenantId, entityBO.getTenantId());
|
||||
wrapper.last(QueryWrapperConstant.LIMIT_ONE);
|
||||
MenuDO one = menuManager.getOne(wrapper);
|
||||
if (Objects.isNull(one)) {
|
||||
|
||||
-2
@@ -115,7 +115,6 @@ public class ResourceServiceImpl implements ResourceService {
|
||||
wrapper.eq(StringUtils.isNotEmpty(entityQuery.getResourceCode()), ResourceDO::getResourceCode, entityQuery.getResourceCode());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getResourceTypeFlag()), ResourceDO::getResourceTypeFlag, entityQuery.getResourceTypeFlag());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getEnableFlag()), ResourceDO::getEnableFlag, entityQuery.getEnableFlag());
|
||||
wrapper.eq(Objects.nonNull(entityQuery.getTenantId()), ResourceDO::getTenantId, entityQuery.getTenantId());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -134,7 +133,6 @@ public class ResourceServiceImpl implements ResourceService {
|
||||
wrapper.eq(ResourceDO::getResourceTypeFlag, entityBO.getResourceTypeFlag());
|
||||
wrapper.eq(ResourceDO::getResourceScopeFlag, entityBO.getResourceScopeFlag());
|
||||
wrapper.eq(ResourceDO::getEntityId, entityBO.getEntityId());
|
||||
wrapper.eq(ResourceDO::getTenantId, entityBO.getTenantId());
|
||||
wrapper.last(QueryWrapperConstant.LIMIT_ONE);
|
||||
ResourceDO one = resourceManager.getOne(wrapper);
|
||||
if (Objects.isNull(one)) {
|
||||
|
||||
-2
@@ -37,8 +37,6 @@ public class FacadeResourceRegistrySyncCommandBO {
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
private boolean deleteMissing;
|
||||
|
||||
private List<FacadeScannedApiBO> apis;
|
||||
|
||||
-1
@@ -50,7 +50,6 @@ public class ResourceRegistryGrpcFacade implements ResourceRegistryFacade {
|
||||
public FacadeResourceRegistrySyncResultBO sync(FacadeResourceRegistrySyncCommandBO command) {
|
||||
GrpcSyncRequest.Builder request = GrpcSyncRequest.newBuilder()
|
||||
.setServiceName(Objects.requireNonNullElse(command.getServiceName(), ""))
|
||||
.setTenantId(Objects.requireNonNullElse(command.getTenantId(), 0L))
|
||||
.setDeleteMissing(command.isDeleteMissing());
|
||||
List<FacadeScannedApiBO> apis = command.getApis();
|
||||
if (apis != null) {
|
||||
|
||||
-1
@@ -68,7 +68,6 @@ public class ResourceRegistryLocalFacade implements ResourceRegistryFacade {
|
||||
public FacadeResourceRegistrySyncResultBO sync(FacadeResourceRegistrySyncCommandBO command) {
|
||||
ResourceRegistrySyncCommand cmd = ResourceRegistrySyncCommand.builder()
|
||||
.serviceName(command.getServiceName())
|
||||
.tenantId(command.getTenantId())
|
||||
.deleteMissing(command.isDeleteMissing())
|
||||
.apis(toScannedApis(command.getApis()))
|
||||
.build();
|
||||
|
||||
-1
@@ -17,7 +17,6 @@
|
||||
|
||||
package io.github.pnoker.common.init;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@@ -14,6 +14,5 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.boot.EnvironmentPostProcessor=\
|
||||
io.github.pnoker.common.config.ActiveGatewayProfileConfig
|
||||
|
||||
@@ -61,7 +61,7 @@ spring:
|
||||
- StripPrefix=2
|
||||
- Authentic
|
||||
# Data route for point value operations (requires authentication)
|
||||
- id: data_route
|
||||
- id: data_route
|
||||
uri: ${GATEWAY_ROUTE_DATA_URI:http://${CENTER_DATA_HOST:dc3-center-data}:8500}
|
||||
predicates:
|
||||
- Path=/api/v3/data/**
|
||||
|
||||
-1
@@ -76,7 +76,6 @@ public class ResourceRegistrar {
|
||||
List<FacadeScannedApiBO> apis = scanner.scan();
|
||||
FacadeResourceRegistrySyncCommandBO command = FacadeResourceRegistrySyncCommandBO.builder()
|
||||
.serviceName(serviceName)
|
||||
.tenantId(properties.getTenantId())
|
||||
.deleteMissing(properties.isDeleteMissing())
|
||||
.apis(apis)
|
||||
.build();
|
||||
|
||||
-5
@@ -45,11 +45,6 @@ public class ResourceRegistrarProperties {
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* Tenant ID to register under. 0 for system-level resources.
|
||||
*/
|
||||
private Long tenantId = 0L;
|
||||
|
||||
/**
|
||||
* When true, endpoints that exist in the DB but are absent from the current scan
|
||||
* are soft-deleted. Leave false in production to avoid accidental wipes during rolling
|
||||
|
||||
Reference in New Issue
Block a user