This commit is contained in:
anlicheng 2026-05-09 12:48:52 +08:00
parent 05eef80903
commit 4c9b309b19
2 changed files with 38 additions and 27 deletions

View File

@ -33,7 +33,6 @@
`command``command_response``Domain` 表示业务域,目前支持:
- `auth`
- `container`
## 鉴权请求
@ -52,37 +51,19 @@
```erlang
{response, Ref, {auth_response, ok}}
{response, Ref, {auth_response, {error, {denied, Reason}}}}
{response, Ref, {auth_response, {error, {failed, Reason}}}}
```
处理语义:
- `ok``efka` 进入 `activated` 状态。
- `{error, {denied, Reason}}``efka` 进入 `restricted` 状态,不能正常上报数据,但仍可接收部分命令。
- `{error, {failed, Reason}}`:鉴权失败,连接关闭后重连。
## 授权控制命令
## 授权控制
`iot` 对 `efka` 的授权控制使用 command 语义:
`/host/activate` 只修改 `iot` 本地和持久化的 host 授权状态,不再向 `efka` 下发 auth command。`efka` 可以继续保持连接并发送数据,是否处理这些数据由 `iot_host` 当前状态决定。
```erlang
{command, Ref, {auth, activate}}
{command, Ref, {auth, deactivate}}
```
`efka` 回复:
```erlang
{command_response, Ref, {auth, ok}}
{command_response, Ref, {auth, {error, Reason}}}
```
处理语义:
- `activate`:如果 `efka` 已经是 `activated`,直接回复 `ok`;否则重新发送 `auth_request`,等待鉴权结果后再回复该 command。
- `deactivate``efka` 进入 `restricted` 状态,并回复 `ok`
- `iot` 侧会异步提交 auth command 并等待对应 `Ref``command_response`,再向 `/host/activate` HTTP 调用方返回结果;等待超时为 10 秒,超时返回 `timeout`,无效响应返回 `invalid response`
因此当前协议没有 `{command, Ref, {auth, ...}}``{command_response, Ref, {auth, ...}}`。授权关闭时,`iot_host` 保持 channel 在线,但不处理上报数据;授权重新打开后,已在线的 channel 可以继续使用。
## 容器管理命令
@ -252,5 +233,6 @@ ok
- 旧容器管理:`{request, Ref, {container_request, ...}}`
- 旧容器回复:`{response, Ref, {container_response, ...}}`
- 旧授权控制:`{message, {auth_control, Command}}`
- 已移除的 auth command`{command, Ref, {auth, activate | deactivate}}`
如果需要滚动升级,应先增加临时兼容分支或引入协议版本协商。

View File

@ -133,7 +133,36 @@ POST /change_host_status
---
### 5. 获取主机下的设备列表
### 5. 修改主机授权状态
**接口:**
```
POST /change_host_authorize_status
```
**请求体:**
```json
{
"uuid": "uuid-1",
"new_authorize_status": 1
}
```
`new_authorize_status``1` 表示允许 `iot_host` 处理该 host 的上报数据,为 `0` 表示保持连接但不处理上报数据。
**返回示例:**
```json
{
"result": "ok"
}
```
---
### 6. 获取主机下的设备列表
**接口:**
@ -162,7 +191,7 @@ GET /get_host_devices?host_id=<id>
## 🔧 设备Device相关接口
### 6. 获取设备详情
### 7. 获取设备详情
**接口:**
@ -190,7 +219,7 @@ GET /get_device_by_uuid?device_uuid=<uuid>
---
### 7. 修改设备状态
### 8. 修改设备状态
**接口:**
@ -219,7 +248,7 @@ POST /change_device_status
## 🌐 Endpoint数据终端相关接口
### 8. 获取所有 Endpoint
### 9. 获取所有 Endpoint
**接口:**
@ -312,7 +341,7 @@ GET /get_all_endpoints
---
### 9. 获取指定 Endpoint 信息
### 10. 获取指定 Endpoint 信息
**接口:**