fix(instance): access_mode 值 read/readonly 不一致导致「读」实例被过滤
现象:instance-groups 里给 MySQL 实例授予「只读查询」权限后,
/queries 页面仍然选不到该实例,admin 也无法访问。
根因(枚举值前后端不一致):
前端 CreateInstanceForm「读」按钮写入 access_mode = "read"
后端 AccessibleInstances 只匹配 ["readwrite", "readonly"]
→ "read" 永远不命中,选了「读」的实例(MySQL)被过滤掉;
Redis 实例是 "readwrite" 所以恰好能查,掩盖了该 bug。
修复:后端 readonly 过滤增加 "read",兼容两种历史写法:
[]string{"readwrite", "readonly", "read"}
写过滤仍为 ["readwrite", "write"]("read" 实例正确地不能写)
验证(admin):
GET /instances/accessible?access_type=readonly → 5 个(含 MySQL id=5, access_mode=read)
GET /instances/accessible?access_type=write → 4 个(MySQL 正确排除)
镜像:lghost/opsxsql:latest + v0.1 = sha256:6b1a7121da71
This commit is contained in:
1 parent
f19a84f37e
commit
0427b87412
1 file changed
+5
-1
@@ -20,8 +20,12 @@ func AccessibleInstances(c *gin.Context) {
|
||||
if role == "admin" || role == "dba" {
|
||||
// admin/dba see all instances, filter by access_mode if needed
|
||||
query := model.DB.Order("id")
|
||||
// 注意:access_mode 存在两种历史写法——
|
||||
// 前端「读」按钮写入 "read"(CreateInstanceForm),
|
||||
// 另有 "readonly" 的历史值。两者都必须命中,否则选了「读」的实例
|
||||
// (尤其 MySQL)会被过滤掉,连 admin 都查不到。
|
||||
if accessType == "readonly" {
|
||||
query = query.Where("access_mode IN ? OR access_mode IS NULL", []string{"readwrite", "readonly"})
|
||||
query = query.Where("access_mode IN ? OR access_mode IS NULL", []string{"readwrite", "readonly", "read"})
|
||||
} else {
|
||||
query = query.Where("access_mode IN ? OR access_mode IS NULL", []string{"readwrite", "write"})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user