fix: address code review findings

This commit is contained in:
2026-08-17 23:40:52 +03:00
parent 9b89b7b9ab
commit 8aecaf1468
8 changed files with 632 additions and 576 deletions

View File

@@ -429,16 +429,14 @@ func StationStatus(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
// adminAuth checks authentication for admin endpoints.
// Returns true if the request is authenticated, false otherwise.
func adminAuth(hc *HandlerContext, w http.ResponseWriter, r *http.Request) bool {
// Check for admin API key in header
expectedAPIKey := os.Getenv("TRIP_PLANNER_ADMIN_API_KEY")
if expectedAPIKey == "" {
// Admin API key must be configured
http.Error(w, "unauthorized: admin API key not configured", http.StatusUnauthorized)
http.Error(w, "unauthorized", http.StatusUnauthorized)
return false
}
providedAPIKey := r.Header.Get("X-Admin-Api-Key")
if !hmac.Equal([]byte(providedAPIKey), []byte(expectedAPIKey)) {
http.Error(w, "unauthorized: invalid admin API key", http.StatusUnauthorized)
http.Error(w, "unauthorized", http.StatusUnauthorized)
return false
}
return true