ValidateLabel validates that the specified string is a valid label, and returns it. Labels are in the form of key=value; key must be a non-empty string, and not contain whitespaces. A value is optional (defaults to an empty string if omitted). Leading whitespace is removed during validation but va
(value string)
| 237 | // TODO discuss if quotes (and other special characters) should be valid or invalid for keys |
| 238 | // TODO discuss if leading/trailing whitespace in keys should be preserved (and valid) |
| 239 | func ValidateLabel(value string) (string, error) { |
| 240 | key, _, _ := strings.Cut(value, "=") |
| 241 | key = strings.TrimLeft(key, whiteSpaces) |
| 242 | if key == "" { |
| 243 | return "", fmt.Errorf("invalid label '%s': empty name", value) |
| 244 | } |
| 245 | if strings.ContainsAny(key, whiteSpaces) { |
| 246 | return "", fmt.Errorf("label '%s' contains whitespaces", key) |
| 247 | } |
| 248 | return value, nil |
| 249 | } |
| 250 | |
| 251 | // ValidateSysctl validates a sysctl and returns it. |
| 252 | func ValidateSysctl(val string) (string, error) { |
no outgoing calls
searching dependent graphs…