Chore (sqlstore): add validation and testing for repl config (#90683)

* add some validation and testing for repl cf
* connection strings are secrets
This commit is contained in:
Kristin Laemmert
2024-07-29 10:32:56 -04:00
committed by GitHub
parent d12cd4280c
commit af19f039b6
4 changed files with 121 additions and 15 deletions
+30
View File
@@ -235,3 +235,33 @@ func buildExtraConnectionString(sep rune, urlQueryParams map[string][]string) st
}
return sb.String()
}
func validateReplicaConfigs(primary *DatabaseConfig, cfgs []*DatabaseConfig) error {
if cfgs == nil {
return errors.New("cfg cannot be nil")
}
// Return multiple errors so we can fix them all at once!
var result error
// Check for duplicate connection strings
seen := make(map[string]struct{})
seen[primary.ConnectionString] = struct{}{}
for _, cfg := range cfgs {
if _, ok := seen[cfg.ConnectionString]; ok {
result = errors.Join(result, errors.New("duplicate connection string"))
} else {
seen[cfg.ConnectionString] = struct{}{}
}
}
// Verify that every database is the same type and version, and that it matches the primary database.
for _, cfg := range cfgs {
if cfg.Type != primary.Type {
result = errors.Join(result, fmt.Errorf("the replicas must have the same database type as the primary database (%s != %s)", primary.Type, cfg.Type))
break // Only need to report this once
}
}
return result
}