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

Function lookupAIProvider

coderd/ai_providers.go:518–533  ·  view source on GitHub ↗

lookupAIProvider resolves a UUID-or-name path parameter against a Store. Soft-deleted providers are not returned; lookup by name searches active rows only.

(ctx context.Context, store database.Store, idOrName string)

Source from the content-addressed store, hash-verified

516// Soft-deleted providers are not returned; lookup by name searches active
517// rows only.
518func lookupAIProvider(ctx context.Context, store database.Store, idOrName string) (database.AIProvider, error) {
519 if id, err := uuid.Parse(idOrName); err == nil {
520 row, err := store.GetAIProviderByID(ctx, id)
521 if err != nil {
522 return database.AIProvider{}, err
523 }
524 return row, nil
525 }
526 if !codersdk.AIProviderNameRegex.MatchString(idOrName) {
527 // Bail before hitting the DB: the regex matches the CHECK
528 // constraint on ai_providers.name, so a non-matching string
529 // could not have been inserted.
530 return database.AIProvider{}, errAIProviderInvalidName
531 }
532 return store.GetAIProviderByName(ctx, idOrName)
533}
534
535// writeAIProviderError translates an error from the AI provider
536// lookup/update/delete paths into the right HTTP status code. logMsg

Callers 3

aiProvidersGetMethod · 0.85
aiProvidersUpdateMethod · 0.85
aiProvidersDeleteMethod · 0.85

Calls 3

ParseMethod · 0.65
GetAIProviderByIDMethod · 0.65
GetAIProviderByNameMethod · 0.65

Tested by

no test coverage detected