refactor(report): initialize DB connection (#1186)

This commit is contained in:
Kota Kanbe
2021-03-02 06:34:46 +09:00
committed by GitHub
parent 3f2ac45d71
commit 1c4a12c4b7
5 changed files with 99 additions and 184 deletions

View File

@@ -14,9 +14,14 @@ import (
// VulnDictInterface is an interface of vulnsrc
type VulnDictInterface interface {
CheckHTTPHealth() error
Init()
Validate() error
IsFetchViaHTTP() bool
CheckHTTPHealth() error
GetName() string
GetType() string
GetURL() string
GetSQLite3Path() string
}
// VulnDict is a base struct of vuln dicts
@@ -33,6 +38,26 @@ type VulnDict struct {
SQLite3Path string `json:"-"`
}
// GetType returns type
func (cnf *VulnDict) GetType() string {
return cnf.Type
}
// GetName returns name
func (cnf *VulnDict) GetName() string {
return cnf.Name
}
// GetURL returns url
func (cnf *VulnDict) GetURL() string {
return cnf.URL
}
// GetSQLite3Path return the path of SQLite3
func (cnf *VulnDict) GetSQLite3Path() string {
return cnf.SQLite3Path
}
// Validate settings
func (cnf *VulnDict) Validate() error {
logging.Log.Infof("%s.type=%s, %s.url=%s, %s.SQLite3Path=%s",
@@ -48,6 +73,9 @@ func (cnf *VulnDict) Validate() error {
return xerrors.Errorf("SQLite3 path must be a *Absolute* file path. %s.SQLite3Path: %s",
cnf.Name, cnf.SQLite3Path)
}
if _, err := os.Stat(cnf.SQLite3Path); os.IsNotExist(err) {
logging.Log.Warnf("%s.SQLite3Path=%s file not found", cnf.Name, cnf.SQLite3Path)
}
case "mysql":
if cnf.URL == "" {
return xerrors.Errorf(`MySQL connection string is needed. %s.url="user:pass@tcp(localhost:3306)/dbname"`, cnf.Name)
@@ -70,6 +98,9 @@ func (cnf *VulnDict) Validate() error {
return nil
}
// Init the struct
func (cnf *VulnDict) Init() {}
func (cnf *VulnDict) setDefault(sqlite3Name string) {
if cnf.Type == "" {
cnf.Type = "sqlite3"