mirror of
https://github.com/Icinga/icingadb.git
synced 2026-06-09 08:56:54 -04:00
Merge pull request #477 from Icinga/feature/more-config-validation
Check for required database and Redis config options during config validation
This commit is contained in:
commit
da3fa88707
2 changed files with 21 additions and 1 deletions
|
|
@ -47,7 +47,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) {
|
|||
config.User = d.User
|
||||
config.Passwd = d.Password
|
||||
|
||||
if strings.HasPrefix(d.Host, "/") {
|
||||
if d.isUnixAddr() {
|
||||
config.Net = "unix"
|
||||
config.Addr = d.Host
|
||||
} else {
|
||||
|
|
@ -151,9 +151,25 @@ func (d *Database) Validate() error {
|
|||
return unknownDbType(d.Type)
|
||||
}
|
||||
|
||||
if d.Host == "" {
|
||||
return errors.New("database host missing")
|
||||
}
|
||||
|
||||
if d.User == "" {
|
||||
return errors.New("database user missing")
|
||||
}
|
||||
|
||||
if d.Database == "" {
|
||||
return errors.New("database name missing")
|
||||
}
|
||||
|
||||
return d.Options.Validate()
|
||||
}
|
||||
|
||||
func (d *Database) isUnixAddr() bool {
|
||||
return strings.HasPrefix(d.Host, "/")
|
||||
}
|
||||
|
||||
func unknownDbType(t string) error {
|
||||
return errors.Errorf(`unknown database type %q, must be one of: "mysql", "pgsql"`, t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,5 +103,9 @@ func dialWithLogging(dialer ctxDialerFunc, logger *logging.Logger) ctxDialerFunc
|
|||
|
||||
// Validate checks constraints in the supplied Redis configuration and returns an error if they are violated.
|
||||
func (r *Redis) Validate() error {
|
||||
if r.Address == "" {
|
||||
return errors.New("Redis address missing")
|
||||
}
|
||||
|
||||
return r.Options.Validate()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue