added multi-key support for optional auth logic
This commit is contained in:
@@ -27,14 +27,25 @@ func main() {
|
||||
csvUpdateInterval := flag.Int("csv-update-interval", 10, "Interval in minutes with which to run the CSV updater command")
|
||||
flag.Parse()
|
||||
|
||||
var authToken string
|
||||
var authTokens []string
|
||||
if *keyPath != "" {
|
||||
content, err := os.ReadFile(*keyPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read auth token file: %v", err)
|
||||
}
|
||||
authToken = strings.TrimSpace(string(content))
|
||||
log.Printf("Starting Dynagate LLM Gateway. Config: %s, Port: %d, Auth: Required", *csvPath, *port)
|
||||
var tokens []string
|
||||
for _, line := range strings.Split(string(content), "\n") {
|
||||
token := strings.TrimSpace(line)
|
||||
if token != "" {
|
||||
tokens = append(tokens, token)
|
||||
}
|
||||
}
|
||||
if len(tokens) > 0 {
|
||||
authTokens = tokens
|
||||
log.Printf("Starting Dynagate LLM Gateway. Config: %s, Port: %d, Auth: Required (%d tokens loaded)", *csvPath, *port, len(authTokens))
|
||||
} else {
|
||||
log.Printf("Starting Dynagate LLM Gateway. Config: %s, Port: %d, Auth: None (empty key file)", *csvPath, *port)
|
||||
}
|
||||
} else {
|
||||
log.Printf("Starting Dynagate LLM Gateway. Config: %s, Port: %d, Auth: None", *csvPath, *port)
|
||||
}
|
||||
@@ -62,9 +73,9 @@ func main() {
|
||||
|
||||
// Register routes
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/v1/models", handleModels(cm, authToken))
|
||||
mux.HandleFunc("/v1/chat/completions", handleChatCompletions(cm, authToken))
|
||||
mux.HandleFunc("/v1/images/generations", handleImageGenerations(cm, authToken))
|
||||
mux.HandleFunc("/v1/models", handleModels(cm, authTokens))
|
||||
mux.HandleFunc("/v1/chat/completions", handleChatCompletions(cm, authTokens))
|
||||
mux.HandleFunc("/v1/images/generations", handleImageGenerations(cm, authTokens))
|
||||
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", *port),
|
||||
|
||||
Reference in New Issue
Block a user