normalizeLabel canonicalizes a single label (lowercase, charset [a-z0-9:_-], 1..maxLabelLength). allowSystem mirrors the read-side allowSystemPrefix=true: filtering by an e2a: system label is permitted.
(raw string, allowSystem bool)
| 613 | // [a-z0-9:_-], 1..maxLabelLength). allowSystem mirrors the read-side |
| 614 | // allowSystemPrefix=true: filtering by an e2a: system label is permitted. |
| 615 | func normalizeLabel(raw string, allowSystem bool) (string, error) { |
| 616 | l := strings.ToLower(strings.TrimSpace(raw)) |
| 617 | if l == "" { |
| 618 | return "", errors.New("label must not be empty") |
| 619 | } |
| 620 | if len(l) > maxLabelLength { |
| 621 | return "", fmt.Errorf("label too long (max %d chars)", maxLabelLength) |
| 622 | } |
| 623 | for _, r := range l { |
| 624 | switch { |
| 625 | case r >= 'a' && r <= 'z': |
| 626 | case r >= '0' && r <= '9': |
| 627 | case r == '-' || r == '_' || r == ':': |
| 628 | default: |
| 629 | return "", fmt.Errorf("label %q has invalid character; allowed: a-z 0-9 : - _", l) |
| 630 | } |
| 631 | } |
| 632 | if !allowSystem && strings.HasPrefix(l, labelSystemPrefix) { |
| 633 | return "", fmt.Errorf("labels starting with %q are reserved for system use", labelSystemPrefix) |
| 634 | } |
| 635 | return l, nil |
| 636 | } |
| 637 | |
| 638 | // normalizeLabelFilter validates + dedups a labels= filter list. |
| 639 | func normalizeLabelFilter(raw []string) ([]string, error) { |
no outgoing calls
no test coverage detected