annotation validation: validate regex in common name annotation (#10657)
* fix common name validation * add tests
This commit is contained in:
parent
5a72a42235
commit
05d68a1512
3 changed files with 71 additions and 3 deletions
|
|
@ -117,6 +117,20 @@ func ValidateRegex(regex *regexp.Regexp, removeSpace bool) AnnotationValidator {
|
|||
}
|
||||
}
|
||||
|
||||
// CommonNameAnnotationValidator checks whether the annotation value starts with
|
||||
// 'CN=' and is followed by a valid regex.
|
||||
func CommonNameAnnotationValidator(s string) error {
|
||||
if !strings.HasPrefix(s, "CN=") {
|
||||
return fmt.Errorf("value %s is not a valid Common Name annotation: missing prefix 'CN='", s)
|
||||
}
|
||||
|
||||
if _, err := regexp.Compile(s[3:]); err != nil {
|
||||
return fmt.Errorf("value %s is not a valid regex: %w", s, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateOptions receives an array of valid options that can be the value of annotation.
|
||||
// If no valid option is found, it will return an error
|
||||
func ValidateOptions(options []string, caseSensitive, trimSpace bool) AnnotationValidator {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue