Documentation
¶
Index ¶
- func CheckRedirectNoHTTPSDowngrade(req *http.Request, via []*http.Request) error
- func CleanDir(path string) (retErr error)
- func ExtractTar(body io.Reader, destDir string) error
- func InstallFile(filename string, r io.Reader, perm os.FileMode) error
- func InstallFileWithLimitedSize(filename string, r io.Reader, perm os.FileMode, maxBytes int64) error
- func IsDirEmpty(dir string) (bool, error)
- func IsExecutable(filePath string) bool
- func NearestExistingDir(stat func(string) (fs.FileInfo, error), dir string) string
- func ProbeRemoteHTTPObject(ctx context.Context, source string) error
- func ProbeWritableDir(dir string) error
- func RedactHTTPError(err error) error
- func RedactURLQuery(rawURL string) string
- func RemoveAllIfExists(log *slog.Logger, path string) error
- func RemoveFileIfExists(log *slog.Logger, path string) error
- func URLWithoutQuery(rawURL string) string
- func UpdateSymlink(linkPath, targetPath string) error
- func WriteFile(filename string, content []byte, perm os.FileMode) error
- func WriteFileIfChanged(filename string, content []byte, perm os.FileMode) (bool, error)
- type TarFile
- type TarFileSeq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckRedirectNoHTTPSDowngrade ¶ added in v0.2.0
CheckRedirectNoHTTPSDowngrade rejects redirects from an HTTPS source to an insecure destination while allowing redirects that preserve or improve the transport scheme.
func ExtractTar ¶ added in v0.2.0
ExtractTar extracts a tar or gzip-compressed tar stream into destDir. Only directories and regular files are accepted.
func InstallFile ¶
InstallFile writes the content from the provided reader to a local file with specified permissions. It limits the size of the content to 1 GiB and returns an error if the limit is exceeded. It ensures that the target directory exists and handles the file writing atomically.
NOTE: we assume the filename is trusted and cleaned without path traversal characters.
func InstallFileWithLimitedSize ¶ added in v0.2.3
func InstallFileWithLimitedSize(filename string, r io.Reader, perm os.FileMode, maxBytes int64) error
InstallFileWithLimitedSize streams content to a local file with limited size and specified permissions. It ensures that the target directory exists and handles the file writing atomically.
NOTE: we assume the filename is trusted and cleaned without path traversal characters.
func IsDirEmpty ¶
IsDirEmpty reports whether dir is empty or does not exist.
func IsExecutable ¶
func NearestExistingDir ¶ added in v0.9.0
NearestExistingDir returns dir when it is an existing directory, and otherwise the closest ancestor that is.
It exists so a caller can ask whether a path could be created without creating it. Probing the path itself answers a different question: a directory the agent has not made yet is reported as unusable even when its parent is perfectly writable, which is the normal state of an install directory before the first bootstrap.
func ProbeRemoteHTTPObject ¶ added in v0.1.20
ProbeRemoteHTTPObject checks that an HTTP artifact object is reachable without downloading the full object. It first tries HEAD, then falls back to a ranged GET for servers that do not support or incorrectly reject HEAD.
func ProbeWritableDir ¶ added in v0.1.20
ProbeWritableDir verifies that dir accepts file creation and removal without leaving durable state behind.
The directory must already exist. Use NearestExistingDir first to check a path the caller intends to create.
func RedactHTTPError ¶ added in v0.2.0
RedactHTTPError removes query parameters from URL errors returned by the Go HTTP client while preserving the underlying transport error.
func RedactURLQuery ¶ added in v0.2.0
RedactURLQuery removes query parameters from rawURL before it is logged or included in an error message.
func RemoveAllIfExists ¶ added in v0.23.0
RemoveAllIfExists removes a path and everything below it. Removal failures are logged and returned so callers keep ownership of what is left.
func RemoveFileIfExists ¶ added in v0.23.0
RemoveFileIfExists removes a file, ignoring absence and logging and returning any other failure.
func URLWithoutQuery ¶ added in v0.2.0
URLWithoutQuery removes query parameters from rawURL. It returns a redacted placeholder when rawURL cannot be parsed safely.
func UpdateSymlink ¶ added in v0.1.4
UpdateSymlink atomically updates linkPath to point at targetPath.
func WriteFile ¶
WriteFile writes the provided content to a local file with specified permissions. It ensures that the target directory exists and handles the file writing atomically. The temp file is created in the same directory as the destination to preserve the correct SELinux label (avoiding the user_tmp_t label from /tmp).
NOTE: we assume the filename is trusted and cleaned without path traversal characters.
func WriteFileIfChanged ¶ added in v0.9.0
WriteFileIfChanged writes content like WriteFile and reports whether the content differed beforehand.
It exists so a caller that reapplies configuration can tell an actual change from a no-op. Writing unconditionally would be correct on disk but would make every reapply look like a change, so callers that act on one, such as restarting the service that reads the file, would act every time.
Only content is compared. WriteFile preserves an existing file's permissions rather than resetting them to perm, so a drifted mode cannot be corrected here; reporting it as changed would make this return true on every call and restart the reader forever. perm therefore applies only when the file is being created.
Types ¶
type TarFileSeq ¶ added in v0.1.21
func DecompressTarGz ¶ added in v0.1.21
func DecompressTarGz(body io.Reader) TarFileSeq
DecompressTarGz returns an iterator that yields the files contained in a gzip-compressed tar stream.
func DecompressTarGzFromRemote ¶
func DecompressTarGzFromRemote(ctx context.Context, url string) TarFileSeq
DecompressTarGzFromRemote returns an iterator that yields the files contained in a .tar.gz file located at the given HTTP(S) URL.