Skip to content

Commit e0f14b1

Browse files
committed
feat(eql-codegen): print and log every Go EQL type redacted
A Go EQL value is the JSON its column stores: a stored value holds ciphertext and terms, and a query value holds terms. Until now each type was a bare []byte to fmt and slog, so %s or a log line wrote those bytes out. The compiled predicate Match returns (#1443) is the first operand a caller is likely to log whole, so every generated type now gets String, Format and LogValue, written by eql-codegen beside Value and Scan so no type can be missed. All three write one text, the type's name and [redacted] (or {} when empty); Format answers every verb, %#v included, so no GoString is generated. Value, MarshalJSON and a []byte or string conversion still give the JSON. The helpers (text, format, logValue) are hand-written in eql.go, so the generated methods stay one-line block bodies gofmt leaves alone. A codegen test checks every `type X []byte` the file declares has all three.
1 parent 52802ef commit e0f14b1

4 files changed

Lines changed: 1824 additions & 9 deletions

File tree

‎languages/golang/encrypt/eql/eql.go‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
// the guest returns and never assembles an EQL value itself (ADR-0007,
99
// amended 2026-10-06). Each type implements driver.Valuer and sql.Scanner
1010
// for one column, and json.Marshaler, which writes the value as the JSON
11-
// it is.
11+
// it is. It prints (fmt.Stringer, fmt.Formatter, for every verb) and logs
12+
// (slog.LogValuer) as its type's name and never its bytes, so fmt.Sprint
13+
// and %s do not give its JSON: a stored value holds ciphertext and terms,
14+
// and a query value terms. The JSON is the value itself, a []byte:
15+
// convert it (string(v), json.RawMessage(v)), or call MarshalJSON.
1216
//
1317
// Importing this package links the build of the engine that holds the EQL
1418
// types: eql_gen.go's init registers the embedded module with package
@@ -28,6 +32,8 @@ import (
2832
"encoding/json"
2933
"errors"
3034
"fmt"
35+
"io"
36+
"log/slog"
3137
)
3238

3339
// Type is one EQL type as the catalog describes it: what stashgen learns
@@ -121,3 +127,26 @@ func unmarshal(dst *[]byte, b []byte) error {
121127
*dst = append([]byte(nil), b...)
122128
return nil
123129
}
130+
131+
// redacted stands in for an EQL value's bytes in what it prints and logs.
132+
const redacted = "[redacted]"
133+
134+
// text is what an EQL value prints: its type's name, and [redacted] for
135+
// its bytes, or {} when it is empty.
136+
func text(b []byte, kind string) string {
137+
if len(b) == 0 {
138+
return "eql." + kind + "{}"
139+
}
140+
return "eql." + kind + "{" + redacted + "}"
141+
}
142+
143+
// format writes [text] for every verb fmt hands an EQL value.
144+
func format(f fmt.State, b []byte, kind string) {
145+
_, _ = io.WriteString(f, text(b, kind))
146+
}
147+
148+
// logValue is what slog records of an EQL value: the [text] it prints,
149+
// never its bytes.
150+
func logValue(b []byte, kind string) slog.Value {
151+
return slog.StringValue(text(b, kind))
152+
}

0 commit comments

Comments
 (0)