mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
* pkg/cwhub: improve support for k8s config maps as custom items - allow links to links - ignore hidden ..data directories, but allow links to their content * allow any number of subdirectories in /etc/crowdsec/{hubtype} * item name as subdir/file.yaml * improve func test * lint
28 lines
656 B
Go
28 lines
656 B
Go
package cwhub
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// relativePathComponents returns the list of path components after baseDir.
|
|
// If path is not inside baseDir, it returns an empty slice.
|
|
func relativePathComponents(path string, baseDir string) []string {
|
|
absPath, err := filepath.Abs(path)
|
|
if err != nil {
|
|
return []string{}
|
|
}
|
|
|
|
absBaseDir, err := filepath.Abs(baseDir)
|
|
if err != nil {
|
|
return []string{}
|
|
}
|
|
|
|
// is path inside baseDir?
|
|
relPath, err := filepath.Rel(absBaseDir, absPath)
|
|
if err != nil || strings.HasPrefix(relPath, "..") || relPath == "." {
|
|
return []string{}
|
|
}
|
|
|
|
return strings.Split(relPath, string(filepath.Separator))
|
|
}
|