utils

package
v0.68.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 52 Imported by: 3

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 helper functions.

Package utils provides generic utility functions.

Index

Constants

View Source
const (
	CosignDefaultTimeout = 3 * time.Minute
)

Default cosign configuration

Variables

This section is empty.

Functions

func AddImageNameAnnotation

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

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

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(in 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) error

ColorPrintYAML pretty prints a yaml file to the console.

func CosignSignBlobWithOptions added in v0.66.0

func CosignSignBlobWithOptions(ctx context.Context, blobPath string, opts SignBlobOptions) ([]byte, error)

CosignSignBlobWithOptions signs a blob with comprehensive cosign options. This function supports all cosign v3 sign-blob capabilities by leveraging the embedded KeyOpts structure.

func CosignVerifyBlobWithOptions added in v0.66.0

func CosignVerifyBlobWithOptions(ctx context.Context, blobPath string, opts VerifyBlobOptions) error

CosignVerifyBlobWithOptions verifies a blob signature with comprehensive cosign options. This function supports all cosign v3 verify-blob capabilities by leveraging the embedded KeyOpts and CertVerifyOptions structures.

func DownloadToFile

func DownloadToFile(ctx context.Context, src, dst string) (err error)

DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary).

func ExecuteWait

func ExecuteWait(ctx context.Context, 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

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

GetCosignArtifacts returns signatures and attestations for the given image

func GetFinalExecutableCommand

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 LoadOCIImage

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 RoundUp

func RoundUp(input float64, places int) float64

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

func SortImagesIndex added in v0.42.0

func SortImagesIndex(ociPath string) error

SortImagesIndex sorts the index.json by digest.

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

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, error)

FindAuthForHost finds the authentication scheme for a given host using .git-credentials then .netrc.

type SignBlobOptions added in v0.66.0

type SignBlobOptions struct {
	// Embed Cosign's KeyOpts for signing configuration
	options.KeyOpts

	// Certificate signing support - X.509 certificate
	Cert      string
	CertChain string

	// Zarf-specific options for output control
	OutputSignature   string // Custom path for signature file
	OutputCertificate string // Where to write certificate (keyless mode)

	// General options
	Verbose bool          // Enable debug output
	Timeout time.Duration // Timeout for signing operations

	// Password provides password for encrypted keys without requiring cosign.PassFunc import
	Password string
}

SignBlobOptions embeds Cosign's native options and adds Zarf-specific configuration. By embedding options.KeyOpts, we get direct access to all Cosign signing capabilities while maintaining a clean interface for Zarf users.

func DefaultSignBlobOptions added in v0.66.0

func DefaultSignBlobOptions() SignBlobOptions

DefaultSignBlobOptions returns SignBlobOptions with Zarf defaults. Configures sensible defaults for offline/air-gapped environments.

func (SignBlobOptions) ShouldSign added in v0.66.0

func (opts SignBlobOptions) ShouldSign() bool

ShouldSign returns true if the options indicate that signing should be performed. This checks if any signing key material is configured (KeyRef, IDToken, or Sk).

type VerifyBlobOptions added in v0.66.0

type VerifyBlobOptions struct {
	// Embed Cosign's KeyOpts for key-based verification
	options.KeyOpts

	// Embed Cosign's CertVerifyOptions for certificate-based (keyless) verification
	options.CertVerifyOptions

	// Verification-specific options
	SigRef     string // Path to signature file
	Offline    bool   // Enable offline verification mode
	IgnoreTlog bool   // Skip transparency log verification

	// General options
	Timeout time.Duration // Timeout for verification operations
}

VerifyBlobOptions embeds Cosign's native options for verification. By embedding options.KeyOpts and options.CertVerifyOptions, we get direct access to all Cosign verification capabilities.

func DefaultVerifyBlobOptions added in v0.66.0

func DefaultVerifyBlobOptions() VerifyBlobOptions

DefaultVerifyBlobOptions returns VerifyBlobOptions with Zarf defaults. Configures sensible defaults for offline/air-gapped environments.

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