Skip to content

Commit

Permalink
Merge pull request #248 from future-architect/skip-broken
Browse files Browse the repository at this point in the history
Add -skip-broken option [CentOS only] #245
  • Loading branch information
kotakanbe authored Nov 7, 2016
2 parents f95af98 + 18a92fa commit e6ec692
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ scan:
[-ignore-unscored-cves]
[-ssh-external]
[-containers-only]
[-skip-broken]
[-report-azure-blob]
[-report-json]
[-report-mail]
Expand Down Expand Up @@ -686,6 +687,8 @@ scan:
Write report to XML files ($PWDresults/current)
-results-dir string
/path/to/results (default "$PWD/results")
-skip-broken
[For CentOS] yum update changelog with --skip-broken option
-ssh-external
Use external ssh command. Default: Use the Go native implementation
```
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ scan:
[-ignore-unscored-cves]
[-ssh-external]
[-containers-only]
[-skip-broken]
[-report-azure-blob]
[-report-json]
[-report-mail]
Expand Down Expand Up @@ -693,6 +694,8 @@ scan:
Write report to XML files ($PWDresults/current)
-results-dir string
/path/to/results (default "$PWD/results")
-skip-broken
[For CentOS] yum update changelog with --skip-broken option
-ssh-external
Use external ssh command. Default: Use the Go native implementation
```
Expand Down
11 changes: 10 additions & 1 deletion commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type ScanCmd struct {
askKeyPassword bool

containersOnly bool
skipBroken bool

// reporting
reportSlack bool
Expand Down Expand Up @@ -101,13 +102,14 @@ func (*ScanCmd) Usage() string {
[-ignore-unscored-cves]
[-ssh-external]
[-containers-only]
[-skip-broken]
[-report-azure-blob]
[-report-json]
[-report-mail]
[-report-s3]
[-report-slack]
[-report-text]
[-report-xml]
[-report-xml]
[-http-proxy=http://192.168.0.1:8080]
[-ask-key-password]
[-debug]
Expand Down Expand Up @@ -187,6 +189,12 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) {
false,
"Scan containers only. Default: Scan both of hosts and containers")

f.BoolVar(
&p.skipBroken,
"skip-broken",
false,
"[For CentOS] yum update changelog with --skip-broken option")

f.StringVar(
&p.httpProxy,
"http-proxy",
Expand Down Expand Up @@ -388,6 +396,7 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
c.Conf.SSHExternal = p.sshExternal
c.Conf.HTTPProxy = p.httpProxy
c.Conf.ContainersOnly = p.containersOnly
c.Conf.SkipBroken = p.skipBroken

Log.Info("Validating Config...")
if !c.Conf.Validate() {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {

SSHExternal bool
ContainersOnly bool
SkipBroken bool

HTTPProxy string `valid:"url"`
ResultsDir string
Expand Down Expand Up @@ -86,7 +87,6 @@ func (c Config) Validate() bool {
"CVE DB type must be either 'sqlite3' or 'mysql'. -cve-dictionary-dbtype: %s", c.CveDBType))
}


if c.CveDBType == "sqlite3" {
if len(c.CveDBPath) != 0 {
if ok, _ := valid.IsFilePath(c.CveDBPath); !ok {
Expand Down
12 changes: 8 additions & 4 deletions scan/redhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ func (o *redhat) checkDependencies() error {
return fmt.Errorf("Not implemented yet: %s", o.Distro)
}

var name = ""
var name = "yum-plugin-changelog"
if majorVersion < 6 {
name = "yum-changelog"
} else {
name = "yum-plugin-changelog"
}

cmd := "rpm -q " + name
Expand Down Expand Up @@ -548,7 +546,13 @@ func (o *redhat) getAllChangelog(packInfoList models.PackageInfoList) (stdout st
}

// yum update --changelog doesn't have --color option.
command += fmt.Sprintf(" LANGUAGE=en_US.UTF-8 yum update --changelog %s", packageNames)
if config.Conf.SkipBroken {
command += fmt.Sprintf(
" LANGUAGE=en_US.UTF-8 yum --skip-broken update --changelog %s", packageNames)
} else {
command += fmt.Sprintf(
" LANGUAGE=en_US.UTF-8 yum update --changelog %s", packageNames)
}

r := o.ssh(command, sudo)
if !r.isSuccess(0, 1) {
Expand Down

0 comments on commit e6ec692

Please sign in to comment.