feat(钉钉通道): 支持仅使用 access_token 配置钉钉机器人
Motivation: 钉钉机器人的 webhook 前缀固定不变,要求用户填写完整 URL 冗余且容易出错。简化通道配置项,降低接入配置成本,同时保证存量配置不受影响。 Changes: * 钉钉通道配置改用 access_token,webhook 前缀由内部固定拼接 * 保留对旧 webhook_url 配置的兼容,access_token 存在时优先生效 * 新增 webhook 地址解析逻辑的单元测试,覆盖优先级与回退场景 * 同步更新 README、HTTP 请求示例及设计文档中的配置示例 * E2E 测试改用 E2E_DINGTALK_ACCESS_TOKEN 环境变量并按新格式创建通道
This commit is contained in:
@@ -33,23 +33,23 @@ type fixture struct {
|
||||
chEmail string
|
||||
}
|
||||
|
||||
func requireE2EEnv(t *testing.T) (base, adminKey, dingWebhook, dingSecret, barkURL, emailTo string) {
|
||||
func requireE2EEnv(t *testing.T) (base, adminKey, dingAccessToken, dingSecret, barkURL, emailTo string) {
|
||||
t.Helper()
|
||||
base = envOr("E2E_BASE_URL", "http://82.157.251.93:8080")
|
||||
adminKey = envOr("E2E_ADMIN_KEY", "admin-sk-change-me")
|
||||
dingWebhook = os.Getenv("E2E_DINGTALK_WEBHOOK")
|
||||
dingAccessToken = os.Getenv("E2E_DINGTALK_ACCESS_TOKEN")
|
||||
dingSecret = os.Getenv("E2E_DINGTALK_SECRET")
|
||||
barkURL = os.Getenv("E2E_BARK_URL")
|
||||
emailTo = os.Getenv("E2E_EMAIL_TO")
|
||||
if dingWebhook == "" || dingSecret == "" || barkURL == "" || emailTo == "" {
|
||||
t.Skip("missing E2E_DINGTALK_WEBHOOK / E2E_DINGTALK_SECRET / E2E_BARK_URL / E2E_EMAIL_TO")
|
||||
if dingAccessToken == "" || dingSecret == "" || barkURL == "" || emailTo == "" {
|
||||
t.Skip("missing E2E_DINGTALK_ACCESS_TOKEN / E2E_DINGTALK_SECRET / E2E_BARK_URL / E2E_EMAIL_TO")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setupFixture(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
base, adminKey, dingWebhook, dingSecret, barkURL, emailTo := requireE2EEnv(t)
|
||||
base, adminKey, dingAccessToken, dingSecret, barkURL, emailTo := requireE2EEnv(t)
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
suffix := fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
|
||||
@@ -81,7 +81,7 @@ func setupFixture(t *testing.T) *fixture {
|
||||
|
||||
ding := mustAdminJSON(t, client, base, adminKey, http.MethodPost, "/api/v1/channels", map[string]any{
|
||||
"name": f.chDing, "type": "dingtalk", "status": 1,
|
||||
"config": map[string]string{"webhook_url": dingWebhook, "secret": dingSecret},
|
||||
"config": map[string]string{"access_token": dingAccessToken, "secret": dingSecret},
|
||||
}, http.StatusCreated)
|
||||
f.dingID = intFrom(ding["id"])
|
||||
t.Cleanup(func() {
|
||||
@@ -288,7 +288,7 @@ func TestNotifyFlow_DisableRule(t *testing.T) {
|
||||
// TestNotifyFlow_DifferentTemplatesPerRule verifies rule→template binding:
|
||||
// same source, three events, each with a distinct template and a single channel.
|
||||
func TestNotifyFlow_DifferentTemplatesPerRule(t *testing.T) {
|
||||
base, adminKey, dingWebhook, dingSecret, barkURL, emailTo := requireE2EEnv(t)
|
||||
base, adminKey, dingAccessToken, dingSecret, barkURL, emailTo := requireE2EEnv(t)
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
suffix := fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
srcName := "e2e-mt-" + suffix
|
||||
@@ -320,7 +320,7 @@ func TestNotifyFlow_DifferentTemplatesPerRule(t *testing.T) {
|
||||
marker: "DING-TMPL",
|
||||
chName: "e2e-mtd-" + suffix,
|
||||
chType: "dingtalk",
|
||||
chCfg: map[string]any{"webhook_url": dingWebhook, "secret": dingSecret},
|
||||
chCfg: map[string]any{"access_token": dingAccessToken, "secret": dingSecret},
|
||||
tmpl: "DING-TMPL {{.symbol}} ding price={{.price}}",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user