// ValidateOnTui validates configuration func (c Config) ValidateOnTui() bool { errs := []error{} if len(c.ResultsDir) != 0 { if ok, _ := valid.IsFilePath(c.ResultsDir); !ok { errs = append(errs, fmt.Errorf( "JSON base directory must be a *Absolute* file path. -results-dir: %s", c.ResultsDir)) } } if c.CveDBType != "sqlite3" && c.CveDBType != "mysql" { errs = append(errs, fmt.Errorf( "CVE DB type must be either 'sqlite3' or 'mysql'. -cve-dictionary-dbtype: %s", c.CveDBType)) } if c.CveDBType == "sqlite3" { if ok, _ := valid.IsFilePath(c.CveDBPath); !ok { errs = append(errs, fmt.Errorf( "SQLite3 DB(CVE-Dictionary) path must be a *Absolute* file path. -cve-dictionary-dbpath: %s", c.CveDBPath)) } } for _, err := range errs { log.Error(err) } return len(errs) == 0 }
// ValidateOnReport validates configuration func (c Config) ValidateOnReport() bool { errs := []error{} if len(c.ResultsDir) != 0 { if ok, _ := valid.IsFilePath(c.ResultsDir); !ok { errs = append(errs, fmt.Errorf( "JSON base directory must be a *Absolute* file path. -results-dir: %s", c.ResultsDir)) } } if c.CveDBType != "sqlite3" && c.CveDBType != "mysql" { errs = append(errs, fmt.Errorf( "CVE DB type must be either 'sqlite3' or 'mysql'. -cve-dictionary-dbtype: %s", c.CveDBType)) } if c.CveDBType == "sqlite3" { if ok, _ := valid.IsFilePath(c.CveDBPath); !ok { errs = append(errs, fmt.Errorf( "SQLite3 DB(CVE-Dictionary) path must be a *Absolute* file path. -cve-dictionary-dbpath: %s", c.CveDBPath)) } } _, err := valid.ValidateStruct(c) if err != nil { errs = append(errs, err) } if mailerrs := c.EMail.Validate(); 0 < len(mailerrs) { errs = append(errs, mailerrs...) } if slackerrs := c.Slack.Validate(); 0 < len(slackerrs) { errs = append(errs, slackerrs...) } for _, err := range errs { log.Error(err) } return len(errs) == 0 }
// ValidateOnScan validates configuration func (c Config) ValidateOnScan() bool { errs := []error{} if len(c.ResultsDir) != 0 { if ok, _ := valid.IsFilePath(c.ResultsDir); !ok { errs = append(errs, fmt.Errorf( "JSON base directory must be a *Absolute* file path. -results-dir: %s", c.ResultsDir)) } } if runtime.GOOS == "windows" && c.SSHExternal { errs = append(errs, fmt.Errorf("-ssh-external cannot be used on windows")) } if len(c.ResultsDir) != 0 { if ok, _ := valid.IsFilePath(c.ResultsDir); !ok { errs = append(errs, fmt.Errorf( "JSON base directory must be a *Absolute* file path. -results-dir: %s", c.ResultsDir)) } } if len(c.CacheDBPath) != 0 { if ok, _ := valid.IsFilePath(c.CacheDBPath); !ok { errs = append(errs, fmt.Errorf( "Cache DB path must be a *Absolute* file path. -cache-dbpath: %s", c.CacheDBPath)) } } _, err := valid.ValidateStruct(c) if err != nil { errs = append(errs, err) } for _, err := range errs { log.Error(err) } return len(errs) == 0 }
// Validate configuration func (c Config) Validate() bool { errs := []error{} if len(c.DBPath) != 0 { if ok, _ := valid.IsFilePath(c.DBPath); !ok { errs = append(errs, fmt.Errorf( "SQLite3 DB path must be a *Absolute* file path. dbpath: %s", c.DBPath)) } } if len(c.CveDBPath) != 0 { if ok, _ := valid.IsFilePath(c.CveDBPath); !ok { errs = append(errs, fmt.Errorf( "SQLite3 DB(Cve Dictionary) path must be a *Absolute* file path. dbpath: %s", c.CveDBPath)) } } _, err := valid.ValidateStruct(c) if err != nil { errs = append(errs, err) } if mailerrs := c.Mail.Validate(); 0 < len(mailerrs) { errs = append(errs, mailerrs...) } if slackerrs := c.Slack.Validate(); 0 < len(slackerrs) { errs = append(errs, slackerrs...) } for _, err := range errs { log.Error(err) } return len(errs) == 0 }
func (s *service) IsFilePath(str string) (bool, int) { return gov.IsFilePath(str) }