Return not found for more recently deleted servers, too
This commit is contained in:
16
ntpdb/server.go
Normal file
16
ntpdb/server.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package ntpdb
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func (s *Server) DeletionAge(dur time.Duration) bool {
|
||||||
|
if !s.DeletionOn.Valid {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if dur > 0 {
|
||||||
|
dur = dur * -1
|
||||||
|
}
|
||||||
|
if s.DeletionOn.Time.Before(time.Now().Add(dur)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-retryablehttp"
|
"github.com/hashicorp/go-retryablehttp"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
@@ -49,6 +50,9 @@ func (srv *Server) graphImage(c echo.Context) error {
|
|||||||
if serverData.ID == 0 {
|
if serverData.ID == 0 {
|
||||||
return c.String(http.StatusNotFound, "not found")
|
return c.String(http.StatusNotFound, "not found")
|
||||||
}
|
}
|
||||||
|
if serverData.DeletionAge(7 * 24 * time.Hour) {
|
||||||
|
return c.String(http.StatusNotFound, "not found")
|
||||||
|
}
|
||||||
|
|
||||||
if serverData.Ip != serverID {
|
if serverData.Ip != serverID {
|
||||||
return c.Redirect(308, fmt.Sprintf("/graph/%s/offset.png", serverData.Ip))
|
return c.Redirect(308, fmt.Sprintf("/graph/%s/offset.png", serverData.Ip))
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ func (srv *Server) history(c echo.Context) error {
|
|||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return c.String(http.StatusInternalServerError, "internal error")
|
return c.String(http.StatusInternalServerError, "internal error")
|
||||||
}
|
}
|
||||||
|
if server.DeletionAge(30 * 24 * time.Hour) {
|
||||||
|
span.AddEvent("server deleted")
|
||||||
|
return c.String(http.StatusNotFound, "server not found")
|
||||||
|
}
|
||||||
if server.ID == 0 {
|
if server.ID == 0 {
|
||||||
span.AddEvent("server not found")
|
span.AddEvent("server not found")
|
||||||
return c.String(http.StatusNotFound, "server not found")
|
return c.String(http.StatusNotFound, "server not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user