feat(center-nodes): enforce nodeId and endpoint uniqueness
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
|
ConflictException,
|
||||||
Controller,
|
Controller,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
Get,
|
Get,
|
||||||
@@ -23,6 +24,20 @@ export class NodesController {
|
|||||||
throw new ForbiddenException('invalid shared secret');
|
throw new ForbiddenException('invalid shared secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const existedByNodeId = await this.nodeRepo.findOne({
|
||||||
|
where: { nodeId: body.nodeId },
|
||||||
|
});
|
||||||
|
if (existedByNodeId) {
|
||||||
|
throw new ConflictException('nodeId already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existedByEndpoint = await this.nodeRepo.findOne({
|
||||||
|
where: { endpoint: body.endpoint },
|
||||||
|
});
|
||||||
|
if (existedByEndpoint) {
|
||||||
|
throw new ConflictException('endpoint already exists');
|
||||||
|
}
|
||||||
|
|
||||||
const node = this.nodeRepo.create({
|
const node = this.nodeRepo.create({
|
||||||
nodeId: body.nodeId,
|
nodeId: body.nodeId,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
### 1.2 Guild Node 注册与握手
|
### 1.2 Guild Node 注册与握手
|
||||||
- [x] `POST /nodes/register` shared-secret 校验
|
- [x] `POST /nodes/register` shared-secret 校验
|
||||||
- [ ] node 唯一性校验(nodeId/endpoint)
|
- [x] node 唯一性校验(nodeId/endpoint)
|
||||||
- [ ] node 状态模型(active/offline/revoked)
|
- [ ] node 状态模型(active/offline/revoked)
|
||||||
- [ ] `GET /nodes` 列表 + 分页
|
- [ ] `GET /nodes` 列表 + 分页
|
||||||
- [ ] node 心跳接口(可选)
|
- [ ] node 心跳接口(可选)
|
||||||
|
|||||||
Reference in New Issue
Block a user