Validate validates the database config entry
()
| 538 | |
| 539 | // Validate validates the database config entry |
| 540 | func (d *Database) Validate() error { |
| 541 | if d.DbBackend == "" { |
| 542 | return fmt.Errorf("invalid databse configuration: backend is required") |
| 543 | } |
| 544 | |
| 545 | if len(d.Passphrase) != 32 { |
| 546 | return fmt.Errorf("passphrase must be set and it must be a string of 32 characters (aes 256)") |
| 547 | } |
| 548 | |
| 549 | passwordStenght := zxcvbn.PasswordStrength(d.Passphrase, nil) |
| 550 | if passwordStenght.Score < 4 { |
| 551 | return fmt.Errorf("database passphrase is too weak") |
| 552 | } |
| 553 | |
| 554 | switch d.DbBackend { |
| 555 | case MySQLBackend: |
| 556 | if err := d.MySQL.Validate(); err != nil { |
| 557 | return fmt.Errorf("validating mysql config: %w", err) |
| 558 | } |
| 559 | case SQLiteBackend: |
| 560 | if err := d.SQLite.Validate(); err != nil { |
| 561 | return fmt.Errorf("validating sqlite3 config: %w", err) |
| 562 | } |
| 563 | default: |
| 564 | return fmt.Errorf("invalid database backend: %s", d.DbBackend) |
| 565 | } |
| 566 | return nil |
| 567 | } |
| 568 | |
| 569 | // SQLite is the config entry for the sqlite3 section |
| 570 | type SQLite struct { |