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)
| 516 | // Soft-deleted providers are not returned; lookup by name searches active |
| 517 | // rows only. |
| 518 | func 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 |
no test coverage detected