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

Function validateProviderCredentialList

cli/server.go:3305–3327  ·  view source on GitHub ↗

validateProviderCredentialList checks that a list of credentials belonging to a provider is well-formed: no empty values, no duplicates, and within the maximum count. Trims whitespace in place.

(providerIndex int, providerType string, keys []string)

Source from the content-addressed store, hash-verified

3303// duplicates, and within the maximum count. Trims whitespace in
3304// place.
3305func validateProviderCredentialList(providerIndex int, providerType string, keys []string) error {
3306 if len(keys) > maxKeysPerProvider {
3307 return xerrors.Errorf("provider %d (%s): too many keys (%d), maximum is %d",
3308 providerIndex, providerType, len(keys), maxKeysPerProvider)
3309 }
3310
3311 seen := make(map[string]struct{}, len(keys))
3312 for i, key := range keys {
3313 trimmed := strings.TrimSpace(key)
3314 if trimmed == "" {
3315 return xerrors.Errorf("provider %d (%s): key at index %d is empty",
3316 providerIndex, providerType, i)
3317 }
3318 keys[i] = trimmed
3319 if _, exists := seen[trimmed]; exists {
3320 return xerrors.Errorf("provider %d (%s): duplicate key at index %d",
3321 providerIndex, providerType, i)
3322 }
3323 seen[trimmed] = struct{}{}
3324 }
3325
3326 return nil
3327}
3328
3329// validateBedrockCredentials checks that Bedrock access keys and
3330// secrets are paired correctly (same count) and that each list is

Callers 2

ReadAIProvidersFromEnvFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected