MCPcopy Create free account
hub / github.com/cloudbase/garm / Validate

Method Validate

config/config.go:540–567  ·  view source on GitHub ↗

Validate validates the database config entry

()

Source from the content-addressed store, hash-verified

538
539// Validate validates the database config entry
540func (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
570type SQLite struct {

Callers 1

GormParamsMethod · 0.95

Calls 1

ValidateMethod · 0.45

Tested by

no test coverage detected