mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add load_restrictor flag.
This commit is contained in:
@@ -19,9 +19,50 @@ package loader
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=loadRestrictions
|
||||
type loadRestrictions int
|
||||
|
||||
const (
|
||||
unknown loadRestrictions = iota
|
||||
rootOnly
|
||||
none
|
||||
)
|
||||
|
||||
const (
|
||||
flagName = "load_restrictor"
|
||||
)
|
||||
|
||||
var (
|
||||
flagValue = rootOnly.String()
|
||||
flagHelp = "if set to '" + none.String() +
|
||||
"', local kustomizations may load files from outside their root. " +
|
||||
"This does, however, break the relocatability of the kustomization."
|
||||
)
|
||||
|
||||
func AddLoadRestrictionsFlag(set *pflag.FlagSet) {
|
||||
set.StringVar(
|
||||
&flagValue, flagName,
|
||||
rootOnly.String(), flagHelp)
|
||||
}
|
||||
|
||||
func ValidateLoadRestrictorFlag() (LoadRestrictorFunc, error) {
|
||||
switch flagValue {
|
||||
case rootOnly.String():
|
||||
return RestrictionRootOnly, nil
|
||||
case none.String():
|
||||
return RestrictionNone, nil
|
||||
default:
|
||||
return nil, fmt.Errorf(
|
||||
"illegal flag value --%s %s; legal values: %v",
|
||||
flagName, flagValue,
|
||||
[]string{rootOnly.String(), none.String()})
|
||||
}
|
||||
}
|
||||
|
||||
type LoadRestrictorFunc func(
|
||||
fs.FileSystem, fs.ConfirmedDir, string) (string, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user