utils

package
v0.0.0-...-1ba91b8 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInternal indicates an internal error.
	ErrInternal = errors.New("internal error")

	// ErrInvalidPath indicates an invalid path.
	ErrInvalidPath = errors.New("invalid path")
)

Functions

func CreateNewFileUnderCurrentDirectory

func CreateNewFileUnderCurrentDirectory(path string, flag int) (io.Writer, error)

CreateNewFileUnderCurrentDirectory create a new file under the current directory and fails if the file already exists. The file is always created with the pemisisons `0o600`.

func CreateNewFileUnderDirectory

func CreateNewFileUnderDirectory(path, dir string, flag int) (io.Writer, error)

CreateNewFileUnderDirectory create a new file under the current directory and fails if the file already exists. The file is always created with the pemisisons `0o600`. Ensures that the path does not exit out of the given directory.

func IsPresubmitTests

func IsPresubmitTests() bool

IsPresubmitTests returns true if running in pre-submit tests.

func MarshalToBytes

func MarshalToBytes(args interface{}) ([]byte, error)

MarshalToBytes marshals to a byte array.

func MarshalToString

func MarshalToString(args interface{}) (string, error)

MarshalToString marshals to a string.

func PathIsUnderCurrentDirectory

func PathIsUnderCurrentDirectory(path string) error

PathIsUnderCurrentDirectory checks whether the `path` is under the current working directory. Examples: ./file, ./some/path, ../<cwd>.file would return `nil`. `../etc/password` would return an error.

func PathIsUnderDirectory

func PathIsUnderDirectory(path, absoluteDir string) error

PathIsUnderDirectory checks to see if path is under the absolute directory specified.

func SafeReadFile

func SafeReadFile(path string) ([]byte, error)

SafeReadFile checks for directory traversal before reading the given file.

func UnmarshalList

func UnmarshalList(arg string) ([]string, error)

UnmarshalList unmarshals a string into a list of strings.

func VerifyAttestationPath

func VerifyAttestationPath(path string) error

VerifyAttestationPath verifies that the path of an attestation is valid. It checks that the path is under the current working directory and that the extension of the file is `intoto.jsonl`.

Types

This section is empty.

Jump to

Keyboard shortcuts

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