insertAIProviderKeys writes a fresh set of key rows for a provider inside a transaction. It returns the inserted rows in insertion order so callers can render them in a response.
(ctx context.Context, tx database.Store, providerID uuid.UUID, plaintexts []string)
| 580 | // inside a transaction. It returns the inserted rows in insertion |
| 581 | // order so callers can render them in a response. |
| 582 | func insertAIProviderKeys(ctx context.Context, tx database.Store, providerID uuid.UUID, plaintexts []string) ([]database.AIProviderKey, error) { |
| 583 | out := make([]database.AIProviderKey, 0, len(plaintexts)) |
| 584 | now := dbtime.Now() |
| 585 | for _, key := range plaintexts { |
| 586 | row, err := tx.InsertAIProviderKey(ctx, database.InsertAIProviderKeyParams{ |
| 587 | ID: uuid.New(), |
| 588 | ProviderID: providerID, |
| 589 | APIKey: key, |
| 590 | // ApiKeyKeyID is set by the dbcrypt wrapper. |
| 591 | ApiKeyKeyID: sql.NullString{}, |
| 592 | CreatedAt: now, |
| 593 | UpdatedAt: now, |
| 594 | }) |
| 595 | if err != nil { |
| 596 | return nil, xerrors.Errorf("insert ai provider key: %w", err) |
| 597 | } |
| 598 | out = append(out, row) |
| 599 | } |
| 600 | return out, nil |
| 601 | } |
| 602 | |
| 603 | // aiProviderKeyOpsAudit is serialized into the audit entry's |
| 604 | // additional_fields. Surfacing the per-key ID and masked secret for |
no test coverage detected