quota.go 770 B

12345678910111213141516171819202122232425262728
  1. package middleware
  2. import (
  3. "fmt"
  4. "gopkg.in/macaron.v1"
  5. m "github.com/grafana/grafana/pkg/models"
  6. "github.com/grafana/grafana/pkg/services/quota"
  7. )
  8. // Quota returns a function that returns a function used to call quotaservice based on target name
  9. func Quota(quotaService *quota.QuotaService) func(target string) macaron.Handler {
  10. //https://open.spotify.com/track/7bZSoBEAEEUsGEuLOf94Jm?si=T1Tdju5qRSmmR0zph_6RBw fuuuuunky
  11. return func(target string) macaron.Handler {
  12. return func(c *m.ReqContext) {
  13. limitReached, err := quotaService.QuotaReached(c, target)
  14. if err != nil {
  15. c.JsonApiErr(500, "failed to get quota", err)
  16. return
  17. }
  18. if limitReached {
  19. c.JsonApiErr(403, fmt.Sprintf("%s Quota reached", target), nil)
  20. return
  21. }
  22. }
  23. }
  24. }