Documentation ¶
Overview ¶
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions ¶
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Package utils provides generic helper functions.
Index ¶
- func ByteFormat(inputNum float64, precision int) string
- func ColorPrintYAML(data any)
- func CosignSignBlob(blobPath string, outputSigPath string, keyPath string, ...) ([]byte, error)
- func CosignVerifyBlob(blobPath string, sigPath string, keyPath string) error
- func CreateDirectory(path string, mode os.FileMode) error
- func CreateFilePath(destination string) error
- func CreatePathAndCopy(source string, destination string) error
- func DoHostnamesMatch(url1 string, url2 string) (bool, error)
- func DownloadToFile(src string, dst string, cosignKeyPath string) (err error)
- func Fetch(url string) io.ReadCloser
- func Filter[T any](ss []T, test func(T) bool) (r []T)
- func Find[T any](ss []T, test func(T) bool) (r T)
- func FindYamlTemplates(config any, prefix string, suffix string) (map[string]string, error)
- func First30last30(s string) string
- func GetAvailablePort() (int, error)
- func GetCRCHash(text string) uint32
- func GetCryptoHash(path string, hashName crypto.Hash) (string, error)
- func GetDirSize(path string) (int64, error)
- func GetFinalExecutablePath() (string, error)
- func GetHtpasswdString(username string, password string) (string, error)
- func GetSHA256OfFile(filePath string) (string, error)
- func Insert[T any](slice []T, index int, element T) []T
- func InvalidPath(path string) bool
- func IsOCIURL(source string) bool
- func IsTextFile(path string) (bool, error)
- func IsURL(source string) bool
- func IsValidHostName() bool
- func ListDirectories(directory string) ([]string, error)
- func LoadOCIImage(imgPath, imgTag string) (v1.Image, error)
- func MakeTempDir(tmpDir string) (string, error)
- func MatchRegex(regex *regexp.Regexp, str string) (func(string) string, error)
- func MergeMap[T any](m1, m2 map[string]T) (r map[string]T)
- func MergeMapRecursive(m1, m2 map[string]interface{}) (r map[string]interface{})
- func PrintComponentCredential(state types.ZarfState, componentName string)
- func PrintCredentialTable(state types.ZarfState, componentsToDeploy []types.DeployedComponent)
- func PrintLayerExists(_ context.Context, desc ocispec.Descriptor) error
- func RandomString(length int) string
- func ReadYaml(path string, destConfig any) error
- func RecursiveFileList(dir string, pattern *regexp.Regexp, skipPermission bool, skipHidden bool) (files []string, err error)
- func ReloadYamlTemplate(config any, mappings map[string]string) error
- func RemoveMatches[T any](ss []T, test func(T) bool) (r []T)
- func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, ...)
- func ReplaceTextTemplate(path string, mappings map[string]*TextTemplate, deprecations map[string]string, ...) error
- func Retry(fn func() error, retries int, delay time.Duration) (err error)
- func Reverse[T any](s []T) (r []T)
- func RoundUp(input float64, places int) (newVal float64)
- func Sget(ctx context.Context, image, key string, out io.Writer) error
- func SliceContains[T comparable](s []T, e T) bool
- func SortDependencies(data []Dependency) ([]string, error)
- func SplitFile(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
- func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
- func SplitYAMLToString(yamlData []byte) ([]string, error)
- func TransformMapKeys[T any](m map[string]T, transform func(string) string) (r map[string]T)
- func Unique[T comparable](s []T) (r []T)
- 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 Credential
- type Dependency
- type OrasRemote
- type TextTemplate
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteFormat ¶
ByteFormat formats a number of bytes into a human readable string.
func ColorPrintYAML ¶
func ColorPrintYAML(data any)
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 CreateFilePath ¶
CreateFilePath 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 DoHostnamesMatch ¶ added in v0.23.2
DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same.
func DownloadToFile ¶
DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary).
func Filter ¶ added in v0.24.0
Filter returns a new slice with only the elements that pass the test.
func FindYamlTemplates ¶
FindYamlTemplates finds strings with a given prefix in a config.
func First30last30 ¶ added in v0.25.0
First30last30 returns the source string that has been trimmed to 30 characters at the beginning and end.
func GetAvailablePort ¶
GetAvailablePort retrieves an available port on the host machine. This delegates the port selection to the golang net library by starting a server and then checking the port that the server is using.
func GetCRCHash ¶ added in v0.25.0
GetCRCHash returns the computed CRC32 Sum of a given string
func GetCryptoHash ¶ added in v0.24.0
GetCryptoHash returns the computed SHA256 Sum of a given file
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 GetFinalExecutablePath ¶
GetFinalExecutablePath returns the absolute path to the Zarf 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 Insert ¶ added in v0.25.0
Insert returns a new slice with the element inserted at the given index.
func IsTextFile ¶ added in v0.23.3
IsTextFile returns true if the given file is a text file.
func IsValidHostName ¶
func IsValidHostName() bool
IsValidHostName returns a boolean indicating if the hostname of the host machine is valid according to https://www.ietf.org/rfc/rfc1123.txt.
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 tag specified from a location provided, or an error if the image cannot be found.
func MakeTempDir ¶
MakeTempDir creates a temp directory with the given prefix.
func MatchRegex ¶ added in v0.25.0
MatchRegex wraps a get function around a substring match.
func MergeMap ¶ added in v0.24.0
MergeMap merges map m2 with m1 overwriting common values with m2's values.
func MergeMapRecursive ¶ added in v0.25.0
MergeMapRecursive recursively (nestedly) merges map m2 with m1 overwriting common values with m2's values.
func PrintComponentCredential ¶ added in v0.24.0
PrintComponentCredential displays credentials for a single component
func PrintCredentialTable ¶ added in v0.24.0
func PrintCredentialTable(state types.ZarfState, componentsToDeploy []types.DeployedComponent)
PrintCredentialTable displays credentials in a table
func PrintLayerExists ¶ added in v0.25.0
func PrintLayerExists(_ context.Context, desc ocispec.Descriptor) error
PrintLayerExists prints a success message to the console when a layer has been successfully published to a registry.
func RandomString ¶
RandomString generates a secure random string of the specified length.
func RecursiveFileList ¶
func RecursiveFileList(dir string, pattern *regexp.Regexp, skipPermission bool, skipHidden bool) (files []string, err error)
RecursiveFileList walks a path with an optional regex pattern and returns a slice of file paths. the skipPermission flag can be provided to ignore unauthorized files/dirs when true the skipHidden flag can be provided to ignore dot prefixed files/dirs when true
func ReloadYamlTemplate ¶
ReloadYamlTemplate marshals a given config, replaces strings and unmarshals it back.
func RemoveMatches ¶ added in v0.24.0
RemoveMatches removes the given element from the slice that matches the test.
func RenderProgressBarForLocalDirWrite ¶ added in v0.25.0
func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, completeChan chan int, updateText 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 the completeChan 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 Retry ¶
Retry will retry a function until it succeeds or the timeout is reached, timeout == retries * delay.
func Reverse ¶ added in v0.24.0
func Reverse[T any](s []T) (r []T)
Reverse returns a new slice with the elements in reverse order.
func Sget ¶
Sget performs a cosign signature verification on a given image using the specified public key.
func SliceContains ¶ added in v0.24.0
func SliceContains[T comparable](s []T, e T) bool
SliceContains returns true if the given element is in the slice.
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 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 TransformMapKeys ¶ added in v0.24.0
TransformMapKeys takes a map and transforms its keys using the provided function.
func Unique ¶
func Unique[T comparable](s []T) (r []T)
Unique returns a new slice with only unique elements.
func VerifyBinary ¶
VerifyBinary returns true if binary is available.
Types ¶
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 OrasRemote ¶ added in v0.25.0
type OrasRemote struct { *remote.Repository context.Context Transport *Transport }
OrasRemote is a wrapper around the Oras remote repository that includes a progress bar for interactive feedback.
func NewOrasRemote ¶ added in v0.25.0
func NewOrasRemote(ref registry.Reference) (*OrasRemote, error)
NewOrasRemote returns an oras remote repository client and context for the given reference.
type TextTemplate ¶ added in v0.25.1
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