Files
ops-assistant/docs/debug/cf-dnsproxy-dnsadd-20260319.md
2026-03-19 21:23:28 +08:00

80 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CF DNS 命令修复与扩展记录2026-03-19
## 背景
用户要求:
- `/cf dnsproxy` 支持直接用域名,例如:`/cf dnsproxy ima.good.xx.kg on`
- `/cf dnsadd` 最后参数用 `on/off` 表示是否开启代理
线上报错:
- `yaml: line 8: did not find expected key`
- `/cf dnsproxy` 解析失败bash: bad substitution
## 改动概览
1) **命令解析**
- `internal/module/cf/commands.go`
- `/cf dnsproxy` 支持 `record_id|name`
- `/cf dnsadd` 支持 `on/off`(兼容 true/false当未提供 on/off 时把第4参数视为类型
2) **帮助文案**
- `internal/module/cf/module.go`
- `internal/core/ops/service.go`
- 更新 `/cf dnsadd``/cf dnsproxy` 的参数示例
3) **runbook 修复**
- `runbooks/cf_dns_proxy.yaml`
- 解决 YAML 行内命令渲染与变量替换问题
- 修复 `${env.INPUT_RECORD_ID}` 未替换导致 bash 报错
- 加入占位值 `__empty__`,避免空变量导致替换缺失
- `update_dns` 中 JSON 通过单引号包裹,避免 shell 分词/换行破坏
4) **ops-runner 支持**
- `cmd/ops-runner/main.go`
- 增加 `/cf dnsproxy` 支持
- `/cf dnsadd` 参数改为 on/off
## 问题与修复记录
### 1. YAML 解析错误
- 现象:`yaml: line 8: did not find expected key`
- 原因runbook 中 command 复杂引号/换行组合导致 YAML 解析失败
- 修复:重写 `cf_dns_proxy.yaml` command 区块
### 2. dnsproxy 变量替换失败
- 现象:`bash: ${env.INPUT_RECORD_ID}: bad substitution`
- 原因输入为空时没有替换占位shell 直接解析 `${env.INPUT_RECORD_ID}`
- 修复InputsFn 总是注入 `record_id/name` 占位值runbook 将 `__empty__` 转为空
### 3. dnsproxy update 失败JSON 被 shell 吞掉)
- 现象:`bash: line 1: true,: command not found`
- 原因:`${steps.resolve_dns.output}` 未加引号JSON 被 shell 拆分
- 修复:`INPUT_JSON='${steps.resolve_dns.output}'`
### 4. dnsadd on/off 支持
- 现象:`DNS record type "on" is invalid`
- 原因:解析逻辑未识别 on/off误当作类型
- 修复InputsFn 与 ops-runner 同步支持 `on/off`
### 5. 测试记录创建失败127.0.0.1
- 现象:`Target 127.0.0.1 is not allowed for a proxied record`
- 处理:改用公网 IP 199.188.198.12
## 测试结果
1) 新增测试记录
```
/cf dnsadd test001.good.xx.kg 199.188.198.12 on
```
- 成功创建proxied=true
2) 代理切换
```
/cf dnsproxy ima.good.xx.kg on
```
- 成功更新proxied=true
## 产物
- 修复代码与 runbook
- 版本化二进制输出dist/ 目录)
## 注意事项
- proxied=on 不能指向 127.0.0.1 等内网回环地址
- runbook command 中 JSON 建议统一使用单引号包裹