chore: add API key ID to interceptions (#20513)

Adds APIKeyID to interceptions.
Needed for tracking API key usage with bridge.
fixes https://github.com/coder/coder/issues/20001
This commit is contained in:
Paweł Banaszewski
2025-11-10 13:46:41 +01:00
committed by GitHub
parent 81c3375670
commit 991831b1dd
26 changed files with 349 additions and 225 deletions
+6
View File
@@ -1,6 +1,7 @@
package coderd_test
import (
"database/sql"
"io"
"net/http"
"testing"
@@ -101,7 +102,9 @@ func TestAIBridgeListInterceptions(t *testing.T) {
// Insert a bunch of test data.
now := dbtime.Now()
i1ApiKey := sql.NullString{String: "some-api-key", Valid: true}
i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
APIKeyID: i1ApiKey,
InitiatorID: user1.ID,
StartedAt: now.Add(-time.Hour),
}, nil)
@@ -146,6 +149,9 @@ func TestAIBridgeListInterceptions(t *testing.T) {
require.Equal(t, i2SDK.ID, res.Results[0].ID)
require.Equal(t, i1SDK.ID, res.Results[1].ID)
require.Equal(t, &i1ApiKey.String, i1SDK.APIKeyID)
require.Nil(t, i2SDK.APIKeyID)
// Normalize timestamps in the response so we can compare the whole
// thing easily.
res.Results[0].StartedAt = i2SDK.StartedAt