Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 获取加密的配置 #373

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,31 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo
}

func bootstrap(jmsService *service.JMService) {
updateEncryptConfigValue(jmsService)
replayDir := config.GlobalConfig.RecordPath
ftpFilePath := config.GlobalConfig.FTPFilePath
allRemainFiles := scanRemainReplay(jmsService, replayDir)
go uploadRemainReplay(jmsService, allRemainFiles)
go uploadRemainFTPFile(jmsService, ftpFilePath)
}

func updateEncryptConfigValue(jmsService *service.JMService) {
cfg := config.GlobalConfig
encryptKey := cfg.SecretEncryptKey
if encryptKey != "" {
redisPassword := cfg.RedisPassword
ret, err := jmsService.GetEncryptedConfigValue(encryptKey, redisPassword)
if err != nil {
logger.Error("Get encrypted config value failed: " + err.Error())
return
}
if ret.Value != "" {
cfg.UpdateRedisPassword(ret.Value)
} else {
logger.Error("Get encrypted config value failed: empty value")
}
}
}
func uploadRemainFTPFile(jmsService *service.JMService, fileStoreDir string) {
err := config.EnsureDirExist(fileStoreDir)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ type Config struct {
IgnoreVerifyCerts bool `mapstructure:"IGNORE_VERIFY_CERTS"`
PandaHost string `mapstructure:"PANDA_HOST"`
EnablePanda bool `mapstructure:"ENABLE_PANDA"`

SecretEncryptKey string `mapstructure:"SECRET_ENCRYPT_KEY"`
}

func (c *Config) UpdateRedisPassword(val string) {
c.RedisPassword = val
}

func (c *Config) SelectGuacdAddr() string {
Expand Down
14 changes: 14 additions & 0 deletions pkg/jms-sdk-go/service/jms_terminal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package service

func (s *JMService) GetEncryptedConfigValue(encryptKey, encryptedValue string) (resp ResultValue, err error) {
data := map[string]string{
"secret_encrypt_key": encryptKey,
"encrypted_value": encryptedValue,
}
_, err = s.authClient.Post(TerminalEncryptedConfigURL, data, &resp)
return
}

type ResultValue struct {
Value string `json:"value"`
}
2 changes: 2 additions & 0 deletions pkg/jms-sdk-go/service/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
TerminalRegisterURL = "/api/v1/terminal/terminal-registrations/" // 注册
TerminalConfigURL = "/api/v1/terminal/terminals/config/" // 获取配置
TerminalHeartBeatURL = "/api/v1/terminal/terminals/status/"

TerminalEncryptedConfigURL = "/api/v1/terminal/encrypted-config/"
)

// 用户登陆认证使用的API
Expand Down
Loading