Documentation
¶
Overview ¶
Package paths provides utilities for working with file and URL paths.
This package implements functions for manipulating, validating, and resolving paths in a consistent manner throughout the application.
Index ¶
- Variables
- func FindRepoRoot(path string) (string, error)
- func FindTopPkgRoot(root, path string) (string, error)
- func ResolveSymbolicLinkRecursive(path string, maxDepth int) (string, error)
- type Base64PathEncoder
- type PathEncoder
- type RandomizedTempPaths
- type ResolvedFileOrDirectoryPath
- type ResolvedFilePath
- type StaticTempPaths
- type TempPaths
Constants ¶
This section is empty.
Variables ¶
var ( ErrMaxNestingLevelReached = errors.New("maximum nesting level reached") ErrResolvePath = errors.New("internal error: failed to resolve path; check logs for more details") ErrURLSchemeNotAllowed = errors.New("the URL scheme is not allowed") ErrResolvedOutsideRepo = errors.New("file resolved to outside repository root") ErrResolvedToRepoRoot = errors.New("path resolved to repository root, which is not allowed") )
Functions ¶
func FindRepoRoot ¶
FindRepoRoot returns topmost (i.e. passing submodules) git repository for the provided path. If no git repository is found, it will return an error.
func FindTopPkgRoot ¶
FindTopPkgRoot finds the topmost `kcl.mod` file for the provided path. It is similar to both kcl-lang.io/kcl-go/pkg/utils.FindPkgRoot and kcl-lang.io/kcl-go/pkg/tools/list.FindPkgInfo, but adds additional guards to prevent resolving outside the provided root. It also searches downward from the provided root and returns the first match, rather than searching upward from the provided path until the filesystem root.
func ResolveSymbolicLinkRecursive ¶
ResolveSymbolicLinkRecursive resolves the symlink path recursively to its canonical path on the file system, with a maximum nesting level of maxDepth. If path is not a symlink, returns the verbatim copy of path and err of nil.
Types ¶
type Base64PathEncoder ¶
type Base64PathEncoder struct{}
func NewBase64PathEncoder ¶
func NewBase64PathEncoder() *Base64PathEncoder
func (*Base64PathEncoder) Encode ¶
func (*Base64PathEncoder) Encode(s string) string
type PathEncoder ¶
type RandomizedTempPaths ¶
type RandomizedTempPaths struct {
// contains filtered or unexported fields
}
RandomizedTempPaths allows generating and memoizing random paths, each path being mapped to a specific key.
func NewRandomizedTempPaths ¶
func NewRandomizedTempPaths(root string) *RandomizedTempPaths
func (*RandomizedTempPaths) Add ¶
func (p *RandomizedTempPaths) Add(key, value string)
func (*RandomizedTempPaths) GetPath ¶
func (p *RandomizedTempPaths) GetPath(key string) (string, error)
GetPath generates a path for the given key or returns previously generated one.
func (*RandomizedTempPaths) GetPathIfExists ¶
func (p *RandomizedTempPaths) GetPathIfExists(key string) string
GetPathIfExists gets a path for the given key if it exists. Otherwise, returns an empty string.
func (*RandomizedTempPaths) GetPaths ¶
func (p *RandomizedTempPaths) GetPaths() map[string]string
GetPaths gets a copy of the map of paths.
type ResolvedFileOrDirectoryPath ¶
type ResolvedFileOrDirectoryPath string
ResolvedFileOrDirectoryPath represents a resolved file or directory path and is intended to prevent unintentional use of an unverified file or directory path. It is an absolute path.
func ResolveFileOrDirectoryPath ¶
func ResolveFileOrDirectoryPath(currentPath, repoRoot, dir string) (ResolvedFileOrDirectoryPath, error)
func (ResolvedFileOrDirectoryPath) String ¶
func (r ResolvedFileOrDirectoryPath) String() string
String returns the resolved absolute file or directory path as a string.
type ResolvedFilePath ¶
type ResolvedFilePath struct {
// contains filtered or unexported fields
}
ResolvedFilePath represents a resolved file path and is intended to prevent unintentional use of an unverified file path. It is always either a URL or an absolute path.
func ResolveFilePathOrURL ¶
func ResolveFilePathOrURL(currentPath, repoRoot, file string, allowedURLSchemes []string) (ResolvedFilePath, error)
ResolveFilePathOrURL will inspect and resolve given file, and make sure that its final path is within the boundaries of the path specified in repoRoot.
`currentPath` is the path we're operating in, e.g. where a Helm chart was unpacked to. `repoRoot` is the path to the root of the repository. If either `currentPath` or `repoRoot` is relative, it will be treated as relative to the current working directory.
`file` is the path to a file, relative to `currentPath`. If `file` is specified as an absolute path (i.e. leading slash), it will be treated as relative to the `repoRoot`. In case `file` is a symlink in the extracted chart, it will be resolved recursively and the decision of whether it is in the boundary of `repoRoot` will be made using the final resolved path. `file` can also be a remote URL with a protocol scheme as prefix, in which case the scheme must be included in the list of allowed schemes specified by allowedURLSchemes.
Will return an error if either `file` is outside the boundaries of the repoRoot, `file` is an URL with a forbidden protocol scheme or if `file` is a recursive symlink nested too deep. May return errors for other reasons as well.
ResolvedFilePath will hold the absolute, resolved path for `file` on success.
func (ResolvedFilePath) String ¶
func (r ResolvedFilePath) String() string
String returns the resolved absolute file path or URL as a string.
type StaticTempPaths ¶
type StaticTempPaths struct {
// contains filtered or unexported fields
}
StaticTempPaths provides a way to generate temporary paths for storing chart archives, in a way that prevents cache poisoning between different Projects. Rather than storing a mapping of key->path in memory (default Argo behavior), this implementation uses very simple bijective encoding/decoding functions to convert keys to paths. This allows cache preservation across multiple KCL run invocations.
func NewStaticTempPaths ¶
func NewStaticTempPaths(root string, pe PathEncoder) *StaticTempPaths
func (*StaticTempPaths) Add ¶
func (p *StaticTempPaths) Add(_, _ string)
func (*StaticTempPaths) GetPath ¶
func (p *StaticTempPaths) GetPath(key string) (string, error)
GetPath generates a path for the given key or returns previously generated one.
func (*StaticTempPaths) GetPathIfExists ¶
func (p *StaticTempPaths) GetPathIfExists(key string) string
GetPathIfExists gets a path for the given key if it exists. Otherwise, returns an empty string.
func (*StaticTempPaths) GetPaths ¶
func (p *StaticTempPaths) GetPaths() map[string]string
GetPaths gets a copy of the map of paths.