(req *http.Request, setting *provider.Setting)
| 80 | } |
| 81 | |
| 82 | func rewriteHttpAuthHeader(req *http.Request, setting *provider.Setting) error { |
| 83 | uri := req.URL.RequestURI() |
| 84 | if strings.HasPrefix(uri, "/api/routes") { |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | apiKey := setting.GetParam("apikey") |
| 89 | |
| 90 | if strings.HasPrefix(uri, "/api/providers/vllm") { |
| 91 | if len(apiKey) != 0 { |
| 92 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey)) |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | if len(apiKey) == 0 { |
| 98 | if setting.Provider == "bedrock" { |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | return errors.New("api key is empty in provider setting") |
| 103 | } |
| 104 | |
| 105 | if strings.HasPrefix(uri, "/api/providers/anthropic") { |
| 106 | req.Header.Set("x-api-key", apiKey) |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | if strings.HasPrefix(uri, "/api/providers/azure") { |
| 111 | req.Header.Set("api-key", apiKey) |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey)) |
| 116 | |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | func (a *Authenticator) canKeyAccessCustomRoute(path string, keyId string) error { |
| 121 | trimed := strings.TrimPrefix(path, "/api/routes") |
no test coverage detected