Files
be.ems/src/modules/network_element/fetch_link/udm.go
2024-07-19 15:40:36 +08:00

37 lines
984 B
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 fetchlink
import (
"encoding/json"
"fmt"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/fetch"
)
// UDMImportAuth UDM导入鉴权数据
//
// data参数 {path:"服务器文件路径", k4:"可选k4为空时Ki不加密。"}
func UDMImportAuth(udmIP string, data map[string]any) (string, error) {
// 网元参数配置新增array
neUrl := fmt.Sprintf("http://%s:8080/ue-manage/v1/import-auth", udmIP)
resBytes, err := fetch.PostJSON(neUrl, data, nil)
var resData map[string]string
if err != nil {
errStr := err.Error()
logger.Warnf("UDMImportAuth Post \"%s\"", neUrl)
logger.Errorf("UDMImportAuth %s", errStr)
return "", fmt.Errorf("NeService UDM API Error")
}
// 序列化结果
err = json.Unmarshal(resBytes, &resData)
if err != nil {
logger.Errorf("UDMImportAuth Unmarshal %s", err.Error())
return "", err
}
if v, ok := resData["code"]; ok && v == "00000" {
return "ok", nil
}
return "", fmt.Errorf(resData["message"])
}