github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/rule/package_not_installed.go (about)

     1  package rule
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // The PackageNotInstalled validates that a specified package in not installed.
     9  type PackageNotInstalled struct {
    10  	Meta
    11  	PackageName              string
    12  	PackageVersion           string
    13  	AcceptablePackageVersion string
    14  }
    15  
    16  // Name returns the name of the rule
    17  func (p PackageNotInstalled) Name() string {
    18  	name := fmt.Sprintf(`Package "%s" should not be installed`, p.PackageName)
    19  	if p.AcceptablePackageVersion != "" {
    20  		name = fmt.Sprintf(`%s, only acceptable version is "%s"`, name, p.AcceptablePackageVersion)
    21  	}
    22  	return name
    23  }
    24  
    25  // IsRemoteRule returns true if the rule is to be run from outside of the node
    26  func (p PackageNotInstalled) IsRemoteRule() bool { return false }
    27  
    28  // Validate the rule
    29  func (p PackageNotInstalled) Validate() []error {
    30  	err := []error{}
    31  	if p.PackageName == "" {
    32  		err = append(err, errors.New("PackageName cannot be empty"))
    33  	}
    34  	if len(err) > 0 {
    35  		return err
    36  	}
    37  	return nil
    38  }