Documentation
¶
Overview ¶
Package utils is for commonly used functions.
Package utils is for commonly used functions
Index ¶
- Constants
- func CreateDirectory(path string, mode os.FileMode) error
- func DownloadToCache(ctx context.Context, url, relPath string, expectedSha256 ...string) (string, error)
- func DownloadToFile(ctx context.Context, src, dst string) (err error)
- func DownloadToFileWithChecksum(ctx context.Context, src, dst, checksum, cacheBaseName string) (err error)
- func FilterDebianLinux(h *cluster.ZarfHost) bool
- func FilterEngineAlreadyPopulated(h *cluster.ZarfHost) bool
- func FilterEnterpriseLinux(h *cluster.ZarfHost) bool
- func IdentifySource(src string) (string, error)
- func InvalidPath(path string) bool
- func IsDebianLinux(con os.Configurer) bool
- func IsEnterpriseLinux(con os.Configurer) bool
- func MakeTempDir(basePath string) (string, error)
- func ParseChecksum(src string) (string, string, error)
- func ParseRetryAfter(value string) time.Duration
- func PrintJSON(obj any) string
- func RandomString(length int) (string, error)
- func ReadByteStrict(data []byte, destConfig any) error
- func ReadYAMLStrict(path string, destConfig any) error
- func ResolveCachePath(cachePath string) (string, error)
Constants ¶
const ( // TmpPathPrefix is the shared prefix used for all temporary directories TmpPathPrefix = "cargoship-" // ReadWriteExecuteUser is used for any directory or executable not normally used by the end user or containing sensitive data ReadWriteExecuteUser = 0700 )
const CacheDir = "cargoship"
CacheDir is the subdirectory name used under the OS user cache directory for cargoship's shared cache.
Variables ¶
This section is empty.
Functions ¶
func CreateDirectory ¶
CreateDirectory creates a directory for the given path and file mode.
func DownloadToCache ¶
func DownloadToCache(ctx context.Context, url, relPath string, expectedSha256 ...string) (string, error)
DownloadToCache downloads a URL into the given relative path under cargoship's cache directory if not already cached. If expectedSha256 is provided (optional), it validates that the cached or downloaded file matches the sha256 checksum.
func DownloadToFile ¶
DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary). When src contains an inline checksum in the form URL@sha256, that checksum is used. For struct-based callers, prefer DownloadToFileWithChecksum.
func DownloadToFileWithChecksum ¶
func DownloadToFileWithChecksum(ctx context.Context, src, dst, checksum, cacheBaseName string) (err error)
DownloadToFileWithChecksum downloads src to dst, using checksum (if non-empty) for validation and caching. checksum SHOULD come from structured config (e.g. ZarfFile.Shasum) rather than being encoded into src.
func FilterDebianLinux ¶
FilterDebianLinux is a function used to filter whether a host is a Debian based OS
func FilterEngineAlreadyPopulated ¶
FilterEngineAlreadyPopulated is a function used to filter whether a host already has distro files populated
func FilterEnterpriseLinux ¶
FilterEnterpriseLinux is a function used to filter whether a host is an Enterprise Linux OS
func IdentifySource ¶
IdentifySource returns the source type for the given source string.
func InvalidPath ¶
InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access)
func IsDebianLinux ¶
func IsDebianLinux(con os.Configurer) bool
IsDebianLinux is true if the os.Configurer is of a type of Debian based OS
func IsEnterpriseLinux ¶
func IsEnterpriseLinux(con os.Configurer) bool
IsEnterpriseLinux is true if the os.Configurer is of a type of Enterprise Linux
func MakeTempDir ¶
MakeTempDir creates a temp directory with the zarf- prefix.
func ParseChecksum ¶
ParseChecksum splits an inline checksum off the end of a source string, of the form URL@checksum. A single '@' is left alone when the URL parses with userinfo (user@host), so a credential embedded in the URL is never mistaken for a checksum suffix.
func ParseRetryAfter ¶
ParseRetryAfter parses the Retry-After header value into a duration. It supports both delay-seconds (integer) and HTTP-date formats.
func RandomString ¶
RandomString returns a string of hexadecimal characters of a given length that is cryptographically secure, or an error
func ReadByteStrict ¶
ReadByteStrict reads a byte array and tries to place it in the provided "destConfig" object
func ReadYAMLStrict ¶
ReadYAMLStrict reads a YAML file into a struct, with strict parsing
func ResolveCachePath ¶
ResolveCachePath returns cachePath if non-empty, otherwise falls back to filepath.Join(os.UserCacheDir(), "cargoship") which respects XDG_CACHE_HOME on Linux.
Types ¶
This section is empty.