rule

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2017 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Overview

Package rule implements the inspector rules and the engine that runs the rules according to the conditions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpDefaultRules

func DumpDefaultRules(writer io.Writer) error

DumpDefaultRules writes the default rule set to a file

Types

type CheckMapper

type CheckMapper interface {
	GetCheckForRule(Rule) (check.Check, error)
}

CheckMapper implements a mapping between a rule and a check.

type DefaultCheckMapper

type DefaultCheckMapper struct {
	PackageManager check.PackageManager
	// IP of the remote node that is being inspected when in client mode
	TargetNodeIP string
}

The DefaultCheckMapper contains the mappings for all supported rules and checks.

func (DefaultCheckMapper) GetCheckForRule

func (m DefaultCheckMapper) GetCheckForRule(rule Rule) (check.Check, error)

GetCheckForRule returns the check for the given rule. If the rule is unknown to the mapper, it returns an error.

type Engine

type Engine struct {
	RuleCheckMapper CheckMapper
	// contains filtered or unexported fields
}

The Engine executes rules and reports the results

func (*Engine) CloseChecks

func (e *Engine) CloseChecks() error

CloseChecks that need to be closed

func (*Engine) ExecuteRules

func (e *Engine) ExecuteRules(rules []Rule, facts []string) ([]Result, error)

ExecuteRules runs the rules that should be executed according to the facts, and returns a collection of results. The number of results is not guaranteed to equal the number of rules.

type ExecutableInPath

type ExecutableInPath struct {
	Meta
	Executable string
}

ExecutableInPath is a rule that ensures the given executable is in the system's path

func (ExecutableInPath) IsRemoteRule

func (e ExecutableInPath) IsRemoteRule() bool

IsRemoteRule returns true if the rule is to be run from outside of the node

func (ExecutableInPath) Name

func (e ExecutableInPath) Name() string

Name is the name of the rule

func (ExecutableInPath) Validate

func (e ExecutableInPath) Validate() []error

Validate the rule

type FileContentMatches

type FileContentMatches struct {
	Meta
	File         string
	ContentRegex string
}

FileContentMatches is a rule that verifies that the contents of a file match the regular expression provided

func (FileContentMatches) IsRemoteRule

func (f FileContentMatches) IsRemoteRule() bool

IsRemoteRule returns true if the rule is to be run from outside of the node

func (FileContentMatches) Name

func (f FileContentMatches) Name() string

Name is the name of the rule

func (FileContentMatches) Validate

func (f FileContentMatches) Validate() []error

Validate the rule

type Meta

type Meta struct {
	Kind string
	When []string
}

Meta contains the rule's metadata

func (Meta) GetRuleMeta

func (rm Meta) GetRuleMeta() Meta

GetRuleMeta returns the rule's metadata

type PackageAvailable

type PackageAvailable struct {
	Meta
	PackageName    string
	PackageVersion string
}

PackageAvailable is a rule that ensures that the given package is either installed on the host operating system or available for installation

func (PackageAvailable) IsRemoteRule

func (p PackageAvailable) IsRemoteRule() bool

IsRemoteRule returns true if the rule is to be run from outside of the node

func (PackageAvailable) Name

func (p PackageAvailable) Name() string

Name returns the name of the rule

func (PackageAvailable) Validate

func (p PackageAvailable) Validate() []error

Validate the rule

type Python2Version

type Python2Version struct {
	Meta
	SupportedVersions []string
}

PythonVersion rule for checking the host's python version

func (Python2Version) IsRemoteRule

func (p Python2Version) IsRemoteRule() bool

func (Python2Version) Name

func (p Python2Version) Name() string

func (Python2Version) Validate

func (p Python2Version) Validate() []error

type Result

type Result struct {
	// Name is the rule's name
	Name string
	// Success is true when the rule was asserted
	Success bool
	// Error message if there was an error executing the rule
	Error string
	// Remediation contains potential remediation steps for the rule
	Remediation string
}

Result contains the results from executing the rule

type Rule

type Rule interface {
	Name() string
	GetRuleMeta() Meta
	IsRemoteRule() bool
	Validate() []error
}

Rule is an inspector rule

func DefaultRules

func DefaultRules() []Rule

DefaultRules returns the list of rules that are built into the inspector

func ReadFromFile

func ReadFromFile(file string) ([]Rule, error)

ReadFromFile returns the list of rules contained in the specified file

func UnmarshalRulesJSON

func UnmarshalRulesJSON(data []byte) ([]Rule, error)

UnmarshalRulesJSON unmarshals the JSON rules into a list of rules

func UnmarshalRulesYAML

func UnmarshalRulesYAML(data []byte) ([]Rule, error)

UnmarshalRulesYAML unmarshals the data into a list of rules

type TCPPortAccessible

type TCPPortAccessible struct {
	Meta
	Port    int
	Timeout string
}

TCPPortAccessible is a rule that ensures the given port on a remote node is accessible from the network

func (TCPPortAccessible) IsRemoteRule

func (p TCPPortAccessible) IsRemoteRule() bool

IsRemoteRule returns true if the rule is to be run from a remote node

func (TCPPortAccessible) Name

func (p TCPPortAccessible) Name() string

Name returns the name of the rule

func (TCPPortAccessible) Validate

func (p TCPPortAccessible) Validate() []error

Validate the rule

type TCPPortAvailable

type TCPPortAvailable struct {
	Meta
	Port int
}

TCPPortAvailable is a rule that ensures that a given port is available on the node. Available means that the port is not being used by another process.

func (TCPPortAvailable) IsRemoteRule

func (p TCPPortAvailable) IsRemoteRule() bool

IsRemoteRule returns true if the rule is to be run from outside the node

func (TCPPortAvailable) Name

func (p TCPPortAvailable) Name() string

Name is the name of the rule

func (TCPPortAvailable) Validate

func (p TCPPortAvailable) Validate() []error

Validate the rule

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL