utils

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 55 Imported by: 6

Documentation

Overview

Package utils provides generic utility functions.

Package utils provides generic utility 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 helper functions.

Package utils provides generic utility functions.

Package utils provides generic helper functions.

Package utils provides generic utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddImageNameAnnotation added in v0.28.3

func AddImageNameAnnotation(ociPath string, referenceToDigest map[string]string) error

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

func AddRootHint(hints map[string]string, rootKey string, hintText string) map[string]string

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

func ByteFormat(inputNum float64, precision int) string

ByteFormat formats a number of bytes into a human readable string.

func ColorPrintYAML

func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool)

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

func CosignVerifyBlob(blobRef string, sigRef string, keyPath string) error

CosignVerifyBlob verifies the zarf.yaml.sig was signed with the key provided by the flag

func DownloadToFile

func DownloadToFile(src string, dst string, cosignKeyPath string) (err error)

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

func FindYamlTemplates(config any, prefix string, suffix string) (map[string]string, error)

FindYamlTemplates finds strings with a given prefix in a config.

func GetCosignArtifacts added in v0.30.1

func GetCosignArtifacts(image string) (cosignList []string, err error)

GetCosignArtifacts returns signatures and attestations for the given image

func GetFinalExecutableCommand added in v0.30.0

func GetFinalExecutableCommand() (string, error)

GetFinalExecutableCommand returns the final path to the Zarf executable including and library prefixes and overrides.

func GetFinalExecutablePath

func GetFinalExecutablePath() (string, error)

GetFinalExecutablePath returns the absolute path to the current executable, following any symlinks along the way.

func GetHtpasswdString

func GetHtpasswdString(username string, password string) (string, error)

GetHtpasswdString converts a username and password to a properly formatted and hashed format for `htpasswd`.

func HasImageLayers added in v0.30.1

func HasImageLayers(img v1.Image) (bool, error)

HasImageLayers checks if any layers in the v1.Image are known image layers.

func LoadOCIImage added in v0.26.0

func LoadOCIImage(imgPath string, refInfo transform.Image) (v1.Image, error)

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

func MakeTempDir(basePath string) (string, error)

MakeTempDir creates a temp directory with the zarf- prefix.

func ReadYaml

func ReadYaml(path string, destConfig any) error

ReadYaml reads a yaml file and unmarshals it into a given config.

func ReloadYamlTemplate

func ReloadYamlTemplate(config any, mappings map[string]string) error

ReloadYamlTemplate marshals a given config, replaces strings and unmarshals it back.

func RenderProgressBarForLocalDirWrite added in v0.25.0

func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, completeChan chan error, 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 RoundUp

func RoundUp(input float64, places int) (newVal float64)

RoundUp rounds a float64 to the given number of decimal places.

func Sget

func Sget(ctx context.Context, image, key string, out io.Writer) error

Sget performs a cosign signature verification on a given image using the specified public key.

Forked from https://github.com/sigstore/cosign/blob/v1.7.1/pkg/sget/sget.go

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

func SplitFile(srcPath string, chunkSizeBytes int) (err error)

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

func SplitYAMLToString(yamlData []byte) ([]string, error)

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 WriteYaml

func WriteYaml(path string, srcConfig any, perm fs.FileMode) error

WriteYaml writes a given config to a yaml file on disk.

Types

type Credential

type Credential struct {
	Path string
	Auth http.BasicAuth
}

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

type Dependency interface {
	Name() string
	Dependencies() []string
}

Dependency is an interface that represents a node in a list of dependencies.

Directories

Path Synopsis
Package exec provides a wrapper around the os/exec package
Package exec provides a wrapper around the os/exec package

Jump to

Keyboard shortcuts

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