Debian Codegraph @

exporter/pwd_file.go

raw symbols SCIP
1 package exporter
2
3 import (
4 "encoding/json"
5 "os"
6
7 log "github.com/sirupsen/logrus"
8 )
9
10 // LoadPwdFile reads the redis password file and returns the password map
11 func LoadPwdFile(passwordFile string) (map[string]string, error) {
12 res := make(map[string]string)
13
14 log.Debugf("start load password file: %s", passwordFile)
15 bytes, err := os.ReadFile(passwordFile)
16 if err != nil {
17 log.Warnf("load password file failed: %s", err)
18 return nil, err
19 }
20 err = json.Unmarshal(bytes, &res)
21 if err != nil {
22 log.Warnf("password file format error: %s", err)
23 return nil, err
24 }
25
26 log.Infof("Loaded %d entries from %s", len(res), passwordFile)
27 for k := range res {
28 log.Debugf("%s", k)
29 }
30
31 return res, nil
32 }