Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check yum plugin enabled #353

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions scan/redhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ func (o *redhat) checkIfSudoNoPasswd() error {
// RHEL, Amazon ... no additinal packages needed
func (o *redhat) checkDependencies() error {
switch o.Distro.Family {
case "rhel", "amazon":
case "amazon":
return nil

case "rhel":
return o.checkRequiredPluginsEnabled()
case "centos":
majorVersion, err := o.Distro.MajorVersion()
if err != nil {
Expand All @@ -137,7 +138,7 @@ func (o *redhat) checkDependencies() error {

cmd := "rpm -q " + name
if r := o.exec(cmd, noSudo); r.isSuccess() {
return nil
return o.checkRequiredPluginsEnabled()
}
o.lackDependencies = []string{name}
return nil
Expand All @@ -158,6 +159,32 @@ func (o *redhat) install() error {
return nil
}

func (o *redhat) checkRequiredPluginsEnabled() error {
cmd := "yum --help"
r := o.exec(cmd, noSudo)
if !r.isSuccess() {
return fmt.Errorf("Failed to SSH: %s", r)
}
// Extract first line from stdout
// e.g. Loaded plugins: changelog, fastestmirror
loadedPlugins := strings.Split(r.Stdout, "\n")[0]

requiredPlugin := ""
switch o.Distro.Family {
case "rhel":
requiredPlugin = "security"
case "centos":
requiredPlugin = "changelog"
}

if !strings.Contains(loadedPlugins, requiredPlugin) {
msg := fmt.Sprintf("'%s' plugin is not enabled. Please check /etc/yum/pluginconf.d/", requiredPlugin)
o.log.Errorf(msg)
return fmt.Errorf(msg)
}
return nil
}

func (o *redhat) checkRequiredPackagesInstalled() error {
if o.Distro.Family == "centos" {
majorVersion, err := o.Distro.MajorVersion()
Expand Down