Skip to content

Commit e1bcd47

Browse files
authored
Merge pull request #26 from yaacov/allow-labels-and-annotation-field-validation
Allow labels and annotation field validation
2 parents 5403e67 + 1c43139 commit e1bcd47

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/cmd/sql-sql.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ import (
1616

1717
// isValidFieldIdentifier checks if a field name matches the allowed pattern
1818
func isValidFieldIdentifier(field string) bool {
19+
// Check for labels.* pattern
20+
if strings.HasPrefix(field, "labels.") {
21+
labelKey := field[7:] // Remove "labels." prefix
22+
// K8s label keys: alphanumeric, hyphens, underscores, dots
23+
// Must start and end with alphanumeric character
24+
labelPattern := `^[a-zA-Z0-9]([a-zA-Z0-9\-_.]*[a-zA-Z0-9])?$`
25+
match, _ := regexp.MatchString(labelPattern, labelKey)
26+
return match
27+
}
28+
29+
// Check for annotations.* pattern
30+
if strings.HasPrefix(field, "annotations.") {
31+
annotationKey := field[12:] // Remove "annotations." prefix
32+
// K8s annotation keys: similar to labels but more flexible
33+
// Can contain alphanumeric, hyphens, underscores, dots, and slashes
34+
annotationPattern := `^[a-zA-Z0-9]([a-zA-Z0-9\-_./]*[a-zA-Z0-9])?$`
35+
match, _ := regexp.MatchString(annotationPattern, annotationKey)
36+
return match
37+
}
38+
1939
// Matches patterns like:
2040
// - simple: name, first_name, my.field
2141
// - array access: items[0], my.array[123]

0 commit comments

Comments
 (0)