37 lines
984 B
Go
37 lines
984 B
Go
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"])
|
||
}
|