Skip to content

Commit

Permalink
feat: support custom config.BaseSecretKeyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok committed Jul 11, 2024
1 parent 6f61e6a commit aa90e97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func readConfig() (*MainConf, error) {

func parseSYSConfig(cfg *MainConf) error {
// 基础密钥: 由程序固化的密钥解密环境变量得到, 其他加密变量都使用基础密码加密
cfg.SYSConf.BaseSecretValue = xcrypto.GetenvDecrypt(BaseSecretEnvName, BaseSecretSalt+AppName)
cfg.SYSConf.BaseSecretValue = xcrypto.GetenvDecrypt(BaseSecretEnvName, BaseSecretKeyValue)
if cfg.SYSConf.BaseSecretValue == "" {
return fmt.Errorf("%s cannot be empty", BaseSecretEnvName)
}
Expand Down
4 changes: 4 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ var (
// BaseSecretSaltEnvName 环境变量中读取上一行设置的值的键名, 而不是使用上一行中设置的固定值
BaseSecretSaltEnvName = "BASE_SECRET_SALT"

// BaseSecretKeyValue 用于解密基础密钥的完整密钥, 默认为: 上面的盐 + AppName 值
// 可由应用自行指定该值以跳过上面的规则, 如在 main.go 中: config.BaseSecretKeyValue = "我的基础密钥解密KEY值"
BaseSecretKeyValue string

// WatcherIntervalDuration 文件变化监控时间间隔
WatcherIntervalDuration = 2 * time.Minute

Expand Down
5 changes: 5 additions & 0 deletions config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ func loadEnvConfig() {
_ = os.Setenv(DebNameEnvName, "")
DebName = s
}

// 应用指定的基础密钥解密 KEY 优先, 默认使用: 盐+AppName
if BaseSecretKeyValue == "" {
BaseSecretKeyValue = BaseSecretSalt + AppName
}
}

0 comments on commit aa90e97

Please sign in to comment.