mirror of
https://github.com/allinssl/allinssl.git
synced 2025-12-18 10:04:01 +08:00
兼容执行插件
This commit is contained in:
90
backend/internal/cert/deploy/plugin/deploy.go
Normal file
90
backend/internal/cert/deploy/plugin/deploy.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/internal/access"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CertDeployPlugin struct {
|
||||
Config map[string]any
|
||||
Key string
|
||||
Cert string
|
||||
}
|
||||
|
||||
func Deploy(cfg map[string]any) error {
|
||||
cert, ok := cfg["certificate"].(map[string]any)
|
||||
if !ok {
|
||||
return fmt.Errorf("证书不存在")
|
||||
}
|
||||
action, ok := cfg["action"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("操作类型错误:action")
|
||||
}
|
||||
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配置错误")
|
||||
}
|
||||
var providerConfig map[string]any
|
||||
err = json.Unmarshal([]byte(providerConfigStr), &providerConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("api配置解析错误:%v", err)
|
||||
}
|
||||
pluginName, ok := providerConfig["name"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("插件名称错误")
|
||||
}
|
||||
pluginConfig, ok := providerConfig["config"].(map[string]any)
|
||||
if !ok {
|
||||
return fmt.Errorf("插件配置错误")
|
||||
}
|
||||
pluginParams, ok := pluginConfig["params"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("插件参数错误:")
|
||||
}
|
||||
var paramsMap map[string]any
|
||||
err = json.Unmarshal([]byte(pluginParams), ¶msMap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("插件参数解析错误:%v", err)
|
||||
}
|
||||
// 合并插件配置和参数
|
||||
for k, v := range paramsMap {
|
||||
pluginConfig[k] = v
|
||||
}
|
||||
|
||||
// 设置证书
|
||||
keyPem, ok := cert["key"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("证书错误:key")
|
||||
}
|
||||
certPem, ok := cert["cert"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("证书错误:cert")
|
||||
}
|
||||
|
||||
params := map[string]any{
|
||||
"config": pluginConfig,
|
||||
"key": keyPem,
|
||||
"cert": certPem,
|
||||
}
|
||||
rep, err := CallPlugin(pluginName, action, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("调用插件失败:%v", err)
|
||||
}
|
||||
fmt.Println(rep)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user