chore: 使用环境变量管理内部密钥

This commit is contained in:
zxr
2026-08-04 15:48:59 +08:00
parent 8495fdf039
commit db3cb24b4e
3 changed files with 76 additions and 69 deletions

View File

@@ -23,9 +23,9 @@ Ingest:
AlertForward:
enabled: true
base_url: https://ops-api.apinb.com
internal_key: "ops-alert"
internal_key: ${LOGS_ALERT_SECRET}
default_policy_id: 0
ResourceEvent:
hmac_secret: "replace-with-dc-control-shared-secret"
hmac_secret: ${DC_CONTROL_LOGS_EVENT_SECRET}
max_skew_secs: 300

View File

@@ -23,9 +23,9 @@ Ingest:
AlertForward:
enabled: true
base_url: https://ops-api.apinb.com
internal_key: "ops-alert"
internal_key: ${LOGS_ALERT_SECRET}
default_policy_id: 0
ResourceEvent:
hmac_secret: "replace-with-dc-control-shared-secret"
hmac_secret: ${DC_CONTROL_LOGS_EVENT_SECRET}
max_skew_secs: 300

View File

@@ -2,6 +2,7 @@ package config
import (
"net"
"strings"
"git.apinb.com/bsm-sdk/core/conf"
)
@@ -46,6 +47,12 @@ func New(srvKey string) {
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
conf.NotNil(Spec.Service, Spec.Cache)
Spec.ResourceEvent.HMACSecret = strings.TrimSpace(Spec.ResourceEvent.HMACSecret)
conf.NotNil(Spec.Service, Spec.Cache, Spec.ResourceEvent.HMACSecret)
if Spec.AlertForward != nil && Spec.AlertForward.Enabled {
Spec.AlertForward.BaseURL = strings.TrimSpace(Spec.AlertForward.BaseURL)
Spec.AlertForward.InternalKey = strings.TrimSpace(Spec.AlertForward.InternalKey)
conf.NotNil(Spec.AlertForward.BaseURL, Spec.AlertForward.InternalKey)
}
conf.PrintInfo(Spec.Addr)
}