GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(config): add secrets field to RedactSpec, update validation · majorcontext/keep@dc301a6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal/config
    • config.go
    • validate.go
    • validate_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/config/config.go‎

Copy file name to clipboardExpand all lines: internal/config/config.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const (
5656
// RedactSpec defines what to redact and how.
5757
type RedactSpec struct {
5858
Target string `yaml:"target"`
59-
Patterns []RedactPattern `yaml:"patterns"`
59+
Secrets bool `yaml:"secrets,omitempty"`
60+
Patterns []RedactPattern `yaml:"patterns,omitempty"`
6061
}
6162

6263
// RedactPattern is a regex pattern and its replacement.
Collapse file

‎internal/config/validate.go‎

Copy file name to clipboardExpand all lines: internal/config/validate.go
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var reservedDefNames = map[string]bool{
132132
"upper": true,
133133
"matchesDomain": true,
134134
"dayOfWeek": true,
135+
"hassecrets": true,
135136
"int": true,
136137
"uint": true,
137138
"double": true,
@@ -184,9 +185,9 @@ func validateRedact(i int, spec *RedactSpec) []error {
184185
errs = append(errs, fmt.Errorf("rules[%d]: redact target %q must be a params.* path", i, spec.Target))
185186
}
186187

187-
// patterns must be non-empty and not exceed maxPatternsPerRedact
188-
if len(spec.Patterns) == 0 {
189-
errs = append(errs, fmt.Errorf("rules[%d]: redact patterns must not be empty", i))
188+
// Must have secrets: true or non-empty patterns (or both)
189+
if !spec.Secrets && len(spec.Patterns) == 0 {
190+
errs = append(errs, fmt.Errorf("rules[%d]: redact requires secrets: true or non-empty patterns", i))
190191
} else if len(spec.Patterns) > maxPatternsPerRedact {
191192
errs = append(errs, fmt.Errorf("rules[%d]: redact patterns: %d patterns exceeds maximum of %d", i, len(spec.Patterns), maxPatternsPerRedact))
192193
} else {
Collapse file

‎internal/config/validate_test.go‎

Copy file name to clipboardExpand all lines: internal/config/validate_test.go
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,56 @@ func TestValidate_DefsValueTooLong(t *testing.T) {
509509
}
510510
}
511511

512+
func TestValidate_RedactSecretsOnly(t *testing.T) {
513+
rf := &RuleFile{
514+
Scope: "test-scope",
515+
Rules: []Rule{
516+
{
517+
Name: "redact-secrets",
518+
Match: Match{Operation: "llm.text"},
519+
Action: ActionRedact,
520+
Redact: &RedactSpec{
521+
Target: "params.text",
522+
Secrets: true,
523+
},
524+
},
525+
},
526+
}
527+
if err := Validate(rf); err != nil {
528+
t.Errorf("expected secrets-only redact rule to be valid, got: %v", err)
529+
}
530+
}
531+
532+
func TestValidate_RedactNoSecretsNoPatterns(t *testing.T) {
533+
rf := &RuleFile{
534+
Scope: "test-scope",
535+
Rules: []Rule{
536+
{
537+
Name: "bad-redact",
538+
Match: Match{Operation: "llm.text"},
539+
Action: ActionRedact,
540+
Redact: &RedactSpec{
541+
Target: "params.text",
542+
},
543+
},
544+
},
545+
}
546+
if err := Validate(rf); err == nil {
547+
t.Error("expected error for redact rule with no secrets and no patterns")
548+
}
549+
}
550+
551+
func TestValidate_DefNameHasSecrets(t *testing.T) {
552+
rf := &RuleFile{
553+
Scope: "test-scope",
554+
Rules: []Rule{
555+
{Name: "r1", Match: Match{Operation: "op"}, Action: ActionLog},
556+
},
557+
Defs: map[string]string{"hassecrets": "'shadowed'"},
558+
}
559+
err := Validate(rf)
560+
if err == nil || !strings.Contains(err.Error(), "shadows") {
561+
t.Errorf("expected shadow error for hasSecrets def, got: %v", err)
562+
}
563+
}
564+

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.