Refactor API key handling in runners.go to streamline authorization logic. Remove redundant checks for "Bearer " prefix in API key extraction, enhancing code clarity and maintainability.
This commit is contained in:
@@ -43,9 +43,7 @@ func (s *Server) runnerAuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// Remove "Bearer " prefix if present
|
||||
if strings.HasPrefix(apiKey, "Bearer ") {
|
||||
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
||||
}
|
||||
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
||||
|
||||
// Validate API key and get its ID
|
||||
apiKeyID, _, err := s.secrets.ValidateRunnerAPIKey(apiKey)
|
||||
@@ -739,9 +737,7 @@ func (s *Server) handleRunnerWebSocket(w http.ResponseWriter, r *http.Request) {
|
||||
apiKey := r.URL.Query().Get("api_key")
|
||||
if apiKey == "" {
|
||||
apiKey = r.Header.Get("Authorization")
|
||||
if strings.HasPrefix(apiKey, "Bearer ") {
|
||||
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
||||
}
|
||||
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
||||
}
|
||||
if apiKey == "" {
|
||||
s.respondError(w, http.StatusBadRequest, "API key required")
|
||||
@@ -2186,4 +2182,3 @@ func (s *Server) logTaskEvent(taskID int64, runnerID *int64, logLevel types.LogL
|
||||
StepName: stepName,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user