Chore: Remove public vars in setting package (#81018)

Removes the public variable setting.SecretKey plus some other ones. 
Introduces some new functions for creating setting.Cfg.
This commit is contained in:
Marcus Efraimsson
2024-01-23 12:36:22 +01:00
committed by GitHub
parent 147bf01745
commit 6768c6c059
131 changed files with 759 additions and 699 deletions
@@ -77,7 +77,7 @@ func (e externalAlertmanagerToDatasources) Exec(sess *xorm.Session, mg *migrator
ds.BasicAuth = true
ds.BasicAuthUser = u.User.Username()
if password, ok := u.User.Password(); ok {
ds.SecureJsonData = getEncryptedJsonData(map[string]string{
ds.SecureJsonData = getEncryptedJsonData(mg.Cfg, map[string]string{
"basicAuthPassword": password,
}, log.New("securejsondata"))
}
@@ -132,10 +132,10 @@ func generateNewDatasourceUid(sess *xorm.Session, orgId int64) (string, error) {
type secureJsonData map[string][]byte
// getEncryptedJsonData returns map where all keys are encrypted.
func getEncryptedJsonData(sjd map[string]string, log log.Logger) secureJsonData {
func getEncryptedJsonData(cfg *setting.Cfg, sjd map[string]string, log log.Logger) secureJsonData {
encrypted := make(secureJsonData)
for key, data := range sjd {
encryptedData, err := util.Encrypt([]byte(data), setting.SecretKey)
encryptedData, err := util.Encrypt([]byte(data), cfg.SecretKey)
if err != nil {
log.Error(err.Error())
os.Exit(1)