Drop redundant safecsv WriteRow helper
WriteRow was a variadic alias for Write(SanitizeRecord(...)) with no extra safety or column checks. Export call sites already use []string headers; matching encoding/csv keeps one API surface. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -99,7 +99,7 @@ func (s *LogExportService) streamAuditLogCSV(
|
||||
filter *coredata.AuditLogEntryFilter,
|
||||
w *safecsv.Writer,
|
||||
) error {
|
||||
if err := w.WriteRow(auditLogExportCSVHeader...); err != nil {
|
||||
if err := w.Write(auditLogExportCSVHeader); err != nil {
|
||||
return fmt.Errorf("cannot write audit log CSV header: %w", err)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (s *LogExportService) streamSCIMEventCSV(
|
||||
filter *coredata.SCIMEventFilter,
|
||||
w *safecsv.Writer,
|
||||
) error {
|
||||
if err := w.WriteRow(scimEventExportCSVHeader...); err != nil {
|
||||
if err := w.Write(scimEventExportCSVHeader); err != nil {
|
||||
return fmt.Errorf("cannot write SCIM event CSV header: %w", err)
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ func writeAuditLogEntryCSVRow(
|
||||
entry *coredata.AuditLogEntry,
|
||||
actor auditLogActorExportInfo,
|
||||
) error {
|
||||
return w.WriteRow(
|
||||
return w.Write([]string{
|
||||
organizationName,
|
||||
entry.ID.String(),
|
||||
entry.CreatedAt.Format(time.RFC3339),
|
||||
@@ -215,7 +215,7 @@ func writeAuditLogEntryCSVRow(
|
||||
entry.Action,
|
||||
entry.ResourceType,
|
||||
entry.ResourceID.String(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func writeSCIMEventCSVRow(
|
||||
@@ -226,7 +226,7 @@ func writeSCIMEventCSVRow(
|
||||
) error {
|
||||
profile := lookup.forEvent(event)
|
||||
|
||||
return w.WriteRow(
|
||||
return w.Write([]string{
|
||||
organizationName,
|
||||
event.ID.String(),
|
||||
event.CreatedAt.Format(time.RFC3339),
|
||||
@@ -238,7 +238,7 @@ func writeSCIMEventCSVRow(
|
||||
strconv.Itoa(event.StatusCode),
|
||||
stringPtrValue(event.ErrorMessage),
|
||||
event.IPAddress.String(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func loadAuditLogActorExportInfo(
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestWriterWrite(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
w := NewWriter(&buf)
|
||||
require.NoError(t, w.WriteRow("ok", "=evil"))
|
||||
require.NoError(t, w.Write([]string{"ok", "=evil"}))
|
||||
w.Flush()
|
||||
require.NoError(t, w.Error())
|
||||
|
||||
|
||||
@@ -41,18 +41,11 @@ func NewWriter(w io.Writer) *Writer {
|
||||
return &Writer{inner: csv.NewWriter(w)}
|
||||
}
|
||||
|
||||
// Write encodes a CSV record after sanitizing every field. Prefer WriteRow for
|
||||
// literal column values at call sites.
|
||||
// Write encodes a CSV record after sanitizing every field.
|
||||
func (w *Writer) Write(record []string) error {
|
||||
return w.inner.Write(SanitizeRecord(record))
|
||||
}
|
||||
|
||||
// WriteRow encodes one CSV record from fields, sanitizing each value before
|
||||
// encoding (spreadsheet formula injection mitigation).
|
||||
func (w *Writer) WriteRow(fields ...string) error {
|
||||
return w.inner.Write(SanitizeRecord(fields))
|
||||
}
|
||||
|
||||
func (w *Writer) Flush() {
|
||||
w.inner.Flush()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user