diff --git a/.gitignore b/.gitignore index 171f672..8b2556d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user- .env .vscode/launch.json dist/metadata.json +*.gz diff --git a/build/sysroot/etc/casaos/user-service.conf.sample b/build/sysroot/etc/casaos/user-service.conf.sample index 5f985d1..a85b31c 100755 --- a/build/sysroot/etc/casaos/user-service.conf.sample +++ b/build/sysroot/etc/casaos/user-service.conf.sample @@ -11,8 +11,7 @@ UserDataPath = /var/lib/casaos [oidc] AuthServer = https://account.nextzenvn.com ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz -ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fP -i6B9IFe3aDBo8x +ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fPi6B9IFe3aDBo8x AuthURL = https://account.nextzenvn.com/application/o/nextzenos/ CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback diff --git a/linux-amd64-nextzenos-user-service.tar.gz b/linux-amd64-nextzenos-user-service.tar.gz deleted file mode 100644 index 500c7ce..0000000 Binary files a/linux-amd64-nextzenos-user-service.tar.gz and /dev/null differ diff --git a/pkg/utils/config/config.go b/pkg/utils/config/config.go new file mode 100644 index 0000000..159f946 --- /dev/null +++ b/pkg/utils/config/config.go @@ -0,0 +1,34 @@ +package config + +import ( + "fmt" + + "github.com/KaySar12/NextZen-UserService/pkg/config" + "gopkg.in/ini.v1" +) + +var ( + Cfg *ini.File +) + +func init() { + var err error + Cfg, err = ini.Load(config.UserServiceConfigFilePath) + if err != nil { + panic(err) + } +} +func WriteMapToConfig(configData map[string]string, section string) { + sectionData := Cfg.Section(section) + for key, value := range sectionData.KeysHash() { + if value != configData[key] { + sectionData.Key(key).SetValue(configData[key]) + } + } + err := Cfg.SaveTo(config.UserServiceConfigFilePath) + if err != nil { + fmt.Println("Failed to save file:", err) + return + } + +} diff --git a/route/v1/user.go b/route/v1/user.go index a1a06e0..dabdddb 100644 --- a/route/v1/user.go +++ b/route/v1/user.go @@ -31,6 +31,7 @@ import ( "github.com/KaySar12/NextZen-UserService/model" "github.com/KaySar12/NextZen-UserService/model/system_model" "github.com/KaySar12/NextZen-UserService/pkg/config" + cfg "github.com/KaySar12/NextZen-UserService/pkg/utils/config" "github.com/KaySar12/NextZen-UserService/pkg/utils/encryption" "github.com/KaySar12/NextZen-UserService/pkg/utils/file" "github.com/KaySar12/NextZen-UserService/service" @@ -1626,8 +1627,27 @@ func PostUserCustomConf(c *gin.Context) { model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)}) return } - data, _ := io.ReadAll(c.Request.Body) + data, err := io.ReadAll(c.Request.Body) + if err != nil { + logger.Error("Failed to read request body", zap.Error(err)) + c.JSON(common_err.SERVICE_ERROR, model.Result{ + Success: common_err.SERVICE_ERROR, + Message: common_err.GetMsg(common_err.SERVICE_ERROR), + }) + return + } if name == "default-app" { + var appInfos []model.AppInfo + err := json.Unmarshal([]byte(data), &appInfos) + if err != nil { + c.JSON(common_err.SERVICE_ERROR, + model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)}) + return + } + go func() { + configData := formatAppInfosToMap(appInfos) + cfg.WriteMapToConfig(configData, name) + }() filePath := config.AppInfo.UserDataPath + "/default" if err := file.IsNotExistMkDir(filePath); err != nil { c.JSON(common_err.SERVICE_ERROR, @@ -1664,11 +1684,19 @@ func PostUserCustomConf(c *gin.Context) { if response.StatusCode() != http.StatusOK { logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response)) } - } c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))}) } +func formatAppInfosToMap(appInfos []model.AppInfo) map[string]string { + formattedMap := make(map[string]string) + for _, appInfo := range appInfos { + formattedString := fmt.Sprintf("%s-%s-%s-%s-%s", + appInfo.Name, appInfo.Hostname, appInfo.Icon, appInfo.AppType, appInfo.Status) + formattedMap[appInfo.Name] = formattedString + } + return formattedMap +} /** * @description: delete user custom config