Skip to content

Commit 991831b

Browse files
authored
chore: add API key ID to interceptions (#20513)
Adds APIKeyID to interceptions. Needed for tracking API key usage with bridge. fixes #20001
1 parent 81c3375 commit 991831b

26 files changed

+348
-224
lines changed

coderd/apidoc/docs.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/db2sdk/db2sdk.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,9 @@ func AIBridgeInterception(interception database.AIBridgeInterception, initiator
974974
UserPrompts: sdkUserPrompts,
975975
ToolUsages: sdkToolUsages,
976976
}
977+
if interception.APIKeyID.Valid {
978+
intc.APIKeyID = &interception.APIKeyID.String
979+
}
977980
if interception.EndedAt.Valid {
978981
intc.EndedAt = &interception.EndedAt.Time
979982
}

coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ func ClaimPrebuild(
14961496
func AIBridgeInterception(t testing.TB, db database.Store, seed database.InsertAIBridgeInterceptionParams, endedAt *time.Time) database.AIBridgeInterception {
14971497
interception, err := db.InsertAIBridgeInterception(genCtx, database.InsertAIBridgeInterceptionParams{
14981498
ID: takeFirst(seed.ID, uuid.New()),
1499+
APIKeyID: seed.APIKeyID,
14991500
InitiatorID: takeFirst(seed.InitiatorID, uuid.New()),
15001501
Provider: takeFirst(seed.Provider, "provider"),
15011502
Model: takeFirst(seed.Model, "model"),

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE aibridge_interceptions DROP COLUMN api_key_id;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- column is nullable to not break interceptions recorded before this column was added
2+
ALTER TABLE aibridge_interceptions ADD COLUMN api_key_id text;

coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ func (q *sqlQuerier) ListAuthorizedAIBridgeInterceptions(ctx context.Context, ar
805805
&i.AIBridgeInterception.StartedAt,
806806
&i.AIBridgeInterception.Metadata,
807807
&i.AIBridgeInterception.EndedAt,
808+
&i.AIBridgeInterception.APIKeyID,
808809
&i.VisibleUser.ID,
809810
&i.VisibleUser.Username,
810811
&i.VisibleUser.Name,

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)