Anonymous: Add configurable device limit (#79265)

* Anonymous: Add device limiter

* break auth if limit reached

* fix typo

* refactored const to make it clearer with expiration

* anon device limit for config

---------

Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com>
This commit is contained in:
Jo
2023-12-12 12:57:25 +02:00
committed by GitHub
co-authored by Eric Leijonmarck
parent ed86583107
commit 3647ba7360
11 changed files with 105 additions and 37 deletions
+2 -4
View File
@@ -15,9 +15,7 @@ import (
"github.com/grafana/grafana/pkg/util"
)
const (
thirtyDays = 30 * 24 * time.Hour
)
const anonymousDeviceExpiration = 30 * 24 * time.Hour
type deviceDTO struct {
anonstore.Device
@@ -70,7 +68,7 @@ func (api *AnonDeviceServiceAPI) RegisterAPIEndpoints() {
// 404: notFoundError
// 500: internalServerError
func (api *AnonDeviceServiceAPI) ListDevices(c *contextmodel.ReqContext) response.Response {
fromTime := time.Now().Add(-thirtyDays)
fromTime := time.Now().Add(-anonymousDeviceExpiration)
toTime := time.Now()
devices, err := api.store.ListDevices(c.Req.Context(), &fromTime, &toTime)