Files
allinssl/backend/internal/cert/deploy/webhook/deploy.go
v-me-50 6d0732fc31 【修复】长期持有tcp连接未关闭
【新增】支持通过webhook调用自己的服务解析dns记录
【新增】支持通过webhook推送证书和密钥
【新增】导入导出工作流、通知、证书、api授权数据
【新增】支持自定义插件目录
2025-08-14 16:41:29 +08:00

58 lines
1.3 KiB
Go
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.

package webhook
import (
"ALLinSSL/backend/internal/access"
"ALLinSSL/backend/public"
"encoding/json"
"fmt"
"strconv"
)
func Deploy(cfg map[string]any) error {
cert, ok := cfg["certificate"].(map[string]any)
if !ok {
return fmt.Errorf("证书不存在")
}
var providerID string
switch v := cfg["provider_id"].(type) {
case float64:
providerID = strconv.Itoa(int(v))
case string:
providerID = v
default:
return fmt.Errorf("参数错误provider_id")
}
//
providerData, err := access.GetAccess(providerID)
if err != nil {
return err
}
providerConfigStr, ok := providerData["config"].(string)
if !ok {
return fmt.Errorf("api配置错误")
}
// 解析 JSON 配置
var providerConfig public.WebhookConfig
err = json.Unmarshal([]byte(providerConfigStr), &providerConfig)
if err != nil {
return err
}
certStr, ok := cert["cert"].(string)
if !ok || certStr == "" {
return fmt.Errorf("cert is required and must be a string")
}
keyStr, ok := cert["key"].(string)
if !ok || keyStr == "" {
return fmt.Errorf("key is required and must be a string")
}
data, err := public.ReplaceJSONPlaceholders(providerConfig.Data, map[string]interface{}{"key": keyStr, "cert": certStr})
if err != nil {
return fmt.Errorf("替换JSON占位符失败: %w", err)
}
providerConfig.Data = data
return providerConfig.Send()
}