| 1289 | } |
| 1290 | |
| 1291 | func redactConfigAsStr(ctx context.Context, dbConfig string) (string, error) { |
| 1292 | var config map[string]*json.RawMessage |
| 1293 | err := base.JSONUnmarshal([]byte(dbConfig), &config) |
| 1294 | if err != nil { |
| 1295 | return "", err |
| 1296 | } |
| 1297 | redactedConfig := make(map[string]any, len(config)) |
| 1298 | for k, v := range config { |
| 1299 | if _, ok := config["password"]; ok { |
| 1300 | redactedConfig["password"] = base.RedactedStr |
| 1301 | } else if _, ok := config["users"]; ok { |
| 1302 | var users map[string]*auth.PrincipalConfig |
| 1303 | err := base.JSONUnmarshal(*v, &users) |
| 1304 | if err != nil { |
| 1305 | return "", err |
| 1306 | } |
| 1307 | for i := range users { |
| 1308 | if users[i].Password != nil && *users[i].Password != "" { |
| 1309 | users[i].Password = base.Ptr(base.RedactedStr) |
| 1310 | } |
| 1311 | } |
| 1312 | redactedConfig["users"] = users |
| 1313 | } else if _, ok := config["replications"]; ok { |
| 1314 | var replications map[string]*db.ReplicationConfig |
| 1315 | err := base.JSONUnmarshal(*v, &replications) |
| 1316 | if err != nil { |
| 1317 | return "", err |
| 1318 | } |
| 1319 | for i := range replications { |
| 1320 | replications[i] = replications[i].Redacted(ctx) |
| 1321 | } |
| 1322 | redactedConfig["replications"] = replications |
| 1323 | } else { |
| 1324 | redactedConfig[k] = v |
| 1325 | } |
| 1326 | } |
| 1327 | output, err := base.JSONMarshal(redactedConfig) |
| 1328 | if err != nil { |
| 1329 | return "", err |
| 1330 | } |
| 1331 | return string(output), nil |
| 1332 | } |
| 1333 | |
| 1334 | // DecodeAndSanitiseStartupConfig will sanitise a config from an io.Reader and unmarshal it into the given config parameter. |
| 1335 | func DecodeAndSanitiseStartupConfig(ctx context.Context, r io.Reader, config interface{}, disallowUnknownFields bool) (err error) { |