Last active
August 15, 2021 15:01
-
-
Save slayer321/76a9d5224d899895458708030ce51de2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func JSONPatchPathHasForwardSlash(patch string) bool { | |
jsonPatch, err := yaml.ToJSON([]byte(patch)) | |
if err != nil { | |
return err | |
} | |
decodedPatch, err := jsonpatch.DecodePatch(jsonPatch) | |
if err != nil { | |
return err | |
} | |
for _, operation := range decodedPatch { | |
path, err := operation.Path() | |
if err != nil { | |
return err | |
} | |
out ,err := regexp.MatchString(`^/`, path) | |
if err != nil{ | |
return fmt.Errorf("Path :" , err) | |
} | |
return out | |
//vars := variables.RegexVariables.FindAllString(path, -1) | |
//if len(vars) > 0 { | |
//return fmt.Errorf("Operation \"%s\" has forbidden variables", operation.Kind()) | |
//} | |
} | |
return nil | |
} | |
//https://github.com/kyverno/kyverno/blob/0fdd349849eeee491fdf6aa651eea6d0422f2a97/pkg/policy/validate.go#L52 | |
for i, rule := range p.Spec.Rules { | |
..... | |
if JSONPatchPathHasForwardSlash(rule) { | |
return fmt.Errorf("path: spec.rules[%d]: %v", i, err) | |
} | |
..... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment