utils

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package utils provides utility fns for UDS-CLI

Package utils provides utility fns for UDS-CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildVerifyBlobOptions

func BuildVerifyBlobOptions(pkg types.Package, tmpDir string) (*signing.VerifyBlobOptions, error)

BuildVerifyBlobOptions builds VerifyBlobOptions from a package's signing configuration. Writes any inline key/trusted-root content to files in tmpDir (caller owns cleanup). Returns an error if both publicKey and keyless fields are specified together. Returns nil if no signing configuration is present.

func ByteFormat

func ByteFormat(in float64, precision int) string

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

func CanWriteToDir

func CanWriteToDir(dir string) error

CanWriteToDir verifies the process can write to the provided directory

func CheckYAMLSourcePath

func CheckYAMLSourcePath(source string) error

CheckYAMLSourcePath checks if the provided YAML source path is valid

func ConfigureLogs

func ConfigureLogs(cmd *cobra.Command) error

ConfigureLogs sets up the log file, log cache and output for the CLI

func ExtractAllFiles

func ExtractAllFiles(outDirPath string) archives.FileHandler

ExtractAllFiles returns a archives.FileHandler that extracts all the contents of the archive into the provided outDirPath

func ExtractBytes

func ExtractBytes(b *[]byte, expectedFilepath string) archives.FileHandler

ExtractBytes returns an archives.FileHandler that extracts a byte contents of a file from an archive. Returns fs.SkipAll once the target file is found so the archive stream stops decompressing the remaining entries.

func ExtractFile

func ExtractFile(expectedFilepath, outDirPath string) archives.FileHandler

ExtractFile returns an archives.FileHandler that extracts a file from an archive

func ExtractJSON

func ExtractJSON(j any, expectedFilepath string) archives.FileHandler

ExtractJSON extracts and unmarshals a tarballed JSON file into a type. Returns fs.SkipAll once the target file is found so the archive stream stops decompressing the remaining entries.

func GetPackageVerificationStrategy

func GetPackageVerificationStrategy(skipSignatureValidation bool) layout.VerificationStrategy

GetPackageVerificationStrategy determines the package verification strategy in which to pass to the Zarf SDK based on the skipSignatureValidation flag

func GetPkgPath

func GetPkgPath(pkg types.Package, arch string, manifestPath string) (string, error)

GetPkgPath returns the normalized path for a local package

func GetPkgSource

func GetPkgSource(pkg types.Package, arch string, srcDir string) (string, error)

GetPkgSource returns the normalized remote or local source path for a package

func HandleSBOM

func HandleSBOM(extractSBOM bool, SBOMArtifactPathMap map[string]string, bundleName, dstPath string) ([]string, error)

HandleSBOM handles the extraction and creation of bundle SBOMs after populating SBOMArtifactPathMap

func IncludeComponent

func IncludeComponent(componentToCheck string, filteredComponents []v1alpha1.ZarfComponent) bool

IncludeComponent checks if a component has been specified in a a list of components (used for filtering optional components)

func IsRegistryURL

func IsRegistryURL(s string) bool

IsRegistryURL checks if a string is a URL

func IsRemotePkg

func IsRemotePkg(pkg types.Package) bool

IsRemotePkg returns true if the Zarf package is remote

func IsValidTarballPath

func IsValidTarballPath(path string) bool

IsValidTarballPath returns true if the path is a valid tarball path to a bundle tarball

func JSONValue

func JSONValue(value any) (string, error)

JSONValue prints any value as JSON.

func LoadPackage

func LoadPackage(ctx context.Context, source string, opts packager.LoadOptions) (_ *layout.PackageLayout, err error)

LoadPackage fetches and loads a Zarf package from the specified source. Signed packages are verified unless verification is skipped; supplying verification material also requires a signature.

func LoadPackageFromDir

func LoadPackageFromDir(ctx context.Context, dirPath string, opts layout.PackageLayoutOptions) (*layout.PackageLayout, error)

LoadFromDir loads a package from the given directory path. Signed packages are verified unless verification is skipped; supplying verification material also requires a signature.

func NegotiatePlainHTTPForOCIRef

func NegotiatePlainHTTPForOCIRef(ctx context.Context, ref string, insecure bool) (bool, error)

NegotiatePlainHTTPForOCIRef returns whether an OCI registry reference should use plain HTTP. UDS's --insecure option permits plain HTTP, but transport still needs to be negotiated per registry host instead of forced globally.

func NegotiatePlainHTTPForRegistry

func NegotiatePlainHTTPForRegistry(ctx context.Context, registryAddress string, insecure bool) (bool, error)

NegotiatePlainHTTPForRegistry returns whether a registry host should use plain HTTP.

func NormalizeDir

func NormalizeDir(path string) (string, error)

NormalizeDir returns the directory path for the file/dir path specified

func ReadPackageYAML

func ReadPackageYAML(path string) (v1alpha1.ZarfPackage, error)

ReadPackageYAML decodes either supported Zarf package schema and returns the legacy v1alpha1 compatibility view through Zarf's public converter.

func ReadPackageYAMLBytes

func ReadPackageYAMLBytes(data []byte) (v1alpha1.ZarfPackage, error)

ReadPackageYAMLBytes decodes either supported Zarf package schema and returns the legacy v1alpha1 compatibility view through Zarf's public converter.

func ReadYAMLStrict

func ReadYAMLStrict(path string, destConfig any) error

ReadYAMLStrict reads a YAML file into a struct, with strict parsing

func RenderProgressBarForLocalDirWrite

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) float64

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

func SBOMExtractor

func SBOMExtractor(dst string, SBOMArtifactPathMap map[string]string) archives.FileHandler

SBOMExtractor is the extraction fn for extracting HTML and JSON files from an sboms.tar archive

func ToLocalFile

func ToLocalFile(t any, filePath string) error

ToLocalFile takes an arbitrary type, typically a struct, marshals it into JSON and stores it as a local file

func ValidateVerifyBlobConfig

func ValidateVerifyBlobConfig(pkg types.Package) error

ValidateVerifyBlobConfig validates the package signing configuration.

func VerifyBlobOptionsFromKey

func VerifyBlobOptionsFromKey(keyPath string) *signing.VerifyBlobOptions

VerifyBlobOptionsFromKey constructs VerifyBlobOptions from a public key path. Returns nil if keyPath is empty.

Types

This section is empty.

Directories

Path Synopsis
Package boci (bundle OCI) provides OCI utility functions for bundles
Package boci (bundle OCI) provides OCI utility functions for bundles

Jump to

Keyboard shortcuts

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