fix(phase-1): redact API key query params from log output and add mutex thread-safety to providers map
This commit is contained in:
@@ -375,7 +375,7 @@ func (p *GeminiProvider) ChatCompletion(ctx context.Context, req *models.Unified
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/models/%s:generateContent?key=%s", baseURL, req.Model, p.apiKey)
|
||||
fmt.Printf("[Gemini] POST %s\n", url)
|
||||
fmt.Printf("[Gemini] POST %s\n", SanitizeURL(url))
|
||||
|
||||
resp, err := p.client.R().
|
||||
SetContext(ctx).
|
||||
@@ -633,7 +633,7 @@ func (p *GeminiProvider) ChatCompletionStream(ctx context.Context, req *models.U
|
||||
|
||||
// Use streamGenerateContent for streaming
|
||||
url := fmt.Sprintf("%s/models/%s:streamGenerateContent?key=%s", baseURL, req.Model, p.apiKey)
|
||||
fmt.Printf("[Gemini-Stream] POST %s\n", url)
|
||||
fmt.Printf("[Gemini-Stream] POST %s\n", SanitizeURL(url))
|
||||
|
||||
resp, err := p.client.R().
|
||||
SetContext(ctx).
|
||||
|
||||
@@ -5,11 +5,20 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gophergate/internal/models"
|
||||
)
|
||||
|
||||
var keySanitizeRegex = regexp.MustCompile(`(?i)(key|api_key|secret)=[^&]+`)
|
||||
|
||||
// SanitizeURL strips sensitive key query parameters from URLs before logging.
|
||||
func SanitizeURL(rawURL string) string {
|
||||
return keySanitizeRegex.ReplaceAllString(rawURL, "$1=REDACTED")
|
||||
}
|
||||
|
||||
|
||||
func sanitizeFunctionName(name string) string {
|
||||
var sb strings.Builder
|
||||
for _, ch := range name {
|
||||
|
||||
Reference in New Issue
Block a user