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

@@ -243,37 +243,14 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
r.ServerInfo(), pp.Sprintf("%s", c.Conf.Servers[r.ServerName]))
}
for _, cnf := range []c.VulnDictInterface{
dbclient, err := detector.NewDBClient(
&c.Conf.CveDict,
&c.Conf.OvalDict,
&c.Conf.Gost,
&c.Conf.Exploit,
&c.Conf.Metasploit,
} {
if err := cnf.Validate(); err != nil {
logging.Log.Errorf("Failed to validate VulnDict: %+v", err)
return subcommands.ExitFailure
}
if err := cnf.CheckHTTPHealth(); err != nil {
logging.Log.Errorf("Run as server mode before reporting: %+v", err)
return subcommands.ExitFailure
}
}
// TODO move into fillcveInfos
dbclient, locked, err := detector.NewDBClient(detector.DBClientConf{
CveDictCnf: c.Conf.CveDict,
OvalDictCnf: c.Conf.OvalDict,
GostCnf: c.Conf.Gost,
ExploitCnf: c.Conf.Exploit,
MetasploitCnf: c.Conf.Metasploit,
DebugSQL: c.Conf.DebugSQL,
})
if locked {
logging.Log.Errorf("SQLite3 is locked. Close other DB connections and try again. err: %+v", err)
return subcommands.ExitFailure
}
c.Conf.DebugSQL,
)
if err != nil {
logging.Log.Errorf("Failed to init DB Clients. err: %+v", err)
return subcommands.ExitFailure
@@ -284,7 +261,6 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
}
}()
// TODO pass conf by arg
if res, err = detector.Detect(*dbclient, res, dir); err != nil {
logging.Log.Errorf("%+v", err)
return subcommands.ExitFailure

View File

@@ -99,36 +99,14 @@ func (p *ServerCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
return subcommands.ExitUsageError
}
for _, cnf := range []c.VulnDictInterface{
dbclient, err := detector.NewDBClient(
&c.Conf.CveDict,
&c.Conf.OvalDict,
&c.Conf.Gost,
&c.Conf.Exploit,
&c.Conf.Metasploit,
} {
if err := cnf.Validate(); err != nil {
logging.Log.Errorf("Failed to validate VulnDict: %+v", err)
return subcommands.ExitFailure
}
if err := cnf.CheckHTTPHealth(); err != nil {
logging.Log.Errorf("Run as server mode before reporting: %+v", err)
return subcommands.ExitFailure
}
}
dbclient, locked, err := detector.NewDBClient(detector.DBClientConf{
CveDictCnf: c.Conf.CveDict,
OvalDictCnf: c.Conf.OvalDict,
GostCnf: c.Conf.Gost,
ExploitCnf: c.Conf.Exploit,
MetasploitCnf: c.Conf.Metasploit,
DebugSQL: c.Conf.DebugSQL,
})
if locked {
logging.Log.Errorf("SQLite3 is locked. Close other DB connections and try again: %+v", err)
return subcommands.ExitFailure
}
c.Conf.DebugSQL,
)
if err != nil {
logging.Log.Errorf("Failed to init DB Clients. err: %+v", err)
return subcommands.ExitFailure

View File

@@ -138,36 +138,14 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s
}
logging.Log.Infof("Loaded: %s", dir)
for _, cnf := range []c.VulnDictInterface{
dbclient, err := detector.NewDBClient(
&c.Conf.CveDict,
&c.Conf.OvalDict,
&c.Conf.Gost,
&c.Conf.Exploit,
&c.Conf.Metasploit,
} {
if err := cnf.Validate(); err != nil {
logging.Log.Errorf("Failed to validate VulnDict: %+v", err)
return subcommands.ExitFailure
}
if err := cnf.CheckHTTPHealth(); err != nil {
logging.Log.Errorf("Run as server mode before reporting: %+v", err)
return subcommands.ExitFailure
}
}
dbclient, locked, err := detector.NewDBClient(detector.DBClientConf{
CveDictCnf: c.Conf.CveDict,
OvalDictCnf: c.Conf.OvalDict,
GostCnf: c.Conf.Gost,
ExploitCnf: c.Conf.Exploit,
MetasploitCnf: c.Conf.Metasploit,
DebugSQL: c.Conf.DebugSQL,
})
if locked {
logging.Log.Errorf("SQLite3 is locked. Close other DB connections and try again: %+v", err)
return subcommands.ExitFailure
}
c.Conf.DebugSQL,
)
if err != nil {
logging.Log.Errorf("Failed to init DB Clients. err: %+v", err)
return subcommands.ExitFailure