grafana/pkg/middleware/quota.go

25 lines
472 B
Go
Raw Normal View History

package middleware
import (
"fmt"
"gopkg.in/macaron.v1"
2018-03-07 16:19:35 -06:00
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/quota"
)
func Quota(target string) macaron.Handler {
2018-03-07 10:54:50 -06:00
return func(c *m.ReqContext) {
2018-03-07 16:19:35 -06:00
limitReached, err := quota.QuotaReached(c, target)
if err != nil {
c.JsonApiErr(500, "failed to get quota", err)
return
}
if limitReached {
c.JsonApiErr(403, fmt.Sprintf("%s Quota reached", target), nil)
return
}
}
}