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
|
||||
|
||||
@@ -132,8 +132,8 @@ func (sm *StationMonitor) updateStationStatus(ctx context.Context, tripCount int
|
||||
var zeroSince time.Time
|
||||
if err == nil && zeroSinceData != nil {
|
||||
var zeroSinceUnix int64
|
||||
_, err := fmt.Sscanf(string(zeroSinceData), "%d", &zeroSinceUnix)
|
||||
if err == nil {
|
||||
_, parseErr := fmt.Sscanf(string(zeroSinceData), "%d", &zeroSinceUnix)
|
||||
if parseErr == nil {
|
||||
zeroSince = time.Unix(zeroSinceUnix, 0)
|
||||
} else {
|
||||
zeroSince = time.Time{}
|
||||
@@ -145,8 +145,8 @@ func (sm *StationMonitor) updateStationStatus(ctx context.Context, tripCount int
|
||||
var lastSeenFlight time.Time
|
||||
if err == nil && lastSeenFlightData != nil {
|
||||
var lastSeenFlightUnix int64
|
||||
_, err := fmt.Sscanf(string(lastSeenFlightData), "%d", &lastSeenFlightUnix)
|
||||
if err == nil {
|
||||
_, parseErr := fmt.Sscanf(string(lastSeenFlightData), "%d", &lastSeenFlightUnix)
|
||||
if parseErr == nil {
|
||||
lastSeenFlight = time.Unix(lastSeenFlightUnix, 0)
|
||||
} else {
|
||||
lastSeenFlight = time.Time{}
|
||||
|
||||
Reference in New Issue
Block a user