-
Notifications
You must be signed in to change notification settings - Fork 207
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: add encrypted key api #1606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"` | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code you provided has been updated to remove the Here's what's changed:
No changes were made to the code structure or logic due to no apparent errors or issues being detected. No further modifications are needed at this point unless more specific issues need addressing. Therefore, there are no major differences or irregularities in current version of your service code snippet. If there are still minor adjustments that could improve performance or adhere better to best practices, feel free to ask for details on those areas! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ func RunForever(confPath string) { | |
gracefulStop := make(chan os.Signal, 1) | ||
signal.Notify(gracefulStop, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) | ||
jmsService := MustJMService() | ||
bootstrapWithJMService(jmsService) | ||
webSrv := httpd.NewServer(jmsService) | ||
sshSrv := sshd.NewSSHServer(jmsService) | ||
app := &Koko{ | ||
|
@@ -55,9 +56,31 @@ func RunForever(confPath string) { | |
func bootstrap() { | ||
i18n.Initial() | ||
logger.Initial() | ||
} | ||
|
||
func bootstrapWithJMService(jmsService *service.JMService) { | ||
updateEncryptConfigValue(jmsService) | ||
exchange.Initial() | ||
} | ||
|
||
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 runTasks(jmsService *service.JMService) { | ||
if config.GetConf().UploadFailedReplay { | ||
go uploadRemainReplay(jmsService) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, you haven't provided the actual code that needs to be checked for differences, improvements or optimizations. Please share the relevant sections of the code so I can assist with analyzing them. Here are general guidelines on how one might approach checking code:
Optimization Suggestion: Suggestions for code difference detection:
In summary, without specifics about what needs verification, it'll be hard to give accurate answers. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a slight difference between the two versions of the code you provided. The first version contains an empty string literal
SecretEncryptKey
which could lead to some unexpected behavior if used elsewhere. In this case, it's not specified what it means exactly in the context ofconfig
, so I would recommend using a more precise name instead (e.g., SecretEncryptionKey).Additionally, there was no previous implementation for RedisPassword being set in UpdateRedisPassword function.
This small refinement can help avoid any possible bugs or confusion related to these changes.