util

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const SchemasDirectory = "_schemas"

SchemasDirectory is the name of the special directory containing schemas. It is defined here to avoid an import loop.

View Source
const TestDataDirectory = "testdata"

TestDataDirectory is the name of the special directory containing test fixtures. It is defined here to avoid an import loop.

Variables

View Source
var (
	AppName   = "cerbos"
	BuildDate = "unknown"
	Commit    = "unknown"
	Version   = "unknown"
)
View Source
var (
	ErrEmptyFile        = errors.New("empty file")
	ErrMultipleYAMLDocs = errors.New("more than one YAML document detected")
)
View Source
var ErrNoMatchingFiles = errors.New("no matching files")

Functions

func AppShortVersion added in v0.26.0

func AppShortVersion() string

func AppVersion added in v0.9.0

func AppVersion() string

func DefaultTLSConfig

func DefaultTLSConfig() *tls.Config

DefaultTLSConfig returns the default TLS configuration.

func DeprecationWarning added in v0.35.0

func DeprecationWarning(deprecated, replacement string)

func FilterGlob added in v0.12.0

func FilterGlob(g string, values []string) []string

FilterGlob returns the set of values that match the given glob.

func FilterGlobNotMatches added in v0.12.0

func FilterGlobNotMatches(g string, values []string) []string

FilterGlobNotMatches returns the set of values that do not match the given glob.

func GetFreeListenAddr

func GetFreeListenAddr() (string, error)

func GetFreePort

func GetFreePort() (int, error)

func GetOneOfSupportedFileNames added in v0.31.0

func GetOneOfSupportedFileNames(fsys fs.FS, fileName string) (string, error)

GetOneOfSupportedFileNames attempts to retrieve a fileName adding supported extensions.

func HashPB added in v0.13.0

func HashPB(h Hashable, ignore map[string]struct{}) uint64

func HashStr added in v0.13.0

func HashStr(s string) uint64

func IsArchiveFile added in v0.26.0

func IsArchiveFile(fileName string) bool

func IsGzip added in v0.26.0

func IsGzip(fileName string) bool

func IsHidden added in v0.18.0

func IsHidden(fileName string) bool

func IsJSON added in v0.34.0

func IsJSON(src []byte) bool

func IsJSONFileTypeExt added in v0.14.0

func IsJSONFileTypeExt(fileName string) bool

IsJSONFileTypeExt returns true if the given file has a json file extension.

func IsSupportedFileType

func IsSupportedFileType(fileName string) bool

IsSupportedFileType returns true if the given file has a supported file extension.

func IsSupportedFileTypeExt added in v0.7.0

func IsSupportedFileTypeExt(fileName string) (string, bool)

IsSupportedFileTypeExt returns true and a file extension if the given file has a supported file extension.

func IsSupportedTestFile added in v0.7.0

func IsSupportedTestFile(fileName string) bool

IsSupportedTestFile return true if the given file is a supported test file name, i.e. "*_test.{yaml,yml,json}".

func IsTar added in v0.26.0

func IsTar(fileName string) bool

func IsZip added in v0.23.0

func IsZip(fileName string) bool

func LoadFromJSONOrYAML

func LoadFromJSONOrYAML(fsys fs.FS, path string, dest proto.Message) error

LoadFromJSONOrYAML reads a JSON or YAML encoded protobuf from the given path.

func MatchesGlob added in v0.12.0

func MatchesGlob(globExpr, val string) bool

MatchesGlob returns true if the given glob expression matches the given string.

func OpenDirectoryFS added in v0.26.0

func OpenDirectoryFS(path string) (fs.FS, error)

OpenDirectoryFS attempts to open a directory FS at the given location. It'll initially check if the target file is an archive, and if so, will return the appropriate type which implements the fs.FS interface.

func PDPIdentifier added in v0.27.0

func PDPIdentifier(pdpID string) *pdpv1.Identifier

func ParseListenAddress

func ParseListenAddress(listenAddr string) (network, addr string, err error)

ParseListenAddress parses an address and returns the network type and the address to dial. inspired by https://github.com/ghostunnel/ghostunnel/blob/6e58c75c8762fe371c1134e89dd55033a6d577a4/socket/net.go#L31

func ReadJSONOrYAML

func ReadJSONOrYAML(src io.Reader, dest proto.Message) error

func RelativeSchemaPath added in v0.18.0

func RelativeSchemaPath(path string) (string, bool)

RelativeSchemaPath returns the given path within the top-level schemas directory, and a flag to indicate whether the path was actually contained in that directory. The path must be "/"-separated and relative to the root policies directory.

func ToStructPB added in v0.9.0

func ToStructPB(v any) (*structpb.Value, error)

func WriteYAML

func WriteYAML(dest io.Writer, data proto.Message) error

Types

type ClosableFS added in v0.30.0

type ClosableFS struct {
	fs.FS
	io.Closer
	// contains filtered or unexported fields
}

func (ClosableFS) Close added in v0.30.0

func (cfs ClosableFS) Close() (outErr error)

type Hashable added in v0.13.0

type Hashable interface {
	HashPB(hash.Hash, map[string]struct{})
}

type IndexedFileType added in v0.18.0

type IndexedFileType uint8
const (
	FileTypeNotIndexed IndexedFileType = iota
	FileTypePolicy
	FileTypeSchema
)

func FileType added in v0.18.0

func FileType(path string) IndexedFileType

FileType categorizes the given path according to how it will be treated by the index. The path must be "/"-separated and relative to the root policies directory.

type RegexpCache added in v0.29.0

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

func NewRegexpCache added in v0.29.0

func NewRegexpCache() *RegexpCache

func (*RegexpCache) GetCompiledExpr added in v0.29.0

func (c *RegexpCache) GetCompiledExpr(re string) (*regexp.Regexp, error)

GetCompiledExpr lazily compiles (and stores) regexp.

Jump to

Keyboard shortcuts

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