Skip to content

Commit

Permalink
Return 403 if data doesn't make sense
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv committed May 28, 2024
1 parent d807922 commit bed0fc3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions controller.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package main

import (
"log"
"net/http"
"strings"

"github.com/gin-gonic/gin"
)

func servOpticalInfo(c *gin.Context) {
c.JSON(http.StatusOK, gponSvc.GetOpticalInfo())
stat := gponSvc.GetOpticalInfo()
if stat.Temperature > 0.0 {
c.JSON(http.StatusOK, stat)
} else {
log.Println("Unable to fetch gpon optical stats at the moment, returning http 403")
c.JSON(http.StatusForbidden, nil)
}
}

func servDeviceInfo(c *gin.Context) {
c.JSON(http.StatusOK, gponSvc.GetDeviceInfo())
stat := gponSvc.GetDeviceInfo()
if len(strings.TrimSpace(stat.DeviceModel)) >= 0 {
c.JSON(http.StatusOK, gponSvc.GetDeviceInfo())
} else {
log.Println("Unable to fetch gpon device stats at the moment, returning http 403")
c.JSON(http.StatusForbidden, nil)
}
}

func servAllInfo(c *gin.Context) {
Expand All @@ -20,5 +34,10 @@ func servAllInfo(c *gin.Context) {
allInfo.OpticalStats = gponSvc.GetOpticalInfo()
allInfo.DeviceStats = gponSvc.GetDeviceInfo()

c.JSON(http.StatusOK, allInfo)
if allInfo.OpticalStats.Temperature > 0.0 && len(strings.TrimSpace(allInfo.DeviceStats.DeviceModel)) >= 0 {
c.JSON(http.StatusOK, allInfo)
} else {
log.Println("Unable to fetch all gpon stats at the moment, returning http 403")
c.JSON(http.StatusForbidden, nil)
}
}

0 comments on commit bed0fc3

Please sign in to comment.