Add Metabase access review source

Implement Metabase as a first-class access review connector backed by
GET /api/user, including account mapping and error handling in the
driver. Register the provider with API-key auth metadata and required
instance URL settings so connectors can be created and resolved
consistently.

Expose Metabase through the console GraphQL and UI flows by adding the
provider enum value, API-key extra setting field wiring, and source
label mapping. Add migration support for the connector_provider enum and
cover driver/provider behavior with focused tests.

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

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
Signed-off-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
Cursor Agent
2026-05-28 21:59:19 +00:00
committed by Bryan Frimin
parent 5ca1e369c0
commit 0920785bdf
12 changed files with 487 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
// 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"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMetabaseDriverListAccounts(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/api/user", r.URL.Path)
assert.Equal(t, "all", r.URL.Query().Get("status"))
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`[
{
"id": 1,
"email": "alice@example.com",
"first_name": "Alice",
"last_name": "Admin",
"common_name": "Alice A.",
"is_active": true,
"is_superuser": true,
"last_login": "2026-05-20T10:11:12.345678Z",
"date_joined": "2026-01-02T03:04:05Z"
},
{
"id": 2,
"email": "bob@example.com",
"first_name": "Bob",
"last_name": "Builder",
"is_active": false,
"is_superuser": false,
"last_login": "",
"date_joined": "2026-02-03T04:05:06Z"
},
{
"id": 3,
"email": "",
"first_name": "No",
"last_name": "Email",
"is_active": true,
"is_superuser": false
}
]`))
}))
defer srv.Close()
driver := NewMetabaseDriver(srv.Client(), srv.URL)
records, err := driver.ListAccounts(context.Background())
require.NoError(t, err)
require.Len(t, records, 2)
assert.Equal(t, "alice@example.com", records[0].Email)
assert.Equal(t, "Alice A.", records[0].FullName)
assert.Equal(t, "Admin", records[0].Role)
assert.True(t, records[0].IsAdmin)
require.NotNil(t, records[0].Active)
assert.True(t, *records[0].Active)
assert.Equal(t, "1", records[0].ExternalID)
require.NotNil(t, records[0].LastLogin)
require.NotNil(t, records[0].CreatedAt)
assert.Equal(t, "bob@example.com", records[1].Email)
assert.Equal(t, "Bob Builder", records[1].FullName)
assert.Equal(t, "User", records[1].Role)
assert.False(t, records[1].IsAdmin)
require.NotNil(t, records[1].Active)
assert.False(t, *records[1].Active)
assert.Equal(t, "2", records[1].ExternalID)
assert.Nil(t, records[1].LastLogin)
require.NotNil(t, records[1].CreatedAt)
}
func TestMetabaseDriverListAccountsUnexpectedStatus(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte(`{"message":"unauthorized"}`))
}))
defer srv.Close()
driver := NewMetabaseDriver(srv.Client(), srv.URL)
_, err := driver.ListAccounts(context.Background())
require.Error(t, err)
assert.Contains(t, err.Error(), "unexpected status 401")
}