mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-06-26 21:50:57 +07:00
update:Save default app info to config file when change was made in the UI
This commit is contained in:
parent
b2ddd6f395
commit
941c4765f8
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,3 +44,4 @@ dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-
|
|||||||
.env
|
.env
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
dist/metadata.json
|
dist/metadata.json
|
||||||
|
*.gz
|
||||||
|
@ -11,8 +11,7 @@ UserDataPath = /var/lib/casaos
|
|||||||
[oidc]
|
[oidc]
|
||||||
AuthServer = https://account.nextzenvn.com
|
AuthServer = https://account.nextzenvn.com
|
||||||
ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz
|
ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz
|
||||||
ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fP
|
ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fPi6B9IFe3aDBo8x
|
||||||
i6B9IFe3aDBo8x
|
|
||||||
AuthURL = https://account.nextzenvn.com/application/o/nextzenos/
|
AuthURL = https://account.nextzenvn.com/application/o/nextzenos/
|
||||||
CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback
|
CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback
|
||||||
|
|
||||||
|
Binary file not shown.
34
pkg/utils/config/config.go
Normal file
34
pkg/utils/config/config.go
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/KaySar12/NextZen-UserService/model"
|
"github.com/KaySar12/NextZen-UserService/model"
|
||||||
"github.com/KaySar12/NextZen-UserService/model/system_model"
|
"github.com/KaySar12/NextZen-UserService/model/system_model"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
"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/encryption"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/utils/file"
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/file"
|
||||||
"github.com/KaySar12/NextZen-UserService/service"
|
"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)})
|
model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
|
||||||
return
|
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" {
|
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"
|
filePath := config.AppInfo.UserDataPath + "/default"
|
||||||
if err := file.IsNotExistMkDir(filePath); err != nil {
|
if err := file.IsNotExistMkDir(filePath); err != nil {
|
||||||
c.JSON(common_err.SERVICE_ERROR,
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
@ -1664,11 +1684,19 @@ func PostUserCustomConf(c *gin.Context) {
|
|||||||
if response.StatusCode() != http.StatusOK {
|
if response.StatusCode() != http.StatusOK {
|
||||||
logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response))
|
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))})
|
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
|
* @description: delete user custom config
|
||||||
|
Loading…
Reference in New Issue
Block a user