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.
Index ¶
- Constants
- func ByteFormat(inputNum float64, precision int) string
- func ColorPrintYAML(data any)
- 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(url string, target string, cosignKeyPath string)
- func ExecCommandWithContext(ctx context.Context, showLogs bool, commandName string, args ...string) (string, string, error)
- func ExecCommandWithContextAndDir(ctx context.Context, dir string, showLogs bool, commandName string, ...) (string, string, error)
- func ExecLaunchURL(url string) error
- func Fetch(url string) io.ReadCloser
- func FindYamlTemplates(config any, prefix string, suffix string) (map[string]*string, error)
- func GetAvailablePort() (int, error)
- func GetFinalExecutablePath() (string, error)
- func GetHtpasswdString(username string, password string) (string, error)
- func GetSha256Sum(path string) (string, error)
- func InvalidPath(path string) bool
- func IsTextFile(path string) (bool, error)
- func IsURL(source string) bool
- func ListDirectories(directory string) ([]string, error)
- func MakeTempDir(tmpDir string) (string, error)
- func RandomString(length int) string
- func ReadYaml(path string, destConfig any) error
- func RecursiveFileList(dir string, pattern *regexp.Regexp) (files []string, err error)
- func ReloadYamlTemplate(config any, mappings map[string]string) error
- func ReplaceTextTemplate(path string, mappings map[string]string, deprecations map[string]string)
- func Retry(fn func() error, retries int, delay time.Duration) (err error)
- func RoundUp(input float64, places int) (newVal float64)
- func RunPreflightChecks()
- func Sget(ctx context.Context, image, key string, out io.Writer) error
- func SplitFile(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
- func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
- func SwapHost(src string, targetHost string) (string, error)
- func SwapHostWithoutChecksum(src string, targetHost string) (string, error)
- func Unique[T comparable](s []T) []T
- func VerifyBinary(binary string) bool
- func WriteFile(path string, data []byte) error
- func WriteYaml(path string, srcConfig any, perm fs.FileMode) error
- type Credential
- type Image
Constants ¶
const SGETProtocol = "sget://"
SGETProtocol is the protocol URI scheme for SGET.
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 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 ExecCommandWithContext ¶
func ExecCommandWithContext(ctx context.Context, showLogs bool, commandName string, args ...string) (string, string, error)
ExecCommandWithContext executes a given command with args in the current working directory.
func ExecCommandWithContextAndDir ¶
func ExecCommandWithContextAndDir(ctx context.Context, dir string, showLogs bool, commandName string, args ...string) (string, string, error)
ExecCommandWithContextAndDir executes a given command with args in the specified directory.
func ExecLaunchURL ¶
ExecLaunchURL opens the default web browser to the given URL.
func FindYamlTemplates ¶
FindYamlTemplates finds strings with a given prefix in a config.
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 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 GetSha256Sum ¶
GetSha256Sum returns the computed SHA256 Sum of a given file.
func IsTextFile ¶ added in v0.23.3
IsTextFile returns true if the given file is a text file.
func ListDirectories ¶
ListDirectories returns a list of directories in the given directory.
func MakeTempDir ¶
MakeTempDir creates a temp directory with the given prefix.
func RandomString ¶
RandomString generates a secure random string of the specified length.
func RecursiveFileList ¶
RecursiveFileList walks a path with an optional regex pattern and returns a slice of file paths.
func ReloadYamlTemplate ¶
ReloadYamlTemplate marshals a given config, replaces strings and unmarshals it back.
func ReplaceTextTemplate ¶
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 RunPreflightChecks ¶
func RunPreflightChecks()
RunPreflightChecks runs pre-flight checks before Zarf begins a deployment.
func Sget ¶
Sget performs a cosign signature verification on a given image using the specified public key.
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 SwapHost ¶
SwapHost Perform base url replacement and adds a crc32 of the original url to the end of the src.
func SwapHostWithoutChecksum ¶
SwapHostWithoutChecksum Perform base url replacement but avoids adding a checksum of the original url.
func Unique ¶
func Unique[T comparable](s []T) []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.