Merge remote-tracking branch 'origin/main' into multi-tenant
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"be.ems/lib/global"
|
||||
"be.ems/lib/log"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
//"github.com/go-yaml-comment/yaml"
|
||||
//"github.com/goccy/go-yaml"
|
||||
)
|
||||
|
||||
// Yaml struct of config
|
||||
@@ -146,30 +150,47 @@ type DbConfig struct {
|
||||
Backup string `yaml:"backup"`
|
||||
}
|
||||
|
||||
//type codingType int
|
||||
|
||||
const (
|
||||
// Short message data coding type
|
||||
CODING_UCS2 int = iota
|
||||
CODING_ASCII
|
||||
CODING_LATIN1
|
||||
CODING_NODEF
|
||||
)
|
||||
|
||||
type AlarmConfig struct {
|
||||
SplitEventAlarm bool `yaml:"splitEventAlarm"`
|
||||
ForwardAlarm bool `yaml:"forwardAlarm"`
|
||||
SMProxy string `yaml:"smProxy"`
|
||||
Email struct {
|
||||
Smtp string `yaml:"smtp"`
|
||||
Port uint16 `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
TlsSkipVerify bool `yaml:"tlsSkipVerify"`
|
||||
} `yaml:"email"`
|
||||
SplitEventAlarm bool `yaml:"splitEventAlarm"`
|
||||
//ForwardAlarm bool `yaml:"forwardAlarm"`
|
||||
|
||||
EmailForward struct {
|
||||
Enable bool `yaml:"enable" json:"enable"`
|
||||
EmailList string `yaml:"emailList" json:"emailList"`
|
||||
SMTP string `yaml:"smtp" json:"smtp"`
|
||||
Port uint16 `yaml:"port" json:"port"`
|
||||
User string `yaml:"user" json:"user"`
|
||||
Password string `yaml:"password" json:"password"`
|
||||
TLSSkipVerify bool `yaml:"tlsSkipVerify" json:"tlsSkipVerify"`
|
||||
} `yaml:"alarmEmailForward"`
|
||||
SMSCForward struct {
|
||||
Enable bool `yaml:"enable" json:"enable"`
|
||||
MobileList string `yaml:"mobileList" json:"mobileList"`
|
||||
SMSCAddr string `yaml:"smscAddr" json:"smscAddr"`
|
||||
SystemID string `yaml:"systemID" json:"systemID"`
|
||||
Password string `yaml:"password" json:"password"`
|
||||
SystemType string `yaml:"systemType" json:"systemType"`
|
||||
DataCoding int `yaml:"dataCoding" json:"dataCoding"`
|
||||
ServiceNumber string `yaml:"serviceNumber" json:"serviceNumber"`
|
||||
} `yaml:"alarmSMSForward"`
|
||||
SMS struct {
|
||||
ApiURL string `yaml:"apiURL"`
|
||||
AccessKeyID string `yaml:"AccessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
SignName string `yaml:"signName"`
|
||||
TemplateCode string `yaml:"templateCode"`
|
||||
} `yaml:"sms"`
|
||||
SMSC struct {
|
||||
Addr string `yaml:"addr"`
|
||||
SystemID string `yaml:"systemID"`
|
||||
Password string `yaml:"password"`
|
||||
SystemType string `yaml:"systemType"`
|
||||
} `yaml:"smsc"`
|
||||
} `yaml:"smsForward"`
|
||||
SMProxy string `yaml:"smProxy"`
|
||||
}
|
||||
|
||||
type MMLParam struct {
|
||||
@@ -218,6 +239,16 @@ type TestDataMap struct {
|
||||
|
||||
var yamlConfig YamlConfig = NewYamlConfig()
|
||||
|
||||
type YamlConfigFile struct {
|
||||
FilePath string `json:"filePath"`
|
||||
ConfigLines YamlConfig `json:"configLines"`
|
||||
OrignalLines []string `json:"orignalLines"`
|
||||
}
|
||||
|
||||
var YamlConfigInfo YamlConfigFile = YamlConfigFile{
|
||||
ConfigLines: NewYamlConfig(),
|
||||
}
|
||||
|
||||
// set default value for yaml config
|
||||
func NewYamlConfig() YamlConfig {
|
||||
return YamlConfig{
|
||||
@@ -237,6 +268,8 @@ func NewYamlConfig() YamlConfig {
|
||||
}
|
||||
|
||||
func ReadConfig(configFile string) {
|
||||
YamlConfigInfo.FilePath = configFile
|
||||
|
||||
yamlFile, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
fmt.Println("Read yaml config file error:", err)
|
||||
@@ -244,25 +277,97 @@ func ReadConfig(configFile string) {
|
||||
}
|
||||
// fmt.Println("yamlfile:", string(yamlFile))
|
||||
|
||||
err = yaml.Unmarshal(yamlFile, &yamlConfig)
|
||||
err = yaml.Unmarshal(yamlFile, &YamlConfigInfo.ConfigLines)
|
||||
if err != nil {
|
||||
fmt.Println("Unmarshal error:", err)
|
||||
os.Exit(3)
|
||||
}
|
||||
yamlConfig = YamlConfigInfo.ConfigLines
|
||||
|
||||
ReadOriginalConfig(configFile)
|
||||
}
|
||||
|
||||
func WriteYamlConfig(newConfigData YamlConfig, configFile string) {
|
||||
func ReadOriginalConfig(configFile string) {
|
||||
// 读取原始YAML文件
|
||||
inputFile, err := os.Open(configFile)
|
||||
if err != nil {
|
||||
fmt.Println("failed to open:", err)
|
||||
os.Exit(3)
|
||||
}
|
||||
defer inputFile.Close()
|
||||
|
||||
scanner := bufio.NewScanner(inputFile)
|
||||
for scanner.Scan() {
|
||||
YamlConfigInfo.OrignalLines = append(YamlConfigInfo.OrignalLines, scanner.Text())
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Println("failed to scanner:", err)
|
||||
os.Exit(3)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteOrignalConfig(configFile string, paramName string, paramData map[string]any) error {
|
||||
lines := YamlConfigInfo.OrignalLines
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, paramName) {
|
||||
for k, v := range paramData {
|
||||
// find the first line nearby the paramName
|
||||
for j := i + 1; j < len(lines); j++ {
|
||||
if strings.Contains(lines[j], k+":") {
|
||||
index := strings.Index(lines[j], k)
|
||||
// Determine the type of v
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
lines[j] = lines[j][:index] + fmt.Sprintf("%s: \"%s\"", k, v)
|
||||
// case int:
|
||||
// lines[j] = lines[j][:index] + fmt.Sprintf("%s: %d", k, v)
|
||||
// case float64:
|
||||
// lines[j] = lines[j][:index] + fmt.Sprintf("%s: %f", k, v)
|
||||
case bool:
|
||||
lines[j] = lines[j][:index] + fmt.Sprintf("%s: %t", k, v)
|
||||
default:
|
||||
lines[j] = lines[j][:index] + fmt.Sprintf("%s: %v", k, v)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// write back to yaml file
|
||||
outputFile, err := os.Create(configFile)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
defer outputFile.Close()
|
||||
|
||||
writer := bufio.NewWriter(outputFile)
|
||||
for _, line := range YamlConfigInfo.OrignalLines {
|
||||
writer.WriteString(line + "\n")
|
||||
}
|
||||
writer.Flush()
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteYamlConfig(newConfigData YamlConfig, configFile string) error {
|
||||
// 将配置转换回YAML数据
|
||||
newYamlData, err := yaml.Marshal(&newConfigData)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to marshal YAML: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 将新的YAML数据写入文件
|
||||
err = os.WriteFile(configFile, newYamlData, 0644)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write YAML file: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var mapYaml map[string]interface{}
|
||||
@@ -284,8 +389,28 @@ func ReadParamConfig(fileName string) *map[string]interface{} {
|
||||
return &mapYaml
|
||||
}
|
||||
|
||||
func UpdateStructFromMap(s any, updates map[string]any) {
|
||||
v := reflect.ValueOf(s).Elem()
|
||||
t := v.Type()
|
||||
|
||||
for key, value := range updates {
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.Tag.Get("json") == key {
|
||||
structField := v.FieldByName(field.Name)
|
||||
if structField.IsValid() && structField.CanSet() {
|
||||
if structField.Type() == reflect.TypeOf(value) {
|
||||
structField.Set(reflect.ValueOf(value))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetYamlConfig() *YamlConfig {
|
||||
return &yamlConfig
|
||||
return &YamlConfigInfo.ConfigLines
|
||||
}
|
||||
|
||||
func GetAuthFromConfig() interface{} {
|
||||
|
||||
@@ -38,29 +38,29 @@ webServer:
|
||||
database:
|
||||
type: mysql
|
||||
user: root
|
||||
password: 1000omc@kp!
|
||||
host: 127.0.0.1
|
||||
password: "1000omc@kp!"
|
||||
host: "127.0.0.1"
|
||||
port: 33066
|
||||
name: tenants_db
|
||||
connParam: charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True
|
||||
backup: d:/local.git/be.ems/restagent/database
|
||||
|
||||
# Redis 缓存数据,数据源声明全小写
|
||||
# Redis data cache
|
||||
redis:
|
||||
dataSource:
|
||||
# OMC系统使用库
|
||||
# OMC system db
|
||||
default:
|
||||
port: 6379 # Redis port
|
||||
host: "127.0.0.1" # Redis host
|
||||
password: "helloearth"
|
||||
db: 10 # Redis db_num
|
||||
# UDM网元用户库
|
||||
# UDM sub/auth db
|
||||
udmuser:
|
||||
port: 6379 # Redis port
|
||||
host: "127.0.0.1"
|
||||
password: "helloearth"
|
||||
db: 0 # Redis db_num
|
||||
# 多个数据源时可以用这个指定默认的数据源
|
||||
# used to specify the default data source for multiple data resourece
|
||||
defaultDataSourceName: "default"
|
||||
|
||||
# sleep: time delay for after write buffer (millisecond)
|
||||
@@ -77,6 +77,12 @@ mml:
|
||||
password: admin
|
||||
mmlHome: ./mmlhome
|
||||
|
||||
# Tracking configuration
|
||||
trace:
|
||||
enabled: true
|
||||
host: "172.16.5.100" # Fill in the specific IP address
|
||||
port: 33033
|
||||
|
||||
# NE config
|
||||
ne:
|
||||
user: omcuser
|
||||
@@ -123,29 +129,35 @@ omc:
|
||||
|
||||
# Alarm module setting
|
||||
# Forward interface:
|
||||
# TLS Skip verify: true/false
|
||||
# email/sms
|
||||
# smProxy: sms(Short Message Service)/smsc(SMS Centre)
|
||||
# dataCoding: 0:UCS2, 1:ASCII, 2:LATIN1
|
||||
alarm:
|
||||
forwardAlarm: false
|
||||
email:
|
||||
smtp: mail.agrandtech.com
|
||||
alarmEmailForward:
|
||||
enable: true
|
||||
emailList:
|
||||
smtp: mail.smtp.com
|
||||
port: 25
|
||||
user: smtpext@agrandtech.com
|
||||
user: smtpext@smtp.com
|
||||
password: "1000smtp@omc!"
|
||||
# TLS skip verify: true/false
|
||||
tlsSkipVerify: true
|
||||
smProxy: smsc
|
||||
alarmSMSForward:
|
||||
enable: true
|
||||
mobileList:
|
||||
smscAddr: "192.168.13.114:2775"
|
||||
systemID: "omc"
|
||||
password: "omc123"
|
||||
systemType: "UTRAN"
|
||||
dataCoding: 0
|
||||
serviceNumber: "OMC"
|
||||
sms:
|
||||
apiURL: http://smsc.xxx.com/
|
||||
accessKeyID: xxxx
|
||||
accessKeySecret: xxxx
|
||||
signName: xxx SMSC
|
||||
templateCode: 1000
|
||||
smsc:
|
||||
addr: "192.168.13.114:2775"
|
||||
systemID: "omc"
|
||||
password: "omc123"
|
||||
systemType: "UTRAN"
|
||||
smProxy: smsc
|
||||
|
||||
#User authorized information
|
||||
# crypt: mysql/md5/bcrypt
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Makefile for rest agent project
|
||||
|
||||
PROJECT = OMC
|
||||
VERSION = 2.2408.1
|
||||
VERSION = 2.2409.3
|
||||
PLATFORM = amd64
|
||||
ARMPLATFORM = aarch64
|
||||
BUILDDIR = ../../build
|
||||
|
||||
@@ -213,6 +213,12 @@ func main() {
|
||||
fmt.Println("dborm.initDbClient err:", err)
|
||||
os.Exit(4)
|
||||
}
|
||||
err = dborm.InitGormConnect(conf.Database.Type, conf.Database.User, conf.Database.Password,
|
||||
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam, true)
|
||||
if err != nil {
|
||||
fmt.Println("dborm.InitGormConnect err:", err)
|
||||
os.Exit(4)
|
||||
}
|
||||
err = fm.InitDbClient(conf.Database.Type, conf.Database.User, conf.Database.Password,
|
||||
conf.Database.Host, conf.Database.Port, conf.Database.Name, conf.Database.ConnParam)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user