utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsRegoCompilationErr

func AsRegoCompilationErr(err error) ast.Errors

AsRegoCompilationErr attempts to convert this error into a Rego compilation error.

func AsRegoTopdownErr

func AsRegoTopdownErr(err error) *topdown.Error

AsRegoTopdownErr attempts to convert this error error to a Rego topdown.Error.

func AsStringSlice

func AsStringSlice(val interface{}) ([]string, bool)

AsStringSlice tries to coerce an interface that may actually be a []string.

func ChainErrors

func ChainErrors(errs ...error) error

ChainErrors takes the slice of errors and constructs a single chained error from is. The captures errors can be retrieved by inspecting the result with errors.As and errors.Is.

func ContainsString

func ContainsString(values []string, wanted string) bool

ContainsString checks whether the wanted string is in the values slice. This is suitable for short, unsorted slices.

func CopyBytes

func CopyBytes(src []byte) []byte

CopyBytes duplicates a slice of bytes.

func ImmediateDeletionOptions

func ImmediateDeletionOptions() *metav1.DeleteOptions

ImmediateDeletionOptions returns metav1.DeleteOptions specifying that the caller requires immediate foreground deletion semantics.

func IsDirPath

func IsDirPath(path string) bool

IsDirPath returns true if path refers to a directory.

func JoinLines

func JoinLines(lines ...string) string

JoinLines joins the given strings with "\n".

func NamespaceOrDefault

func NamespaceOrDefault(u *unstructured.Unstructured) string

NamespaceOrDefault returns the namespace from u, or "default" if u has no namespace field.

func NewSelectorFromObject

func NewSelectorFromObject(u *unstructured.Unstructured) labels.Selector

NewSelectorFromObject creates a selector to match all the labels in u.

func ParseCheckFragment

func ParseCheckFragment(input string) (*ast.Module, error)

ParseCheckFragment parses a Rego string into a *ast.Module. The Rego input is assumed to not have a package declaration so a random package name is prepended to make the parsed module globally unique. ParseCheckFragment can return nil with no error if the input is empty.

func ParseModuleFile

func ParseModuleFile(filePath string) (*ast.Module, error)

ParseModuleFile parses the Rego module in the given file path.

func RandomStringN

func RandomStringN(length int) string

RandomStringN ...

func SplitObjectName

func SplitObjectName(fullName string) (string, string)

SplitObjectName splits a string into namespace and name.

func WalkFiles

func WalkFiles(walkPath string, walkFn func(string) error) error

WalkFiles is a wrapper around filepath.Walk that accepts a path that may be either a file or a directory. In either case, it recurses the path and applied walkFunc to all files that it finds. Hidden files (i.e. dotfiles) are ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

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