MCPcopy Index your code
hub / github.com/coder/coder / insertAIProviderKeys

Function insertAIProviderKeys

coderd/ai_providers.go:582–601  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

580// inside a transaction. It returns the inserted rows in insertion
581// order so callers can render them in a response.
582func 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

Callers 2

aiProvidersCreateMethod · 0.85
applyAIProviderKeyOpsFunction · 0.85

Calls 4

NowFunction · 0.92
InsertAIProviderKeyMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected