Emit audit and SCIM log exports as CSV

JSONL was awkward in spreadsheets and SIEM imports. Write
tab-separated-friendly CSV with organization name on every row,
resolve audit actors to email or API key name, and enrich SCIM rows
with profile email and display name when available.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-07-29 18:14:25 +00:00
parent 0448c25d8b
commit 5cd407bd86
11 changed files with 726 additions and 108 deletions

View File

@@ -0,0 +1,58 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package iam
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestScimEmailFromUserName(t *testing.T) {
t.Parallel()
assert.Equal(t, "user@example.com", scimEmailFromUserName("user@example.com"))
assert.Equal(t, "", scimEmailFromUserName("not-an-email"))
assert.Equal(t, "", scimEmailFromUserName(""))
}
func TestScimDisplayNameFromJSON(t *testing.T) {
t.Parallel()
displayName := scimDisplayNameFromJSON(`{"displayName":"Jane Doe"}`)
require.Equal(t, "Jane Doe", displayName)
formatted := scimDisplayNameFromJSON(`{"name":{"formatted":"John Smith"}}`)
require.Equal(t, "John Smith", formatted)
givenFamily := scimDisplayNameFromJSON(`{"name":{"givenName":"John","familyName":"Smith"}}`)
require.Equal(t, "John Smith", givenFamily)
assert.Equal(t, "", scimDisplayNameFromJSON("not json"))
}
func TestUniqueNonEmptyStrings(t *testing.T) {
t.Parallel()
got := uniqueNonEmptyStrings([]string{"a", "A", "", "b", "a"})
assert.Equal(t, []string{"a", "b"}, got)
}