buildDiscoveryEnv constructs the env slice passed to list_models_cmd. Starts from os.Environ() (via getenv if injected via tests), strips proxy vars when KeepProxyConfig is false, then layers endpoint + api_key on top.
(ep Endpoint, getenv func(string) string)
| 354 | // proxy vars when KeepProxyConfig is false, then layers endpoint + |
| 355 | // api_key on top. |
| 356 | func buildDiscoveryEnv(ep Endpoint, getenv func(string) string) []string { |
| 357 | if getenv == nil { |
| 358 | getenv = os.Getenv |
| 359 | } |
| 360 | apiKey := ResolveAPIKey(ep, getenv) |
| 361 | |
| 362 | current := os.Environ() |
| 363 | out := make([]string, 0, len(current)+2) |
| 364 | for _, kv := range current { |
| 365 | name, _, _ := strings.Cut(kv, "=") |
| 366 | if !ep.KeepProxyConfig && isProxyVar(name) { |
| 367 | continue |
| 368 | } |
| 369 | // Avoid letting an inherited endpoint/api_key override. |
| 370 | if name == "endpoint" || name == "api_key" { |
| 371 | continue |
| 372 | } |
| 373 | out = append(out, kv) |
| 374 | } |
| 375 | out = append(out, "endpoint="+ep.Endpoint) |
| 376 | out = append(out, "api_key="+apiKey) |
| 377 | return out |
| 378 | } |
| 379 | |
| 380 | func isProxyVar(name string) bool { |
| 381 | for _, p := range proxyVars { |
no test coverage detected