Add public bundle manifest package
This commit is contained in:
31
pkg/bundle/path.go
Normal file
31
pkg/bundle/path.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const distributorStateName = ".distributor.json"
|
||||
|
||||
func ValidateSourcePath(value string) error {
|
||||
if value == "" {
|
||||
return fmt.Errorf("source path is required")
|
||||
}
|
||||
if strings.Contains(value, "\\") || strings.HasPrefix(value, "/") {
|
||||
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
||||
}
|
||||
if path.Clean(value) != value {
|
||||
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
||||
}
|
||||
for _, segment := range strings.Split(value, "/") {
|
||||
if segment == "" || segment == "." || segment == ".." {
|
||||
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
||||
}
|
||||
}
|
||||
switch value {
|
||||
case ManifestName, distributorStateName:
|
||||
return fmt.Errorf("%q is reserved", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user