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.
Index ¶
- Constants
- func AddImageNameAnnotation(ociPath string, referenceToDigest map[string]string) error
- func AddRootHint(hints map[string]string, rootKey string, hintText string) map[string]string
- func AddRootListHint(hints map[string]string, listKey string, listValue string, hintText string) map[string]string
- func ByteFormat(in float64, precision int) string
- func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool) error
- func CosignSignBlobWithOptions(ctx context.Context, blobPath string, opts SignBlobOptions) ([]byte, error)
- func CosignVerifyBlobWithOptions(ctx context.Context, blobPath string, opts VerifyBlobOptions) error
- func DownloadToFile(ctx context.Context, src, dst string) (err error)
- func FindYamlTemplates(config any, prefix string, suffix string) (map[string]string, error)
- func GetCosignArtifacts(image string) ([]string, error)
- func GetFinalExecutableCommand() (string, error)
- func GetFinalExecutablePath() (string, error)
- func GetHtpasswdString(username string, password string) (string, error)
- func LoadOCIImage(imgPath string, refInfo transform.Image) (v1.Image, error)
- func MakeTempDir(basePath string) (string, error)
- func ReadYaml(path string, destConfig any) error
- func ReloadYamlTemplate(config any, mappings map[string]string) error
- func ResolveCachePath(cachePath string) (string, error)
- func RoundUp(input float64, places int) float64
- func SortImagesIndex(ociPath string) error
- func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)
- func SplitYAMLToString(yamlData []byte) ([]string, error)
- func WriteYaml(path string, srcConfig any, perm fs.FileMode) error
- type Credential
- type SignBlobOptions
- type VerifyBlobOptions
Constants ¶
const CosignDefaultTimeout = 3 * time.Minute
CosignDefaultTimeout is the default timeout for cosign sign and verify operations.
Variables ¶
This section is empty.
Functions ¶
func AddImageNameAnnotation ¶
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 ¶
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 ¶
ByteFormat formats a number of bytes into a human-readable string.
func ColorPrintYAML ¶
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 via cosign's SignBlobCmd. Mirrors cmd/cosign/cli/signblob.go (v3.0.6) SignBlob().RunE.
func CosignVerifyBlobWithOptions ¶ added in v0.66.0
func CosignVerifyBlobWithOptions(ctx context.Context, blobPath string, opts VerifyBlobOptions) error
CosignVerifyBlobWithOptions verifies a blob via cosign's VerifyBlobCmd. Mirrors cmd/cosign/cli/verify.go (v3.0.6) VerifyBlob().RunE.
func DownloadToFile ¶
DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary).
func FindYamlTemplates ¶
FindYamlTemplates finds strings with a given prefix in a config.
func GetCosignArtifacts ¶
GetCosignArtifacts returns signatures and attestations for the given image.
func GetFinalExecutableCommand ¶
GetFinalExecutableCommand returns the final path to the Zarf executable including and library prefixes and overrides.
func GetFinalExecutablePath ¶
GetFinalExecutablePath returns the absolute path to the current 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 LoadOCIImage ¶
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 ¶
MakeTempDir creates a temp directory with the zarf- prefix.
func ReloadYamlTemplate ¶
ReloadYamlTemplate marshals a given config, replaces strings and unmarshals it back.
func ResolveCachePath ¶ added in v0.75.0
ResolveCachePath returns cachePath if non-empty, otherwise falls back to filepath.Join(os.UserCacheDir(), "zarf") which respects XDG_CACHE_HOME on Linux.
func SortImagesIndex ¶ added in v0.42.0
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 ¶
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.
Types ¶
type Credential ¶
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 {
options.SignBlobOptions
Verbose bool
Timeout time.Duration
Password string
PassFunc cosign.PassFunc
Overwrite bool
// Deprecated: use Key (promoted from the embedded SignBlobOptions). Removed in v1.0.
KeyRef string
}
SignBlobOptions wraps cosign's SignBlobOptions with zarf-specific fields.
func DefaultSignBlobOptions ¶ added in v0.66.0
func DefaultSignBlobOptions() SignBlobOptions
DefaultSignBlobOptions returns SignBlobOptions seeded with zarf defaults. Divergence: TlogUpload defaults to false (cosign default true) for airgap.
func (SignBlobOptions) CheckOverwrite ¶ added in v0.71.0
func (opts SignBlobOptions) CheckOverwrite(ctx context.Context) error
CheckOverwrite errors if any output file exists and Overwrite is false.
func (SignBlobOptions) ShouldSign ¶ added in v0.66.0
func (opts SignBlobOptions) ShouldSign() bool
ShouldSign returns true if any signing key material is configured. KeyRef is included for backward compatibility; it's synced to Key in CosignSignBlobWithOptions.
type VerifyBlobOptions ¶ added in v0.66.0
type VerifyBlobOptions struct {
options.VerifyBlobOptions
Timeout time.Duration
// Deprecated: use Key (promoted from the embedded VerifyBlobOptions). Removed in v1.0.
KeyRef string
// Deprecated: use Signature (promoted from the embedded VerifyBlobOptions). Removed in v1.0.
SigRef string
}
VerifyBlobOptions wraps cosign's VerifyBlobOptions with zarf-specific fields.
func DefaultVerifyBlobOptions ¶ added in v0.66.0
func DefaultVerifyBlobOptions() VerifyBlobOptions
DefaultVerifyBlobOptions returns VerifyBlobOptions seeded with zarf defaults. Divergences: IgnoreTlog and IgnoreSCT default to true (cosign default false) for airgap.