Add offline option to scan and configtest (#588)
Add offline option to scan and configtest
This commit is contained in:
@@ -36,11 +36,14 @@ type ConfigtestCmd struct {
|
||||
logDir string
|
||||
askKeyPassword bool
|
||||
containersOnly bool
|
||||
deep bool
|
||||
sshNative bool
|
||||
httpProxy string
|
||||
timeoutSec int
|
||||
|
||||
fast bool
|
||||
offline bool
|
||||
deep bool
|
||||
|
||||
debug bool
|
||||
}
|
||||
|
||||
@@ -54,6 +57,8 @@ func (*ConfigtestCmd) Synopsis() string { return "Test configuration" }
|
||||
func (*ConfigtestCmd) Usage() string {
|
||||
return `configtest:
|
||||
configtest
|
||||
[-fast]
|
||||
[-offline]
|
||||
[-deep]
|
||||
[-config=/path/to/config.toml]
|
||||
[-log-dir=/path/to/log]
|
||||
@@ -88,6 +93,18 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) {
|
||||
"Ask ssh privatekey password before scanning",
|
||||
)
|
||||
|
||||
f.BoolVar(
|
||||
&p.fast,
|
||||
"fast",
|
||||
false,
|
||||
"Config test for online fast scan mode")
|
||||
|
||||
f.BoolVar(
|
||||
&p.offline,
|
||||
"offline",
|
||||
false,
|
||||
"Config test for offline scan mode")
|
||||
|
||||
f.BoolVar(&p.deep, "deep", false, "Config test for deep scan mode")
|
||||
|
||||
f.StringVar(
|
||||
@@ -137,7 +154,13 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
|
||||
c.Conf.SSHNative = p.sshNative
|
||||
c.Conf.HTTPProxy = p.httpProxy
|
||||
c.Conf.ContainersOnly = p.containersOnly
|
||||
|
||||
c.Conf.Fast = p.fast
|
||||
c.Conf.Offline = p.offline
|
||||
c.Conf.Deep = p.deep
|
||||
if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) {
|
||||
c.Conf.Fast = true
|
||||
}
|
||||
|
||||
var servernames []string
|
||||
if 0 < len(f.Args()) {
|
||||
|
||||
@@ -43,6 +43,8 @@ type ScanCmd struct {
|
||||
httpProxy string
|
||||
askKeyPassword bool
|
||||
containersOnly bool
|
||||
fast bool
|
||||
offline bool
|
||||
deep bool
|
||||
skipBroken bool
|
||||
sshNative bool
|
||||
@@ -61,6 +63,8 @@ func (*ScanCmd) Synopsis() string { return "Scan vulnerabilities" }
|
||||
func (*ScanCmd) Usage() string {
|
||||
return `scan:
|
||||
scan
|
||||
[-fast]
|
||||
[-offline]
|
||||
[-deep]
|
||||
[-config=/path/to/config.toml]
|
||||
[-results-dir=/path/to/results]
|
||||
@@ -134,6 +138,18 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) {
|
||||
"Ask ssh privatekey password before scanning",
|
||||
)
|
||||
|
||||
f.BoolVar(
|
||||
&p.fast,
|
||||
"fast",
|
||||
false,
|
||||
"Online fast scan mode.")
|
||||
|
||||
f.BoolVar(
|
||||
&p.offline,
|
||||
"offline",
|
||||
false,
|
||||
"Offline scan mode. Unable to get updatable packages information.")
|
||||
|
||||
f.BoolVar(
|
||||
&p.deep,
|
||||
"deep",
|
||||
@@ -163,7 +179,6 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) {
|
||||
|
||||
// Execute execute
|
||||
func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
|
||||
// Setup Logger
|
||||
c.Conf.Debug = p.debug
|
||||
c.Conf.LogDir = p.logDir
|
||||
@@ -231,9 +246,15 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
|
||||
c.Conf.SSHNative = p.sshNative
|
||||
c.Conf.HTTPProxy = p.httpProxy
|
||||
c.Conf.ContainersOnly = p.containersOnly
|
||||
c.Conf.Deep = p.deep
|
||||
c.Conf.SkipBroken = p.skipBroken
|
||||
|
||||
c.Conf.Fast = p.fast
|
||||
c.Conf.Offline = p.offline
|
||||
c.Conf.Deep = p.deep
|
||||
if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) {
|
||||
c.Conf.Fast = true
|
||||
}
|
||||
|
||||
util.Log.Info("Validating config...")
|
||||
if !c.Conf.ValidateOnScan() {
|
||||
return subcommands.ExitUsageError
|
||||
|
||||
Reference in New Issue
Block a user