Documentation ¶
Overview ¶
Package utils provides generic utility functions.
Package utils provides generic utility functions.
Package utils provides generic helper functions.
Package utils provides generic utility functions.
Package utils provides generic utility functions.
Package utils provides generic utility functions.
Package utils provides generic helper functions.
Package utils provides generic utility functions.
Package utils provides generic helper functions.
Package utils provides generic utility functions.
Package utils provides generic utility functions.
Package utils provides generic helper functions.
Package utils provides generic utility functions.
Index ¶
- func AddImageNameAnnotation(ociPath string, referenceToDigest map[string]string) error
- func AddRootHint(hints map[string]string, rootKey string, hintText string) map[string]string
- func AddRootListHint(hints map[string]string, listKey string, listValue string, hintText string) map[string]string
- func ByteFormat(inputNum float64, precision int) string
- func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool)
- func CosignSignBlob(blobPath string, outputSigPath string, keyPath string, ...) ([]byte, error)
- func CosignVerifyBlob(blobRef string, sigRef string, keyPath string) error
- func CreateDirectory(path string, mode os.FileMode) error
- func CreateFile(filepath string) error
- func CreateParentDirectory(destination string) error
- func CreatePathAndCopy(source string, destination string) error
- func CreateReproducibleTarballFromDir(dirPath, dirPrefix, tarballPath string) error
- func DownloadToFile(src string, dst string, cosignKeyPath string) (err error)
- func ExecuteWait(waitTimeout, waitNamespace, condition, kind, identifier string, ...) error
- func FindYamlTemplates(config any, prefix string, suffix string) (map[string]string, error)
- func GetCosignArtifacts(image string) (cosignList []string, err error)
- func GetDirSize(path string) (int64, error)
- func GetFinalExecutableCommand() (string, error)
- func GetFinalExecutablePath() (string, error)
- func GetHtpasswdString(username string, password string) (string, error)
- func GetSHA256OfFile(filePath string) (string, error)
- func HasImageLayers(img v1.Image) (bool, error)
- func InvalidPath(path string) bool
- func IsDir(path string) bool
- func IsHidden(name string) bool
- func IsTextFile(path string) (bool, error)
- func IsTrashBin(dirPath string) bool
- func ListDirectories(directory string) ([]string, error)
- func LoadOCIImage(imgPath string, refInfo transform.Image) (v1.Image, error)
- func MakeTempDir(basePath string) (string, error)
- func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
- func ReadYaml(path string, destConfig any) error
- func RecursiveFileList(dir string, pattern *regexp.Regexp, skipHidden bool) (files []string, err error)
- func ReloadYamlTemplate(config any, mappings map[string]string) error
- func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, ...)
- func ReplaceTextTemplate(path string, mappings map[string]*TextTemplate, deprecations map[string]string, ...) error
- func RoundUp(input float64, places int) (newVal float64)
- func SHAsMatch(path, expected string) error
- func Sget(ctx context.Context, image, key string, out io.Writer) error
- func SortDependencies(data []Dependency) ([]string, error)
- func SplitFile(srcFile string, chunkSizeBytes int) (err error)
- func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
- func SplitYAMLToString(yamlData []byte) ([]string, error)
- func VerifyBinary(binary string) bool
- func WriteFile(path string, data []byte) error
- func WriteJSON(path string, v any) error
- func WriteYaml(path string, srcConfig any, perm fs.FileMode) error
- type ConcurrencyTools
- type Credential
- type Dependency
- type TextTemplate
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddImageNameAnnotation ¶ added in v0.28.3
AddImageNameAnnotation adds an annotation to the index.json file so that the deploying code can figure out what the image reference <-> digest shasum will be.
func AddRootHint ¶ added in v0.28.0
AddRootHint adds a hint string for a given root key.
func AddRootListHint ¶ added in v0.28.0
func AddRootListHint(hints map[string]string, listKey string, listValue string, hintText string) map[string]string
AddRootListHint adds a hint string for a given root list key and value.
func ByteFormat ¶
ByteFormat formats a number of bytes into a human readable string.
func ColorPrintYAML ¶
ColorPrintYAML pretty prints a yaml file to the console.
func CosignSignBlob ¶ added in v0.25.1
func CosignSignBlob(blobPath string, outputSigPath string, keyPath string, passwordFunc func(bool) ([]byte, error)) ([]byte, error)
CosignSignBlob signs the provide binary and returns the signature
func CosignVerifyBlob ¶ added in v0.25.1
CosignVerifyBlob verifies the zarf.yaml.sig was signed with the key provided by the flag
func CreateDirectory ¶
CreateDirectory creates a directory for the given path and file mode.
func CreateFile ¶ added in v0.28.1
CreateFile creates an empty file at the given path.
func CreateParentDirectory ¶ added in v0.31.4
CreateParentDirectory creates the parent directory for the given file path.
func CreatePathAndCopy ¶
CreatePathAndCopy creates the parent directory for the given file path and copies the source file to the destination.
func CreateReproducibleTarballFromDir ¶ added in v0.32.1
CreateReproducibleTarballFromDir creates a tarball from a directory with stripped headers
func DownloadToFile ¶
DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary).
func ExecuteWait ¶ added in v0.28.2
func ExecuteWait(waitTimeout, waitNamespace, condition, kind, identifier string, timeout time.Duration) error
ExecuteWait executes the wait-for command.
func FindYamlTemplates ¶
FindYamlTemplates finds strings with a given prefix in a config.
func GetCosignArtifacts ¶ added in v0.30.1
GetCosignArtifacts returns signatures and attestations for the given image
func GetDirSize ¶ added in v0.25.0
GetDirSize walks through all files and directories in the provided path and returns the total size in bytes.
func GetFinalExecutableCommand ¶ added in v0.30.0
GetFinalExecutableCommand returns the final path to the Zarf executable including and library prefixes and overrides.
func GetFinalExecutablePath ¶
GetFinalExecutablePath returns the absolute path to the current executable, following any symlinks along the way.
func GetHtpasswdString ¶
GetHtpasswdString converts a username and password to a properly formatted and hashed format for `htpasswd`.
func GetSHA256OfFile ¶ added in v0.25.1
GetSHA256OfFile returns the SHA256 hash of the provided file.
func HasImageLayers ¶ added in v0.30.1
HasImageLayers checks if any layers in the v1.Image are known image layers.
func InvalidPath ¶
InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access)
func IsTextFile ¶ added in v0.23.3
IsTextFile returns true if the given file is a text file.
func IsTrashBin ¶ added in v0.28.0
IsTrashBin checks if the given directory path corresponds to an operating system's trash bin.
func ListDirectories ¶
ListDirectories returns a list of directories in the given directory.
func LoadOCIImage ¶ added in v0.26.0
LoadOCIImage returns a v1.Image with the image ref specified from a location provided, or an error if the image cannot be found.
func MakeTempDir ¶
MakeTempDir creates a temp directory with the zarf- prefix.
func ReadFileByChunks ¶ added in v0.32.3
func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
ReadFileByChunks reads a file into multiple chunks by the given size.
func RecursiveFileList ¶
func RecursiveFileList(dir string, pattern *regexp.Regexp, skipHidden bool) (files []string, err error)
RecursiveFileList walks a path with an optional regex pattern and returns a slice of file paths. If skipHidden is true, hidden directories will be skipped.
func ReloadYamlTemplate ¶
ReloadYamlTemplate marshals a given config, replaces strings and unmarshals it back.
func RenderProgressBarForLocalDirWrite ¶ added in v0.25.0
func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, completeChan chan int, errChan chan int, updateText string, successText string)
RenderProgressBarForLocalDirWrite creates a progress bar that continuously tracks the progress of writing files to a local directory and all of its subdirectories. NOTE: This function runs infinitely until either completeChan or errChan is triggered, this function should be run in a goroutine while a different thread/process is writing to the directory.
func ReplaceTextTemplate ¶
func ReplaceTextTemplate(path string, mappings map[string]*TextTemplate, deprecations map[string]string, templateRegex string) error
ReplaceTextTemplate loads a file from a given path, replaces text in it and writes it back in place.
func SHAsMatch ¶ added in v0.29.0
SHAsMatch returns an error if the SHA256 hash of the provided file does not match the expected hash.
func Sget ¶
Sget performs a cosign signature verification on a given image using the specified public key.
func SortDependencies ¶ added in v0.25.0
func SortDependencies(data []Dependency) ([]string, error)
SortDependencies performs a topological sort on a dependency graph and returns a slice of the nodes in order of their precedence. The input data is a map of nodes to a slice of its dependencies.
E.g: A depends on B & C, B depends on C and C has no dependencies: {"A": ["B", "C"], "B": ["C"], "C": []string{}}
Note sort order is dependent on the slice order of the input data for nodes with the same in-degree (i.e. the same number of dependencies).
func SplitFile ¶
SplitFile will take a srcFile path and split it into files based on chunkSizeBytes the first file will be a metadata file containing: - sha256sum of the original file - number of bytes in the original file - number of files the srcFile was split into SplitFile will delete the original file
Returns: - fileNames: list of file paths srcFile was split across - sha256sum: sha256sum of the srcFile before splitting - err: any errors encountered
func SplitYAML ¶
func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
SplitYAML splits a YAML file into unstructured objects. Returns list of all unstructured objects found in the yaml. If an error occurs, returns objects that have been parsed so far too. Source: https://github.com/argoproj/gitops-engine/blob/v0.5.2/pkg/utils/kube/kube.go#L286.
func SplitYAMLToString ¶ added in v0.25.0
SplitYAMLToString splits a YAML file into strings. Returns list of yamls found in the yaml. If an error occurs, returns objects that have been parsed so far too. Source: https://github.com/argoproj/gitops-engine/blob/v0.5.2/pkg/utils/kube/kube.go#L304.
func VerifyBinary ¶
VerifyBinary returns true if binary is available.
Types ¶
type ConcurrencyTools ¶ added in v0.30.0
type ConcurrencyTools[P any, E any] struct { ProgressChan chan P ErrorChan chan E Cancel context.CancelFunc // contains filtered or unexported fields }
ConcurrencyTools is a struct that contains channels and a context for use in concurrent routines
func NewConcurrencyTools ¶ added in v0.30.0
func NewConcurrencyTools[P any, E any](length int) *ConcurrencyTools[P, E]
NewConcurrencyTools creates a new ConcurrencyTools struct
Length is the number of iterations that will be performed concurrently
func (*ConcurrencyTools[P, E]) IsDone ¶ added in v0.30.0
func (ct *ConcurrencyTools[P, E]) IsDone() bool
IsDone returns true if the context is done.
func (*ConcurrencyTools[P, E]) WaitWithProgress ¶ added in v0.30.0
func (ct *ConcurrencyTools[P, E]) WaitWithProgress(onProgress func(P, int), onError func(E) error) error
WaitWithProgress waits for all routines to finish
onProgress is a callback function that is called when a routine sends a progress update
onError is a callback function that is called when a routine sends an error
func (*ConcurrencyTools[P, E]) WaitWithoutProgress ¶ added in v0.30.0
func (ct *ConcurrencyTools[P, E]) WaitWithoutProgress(onError func(E) error) error
WaitWithoutProgress waits for all routines to finish without a progress callback
onError is a callback function that is called when a routine sends an error
type Credential ¶
Credential represents authentication for a given host.
func FindAuthForHost ¶
func FindAuthForHost(baseURL string) *Credential
FindAuthForHost finds the authentication scheme for a given host using .git-credentials then .netrc.
type Dependency ¶ added in v0.25.0
Dependency is an interface that represents a node in a list of dependencies.
type TextTemplate ¶ added in v0.25.1
type TextTemplate struct { Sensitive bool AutoIndent bool Type types.VariableType Value string }
TextTemplate represents a value to be templated into a text file.
type Transport ¶ added in v0.25.0
type Transport struct { Base http.RoundTripper ProgressBar *message.ProgressBar }
Transport is an http.RoundTripper that keeps track of the in-flight request and add hooks to report upload progress.
func NewTransport ¶ added in v0.25.0
func NewTransport(base http.RoundTripper, bar *message.ProgressBar) *Transport
NewTransport returns a custom transport that tracks an http.RoundTripper and a message.ProgressBar.
func (*Transport) RoundTrip ¶ added in v0.25.0
RoundTrip is mirrored from retry, but instead of calling retry's private t.roundTrip(), this uses our own which has interactions w/ message.ProgressBar
https://github.com/oras-project/oras-go/blob/main/registry/remote/retry/client.go
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package exec provides a wrapper around the os/exec package
|
Package exec provides a wrapper around the os/exec package |
Package helpers provides generic helper functions with no external imports
|
Package helpers provides generic helper functions with no external imports |