Add SendGrid access review driver

Implement a SendGrid access-review driver that fetches teammates
from the SendGrid API and maps them into AccountRecord values.

Register SendGrid as a connector provider, expose it through the
connector provider enum, and add a migration that extends the
connector_provider type with SENDGRID.

Cover the new driver with a VCR-backed fixture test and helper
tests for role and response-shape handling to keep parsing robust.

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

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-05-29 06:51:44 +00:00
committed by Aurélien Sibiril
parent fca7f2a1e6
commit 6556116601
8 changed files with 374 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package drivers
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.probo.inc/probo/pkg/coredata"
)
func TestSendGridDriver(t *testing.T) {
t.Parallel()
rec := newRecorder(t, "testdata/sendgrid", "SENDGRID_API_KEY")
client := newVCRClient(rec, bearerAuth(os.Getenv("SENDGRID_API_KEY")))
driver := NewSendGridDriver(client)
records, err := driver.ListAccounts(context.Background())
require.NoError(t, err)
require.Len(t, records, 3)
owner := records[0]
assert.Equal(t, "owner@example.com", owner.Email)
assert.Equal(t, "Olivia Owner", owner.FullName)
assert.Equal(t, "Owner", owner.Role)
assert.True(t, owner.IsAdmin)
assert.Equal(t, "owner-user", owner.ExternalID)
assert.Equal(t, coredata.AccessEntryAccountTypeUser, owner.AccountType)
admin := records[1]
assert.Equal(t, "admin@example.com", admin.Email)
assert.Equal(t, "Admin", admin.Role)
assert.True(t, admin.IsAdmin)
assert.Equal(t, "admin-user", admin.ExternalID)
teammate := records[2]
assert.Equal(t, "teammate@example.com", teammate.Email)
assert.Equal(t, "Teammate", teammate.Role)
assert.False(t, teammate.IsAdmin)
assert.Equal(t, "teammate-user", teammate.ExternalID)
}
func TestSendGridRole(t *testing.T) {
t.Parallel()
tests := []struct {
name string
userType string
isAdmin bool
want string
}{
{name: "owner", userType: "owner", isAdmin: true, want: "Owner"},
{name: "admin", userType: "admin", isAdmin: true, want: "Admin"},
{name: "teammate", userType: "teammate", isAdmin: false, want: "Teammate"},
{name: "empty admin", userType: "", isAdmin: true, want: "Admin"},
{name: "empty teammate", userType: "", isAdmin: false, want: "Teammate"},
{name: "unknown", userType: "custom-role", isAdmin: false, want: "custom-role"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, sendGridRole(tt.userType, tt.isAdmin))
})
}
}
func TestSendGridResponseItems(t *testing.T) {
t.Parallel()
t.Run("prefers result", func(t *testing.T) {
t.Parallel()
items := sendGridResponseItems(&sendGridTeammatesResponse{
Result: []sendGridTeammate{
{Email: "owner@example.com"},
},
Results: []sendGridTeammate{
{Email: "fallback@example.com"},
},
})
require.Len(t, items, 1)
assert.Equal(t, "owner@example.com", items[0].Email)
})
t.Run("falls back to results", func(t *testing.T) {
t.Parallel()
items := sendGridResponseItems(&sendGridTeammatesResponse{
Results: []sendGridTeammate{
{Email: "fallback@example.com"},
},
})
require.Len(t, items, 1)
assert.Equal(t, "fallback@example.com", items[0].Email)
})
}