MCPcopy Create free account
hub / github.com/alibaba/open-code-review / checkAPIKeyRequirement

Function checkAPIKeyRequirement

cmd/opencodereview/provider_cmd.go:243–258  ·  view source on GitHub ↗

checkAPIKeyRequirement decides whether a provider selection may be saved with no api_key. It mirrors the resolver's precedence (static api_key -> api_key_cmd -> env var), so an already-configured command satisfies the requirement and picking a model for such a provider does not fail and abandon the

(providerName, apiKey, apiKeyCmd string, preset llm.Provider, isPreset bool)

Source from the content-addressed store, hash-verified

241// make it impossible to configure, since the credentials live in the AWS chain
242// rather than the config file.
243func checkAPIKeyRequirement(providerName, apiKey, apiKeyCmd string, preset llm.Provider, isPreset bool) error {
244 if apiKey != "" || strings.TrimSpace(apiKeyCmd) != "" {
245 return nil
246 }
247 switch {
248 case isPreset && preset.AmbientAuth:
249 return nil
250 case isPreset && preset.EnvVar != "":
251 if os.Getenv(preset.EnvVar) == "" {
252 return fmt.Errorf("API key is required for provider %s (configure it, set providers.%s.api_key_cmd, or set $%s)", providerName, providerName, preset.EnvVar)
253 }
254 return nil
255 default:
256 return fmt.Errorf("API key is required for provider %s (configure it or set providers.%s.api_key_cmd)", providerName, providerName)
257 }
258}
259
260func applyOfficialProviderConfig(configPath string, cfg *Config, result providerTUIResult) error {
261 if result.provider == "" {

Callers 2

Calls

no outgoing calls

Tested by 1