fix: address code review findings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user