ruleset

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

ruleset provides a set of rules and their corresponding validator functions for linting Dockerfile AST elements.

Index

Constants

View Source
const FORCE = true // used for overriding the latched isViolated flag in SetViolated.
View Source
const ToDoReference = DocsReference("TODO")

Variables

View Source
var DocsReferenceMap = map[string]DocsReference{
	"CPY": DocsReference("https://docs.docker.com/engine/reference/builder/#copy"),
	"ENV": DocsReference("https://docs.docker.com/engine/reference/builder/#env"),
	"EXP": DocsReference("https://docs.docker.com/engine/reference/builder/#expose"),
	"FRM": DocsReference("https://docs.docker.com/engine/reference/builder/#from"),
	"RUN": DocsReference("https://docs.docker.com/engine/reference/builder/#run"),
	"STL": DocsReference("https://docs.docker.com/engine/reference/builder/#from"),
	"STS": DocsReference("https://docs.docker.com/engine/reference/builder/#from"),
	"USR": DocsReference("https://docs.docker.com/engine/reference/builder/#user"),
	"WKD": DocsReference("https://docs.docker.com/engine/reference/builder/#workdir"),
}

Functions

func LocationRangeToBKRange

func LocationRangeToBKRange(locationRange LocationRange) parser.Range

func NewCmdCommand

func NewCmdCommand(str string, lineNumber int) (*instructions.CmdCommand, error)

func NewEntrypointCommand

func NewEntrypointCommand(str string, lineNumber int) (*instructions.EntrypointCommand, error)

func NewMaintainerCommand

func NewMaintainerCommand(str string) (*instructions.MaintainerCommand, error)

func NewRunCommand

func NewRunCommand(cmd string, locationRange LocationRange) *instructions.RunCommand

func RegisterTestCaseDocs

func RegisterTestCaseDocs(string, interface{})

RegisterTestCaseDocs is a mock function. For details, please see docs.go.

func SortLocationRanges

func SortLocationRanges(locationRangeSlice []LocationRange)

Types

type DocsReference

type DocsReference string

DocsReference is a documentation reference link and/or source. Usually it's a web link.

type Location

type Location struct {
	// contains filtered or unexported fields
}

func (*Location) CharNumber

func (location *Location) CharNumber() int

func (*Location) LineNumber

func (location *Location) LineNumber() int

func (Location) MarshalJSON

func (location Location) MarshalJSON() ([]byte, error)

func (*Location) UnmarshalJSON

func (location *Location) UnmarshalJSON(data []byte) error

type LocationRange

type LocationRange struct {
	// contains filtered or unexported fields
}

func BKRangeSliceToLocationRange

func BKRangeSliceToLocationRange(parserRange []parser.Range) LocationRange

func LocationRangeFromCommand

func LocationRangeFromCommand(command instructions.Command) LocationRange

func NewLocationFrom4Int

func NewLocationFrom4Int(locationRange [4]int) LocationRange

func NewLocationFrom4IntSlice

func NewLocationFrom4IntSlice(locationRangeSlice [][4]int) []LocationRange

func NewLocationRange

func NewLocationRange(startLine, startChar, endLine, endChar int) LocationRange

func ParseLocationFromRawParser

func ParseLocationFromRawParser(str string, window []parser.Range) LocationRange

func ParseLocationSliceFromRawParser

func ParseLocationSliceFromRawParser(strSlice []string, window []parser.Range) []LocationRange

func UnionOfLocationRanges

func UnionOfLocationRanges(locationRangeSlice []LocationRange) LocationRange

func (*LocationRange) End

func (locationRange *LocationRange) End() *Location

func (LocationRange) MarshalJSON

func (locationRange LocationRange) MarshalJSON() ([]byte, error)

func (*LocationRange) Start

func (locationRange *LocationRange) Start() *Location

func (*LocationRange) UnmarshalJSON

func (locationRange *LocationRange) UnmarshalJSON(data []byte) error

type Rule

type Rule struct {
	// contains filtered or unexported fields
}

Rule represents a Dockerfile lint validation rule. It has the basic id, definition, description, severity attributes and a validation function as an interface. For further details on validateFunc, please see Validate how it is utilized.

func GetRulesForAstElement

func GetRulesForAstElement(astElementInterface interface{}) []Rule

GetRulesForAstElement returns a Rule slice with all the rules that the given Dockerfile AST element needs to be validated against.

func NewRule

func NewRule(id string, definition string, description string, severity Severity, param interface{}) *Rule

NewRule creates a new Rule by joining it's id, definition, description, severity and validation function. It automatically gets assigned into a slice/set of rules corresponding to a specific Dockerfile AST element, inside the ruleMap's corresponding bin, based on the Dockerfile AST element's type. See below, how reflect.TypeOf().String() is used to achieve this.

func (*Rule) Definition

func (rule *Rule) Definition() string

Definition returns the rule's definition, i.e. the rule itself as a statement/guidance.

func (*Rule) Description

func (rule *Rule) Description() string

Description returns the rule's description, the idea behind the definition.

func (*Rule) DocsReference

func (rule *Rule) DocsReference() DocsReference

DocsReference returns an official reference link connected to the rule itself, most likely directly linking to a Docker documentation webpage.

func (*Rule) ID

func (rule *Rule) ID() string

ID returns the rule's id string.

func (*Rule) MarshalJSON

func (rule *Rule) MarshalJSON() ([]byte, error)

MarshalJSON converts a Rule instance to JSON.

func (*Rule) Severity

func (rule *Rule) Severity() Severity

Severity returns the rule's severity, e.g. error, warning, info, deprecation.

func (*Rule) UnmarshalJSON

func (rule *Rule) UnmarshalJSON(data []byte) error

func (*Rule) Validate

func (rule *Rule) Validate(param interface{}) RuleValidationResult

Validation calls the the rule's validationFunc validation function in the correct form, after converting from interface{} to the concrete type.

example: func(runCommand *instructions.RunCommand) RuleValidationResult where runCommand is asserted param as *instructions.RunCommand.

func (*Rule) ValidationFunc

func (rule *Rule) ValidationFunc() interface{}

type RuleMapType

type RuleMapType map[string][]Rule

RuleMapType represents a set of rules for each Dockerfile AST element identified by its type's string value (through reflect).

func Get

func Get() RuleMapType

Get returns ruleset's ruleMap.

func (RuleMapType) Count

func (ruleMap RuleMapType) Count() int

Count gives back the total number of rules in the ruleset. Note: each AST element has a set of corresponding rules in the rule map.

func (RuleMapType) GetRuleByName

func (ruleMap RuleMapType) GetRuleByName(ruleName string, astElement interface{}) Rule

GetRuleByName searches for the rule by its ExampleName in the main rule map.

type RuleValidationResult

type RuleValidationResult struct {
	LocationRange LocationRange
	// contains filtered or unexported fields
}

func NewRuleValidationResult

func NewRuleValidationResult(rule *Rule, isViolated bool, message string,
	locationRange LocationRange) *RuleValidationResult

func ValidateCmd001

func ValidateCmd001(cmdCommand *instructions.CmdCommand) RuleValidationResult

func ValidateCpy001

func ValidateCpy001(copyCommand *instructions.CopyCommand) RuleValidationResult

checks COPY options format for obvious errors --[option]=...

func ValidateCpy002

func ValidateCpy002(copyCommand *instructions.CopyCommand) RuleValidationResult

checks COPY --chmod option format for obvious errors --chmod=XXXX, where XXXX is a valid permission set value.

func ValidateCpy003

func ValidateCpy003(copyCommand *instructions.CopyCommand) RuleValidationResult

func ValidateCpy004

func ValidateCpy004(copyCommand *instructions.CopyCommand) RuleValidationResult

func ValidateCpy005

func ValidateCpy005(copyCommand *instructions.CopyCommand) RuleValidationResult

func ValidateCpy006

func ValidateCpy006(stage instructions.Stage) RuleValidationResult

func ValidateEnt001

func ValidateEnt001(entrypointCommand *instructions.EntrypointCommand) RuleValidationResult

func ValidateExp001

func ValidateExp001(exposeCommand *instructions.ExposeCommand) RuleValidationResult

func ValidateMtr001

func ValidateMtr001(maintainerCommand *instructions.MaintainerCommand) RuleValidationResult

func ValidateRun001

func ValidateRun001(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun002

func ValidateRun002(runCommand *instructions.RunCommand) RuleValidationResult

nolint:funlen

func ValidateRun003

func ValidateRun003(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun004

func ValidateRun004(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun005

func ValidateRun005(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun006

func ValidateRun006(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun007

func ValidateRun007(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun008

func ValidateRun008(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateRun009

func ValidateRun009(runCommand *instructions.RunCommand) RuleValidationResult

nolint: funlen, nestif

func ValidateRun010

func ValidateRun010(runCommand *instructions.RunCommand) RuleValidationResult

func ValidateStl001

func ValidateStl001(stageList []instructions.Stage) RuleValidationResult

func ValidateSts001

func ValidateSts001(stage instructions.Stage) RuleValidationResult

func ValidateSts002

func ValidateSts002(stage instructions.Stage) RuleValidationResult

func ValidateSts003

func ValidateSts003(stage instructions.Stage) RuleValidationResult

func ValidateSts004

func ValidateSts004(stage instructions.Stage) RuleValidationResult

func ValidateUsr001

func ValidateUsr001(stageList []instructions.Stage) RuleValidationResult

func ValidateWkd001

func ValidateWkd001(workdirCommand *instructions.WorkdirCommand) RuleValidationResult

func (*RuleValidationResult) Description

func (ruleValidationResult *RuleValidationResult) Description() string

func (RuleValidationResult) IsViolated

func (ruleValidationResult RuleValidationResult) IsViolated() bool

func (*RuleValidationResult) Location

func (ruleValidationResult *RuleValidationResult) Location() *LocationRange

func (*RuleValidationResult) MarshalJSON

func (ruleValidationResult *RuleValidationResult) MarshalJSON() ([]byte, error)

func (*RuleValidationResult) Message

func (ruleValidationResult *RuleValidationResult) Message() string

func (*RuleValidationResult) RuleID

func (ruleValidationResult *RuleValidationResult) RuleID() string

func (*RuleValidationResult) SetLocation

func (ruleValidationResult *RuleValidationResult) SetLocation(startLineNumber, startCharNumber,
	endLineNumber, endCharNumber int)

func (*RuleValidationResult) SetLocationRangeFrom

func (ruleValidationResult *RuleValidationResult) SetLocationRangeFrom(locationRange LocationRange)

func (*RuleValidationResult) SetRule

func (ruleValidationResult *RuleValidationResult) SetRule(rule *Rule)

func (*RuleValidationResult) SetViolated

func (ruleValidationResult *RuleValidationResult) SetViolated(params ...bool)

func (*RuleValidationResult) Severity

func (ruleValidationResult *RuleValidationResult) Severity() Severity

func (*RuleValidationResult) UnmarshalJSON

func (ruleValidationResult *RuleValidationResult) UnmarshalJSON(data []byte) error

type Severity

type Severity int

Severity type represents a severity, with an int level and a String function.

const (
	ValError Severity = iota
	ValDeprecation
	ValInfo
	ValWarning
	ValUnknown
)

func GetSeverityList

func GetSeverityList() []Severity

GetSeverityList returns a list of all the Severity values.

func (Severity) MarshalJSON

func (severity Severity) MarshalJSON() ([]byte, error)

func (Severity) String

func (severity Severity) String() string

Severity.String() converts the raw Severity into a string. Chose not to use "go:generate stringer -type=Severity" due this being much more readable.

func (*Severity) UnmarshalJSON

func (severity *Severity) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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