lib

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package lib Functionality for the Hookz CLI

Index

Constants

This section is empty.

Variables

View Source
var (
	//Rules contains the loaded rules from lucha.yaml
	Rules []Rule
)

Functions

func BuildFileList

func BuildFileList(fs FileSystem) (fileList []string, err error)

BuildFileList gathers all of the files from the searchpath down the folder tree

func DownloadFile

func DownloadFile(fs FileSystem, filepath string, URL string) (filename string, err error)

DownloadFile will download a url to a local file. It's efficient because it will write as it downloads and not load the whole file into memory. We pass an io.TeeReader into Copy() to report progress on the download.

func IfErrorLog

func IfErrorLog(err error, prefix string)

IfErrorLog Checks to see if an error exists, and if so simply writes it to the log.

func IsError

func IsError(err error, prefix string) error

IsError Checks to see if an error exists, and if so writes it to the log with the provided prefix

func IsErrorBool

func IsErrorBool(err error, prefix string) (b bool)

IsErrorBool Checks to see if an error exists, and if so returns true after writing the error to the log with the provided prefix

func LoadIgnore

func LoadIgnore(fs FileSystem) (ignores []string, err error)

LoadIgnore loads content in from the .luchaignore file

func LuchaDir

func LuchaDir() (path string, err error)

LuchaDir returns the path where the default Lucha rules are stored

Types

type Configuration

type Configuration struct {
	Version string `json:"version"`
	Lucha   Lucha  `json:"lucha"`
}

Configuration encapsulates the high level lucha rules file structure

func LoadRules

func LoadRules(fs FileSystem, version string, luchaFile string) (config Configuration, err error)

LoadRules loads the lucha.yaml rules file into memory

func RefreshRules

func RefreshRules(fs FileSystem, version string) (config Configuration, err error)

RefreshRules pulls down the latest rules from https://github.com/devops-kung-fu/lucha

type FileSystem

type FileSystem struct {
	SearchPath string
	Recursive  bool
	IncludeGit bool
	// contains filtered or unexported fields
}

FileSystem encapsulates the Afero fs Filesystem

func NewOsFs

func NewOsFs() FileSystem

NewOsFs returns a new local os file system

func (FileSystem) AbsoluteSearchPath

func (fs FileSystem) AbsoluteSearchPath() string

AbsoluteSearchPath returns the the absolute path for the (possibly) relative search path

func (FileSystem) Afero

func (fs FileSystem) Afero() *afero.Afero

Afero returns the Afero system

type Issue

type Issue struct {
	LineNumber int
	Rule       Rule
}

Issue represents a found issue and the rule that failed

func Evaluate

func Evaluate(line string, lineNumber int, minSeverity int) (issues []Issue, err error)

Evaluate searches the given line and line number and returns a collection of issues if they are greater than the minimum desired severity level

type Lucha

type Lucha struct {
	Rules []Rule `json:"rules"`
}

Lucha contains the rules used to evaluate files with

type Rule

type Rule struct {
	Code        string `json:"code"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Message     string `json:"message"`
	Attribution string `json:"attribution,omitempty"`
	Regex       string `json:"regex"`
	Severity    int64  `json:"severity,omitempty"`
}

Rule the definition of a rule used to check files against

type ScanFile

type ScanFile struct {
	Path   string
	Info   os.FileInfo
	Issues []Issue
}

ScanFile encapsulates file information and issues for scanned files

func FindIssues

func FindIssues(fs FileSystem, minSeverity int) (violations []ScanFile, violationsDetected bool, err error)

FindIssues scans the provided filesystem for issues

type WriteCounter

type WriteCounter struct {
	Total    uint64
	FileName string
}

WriteCounter encapsulates the total number of bytes captured and rendered

func (WriteCounter) PrintProgress

func (wc WriteCounter) PrintProgress()

PrintProgress prints the current download progress to STDOUT

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

Write increments the total number of bytes and prints progress to STDOUT

Jump to

Keyboard shortcuts

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