2015-09-18 01:36:58 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-01-13 08:38:54 -06:00
|
|
|
"gopkg.in/macaron.v1"
|
2018-03-07 16:19:35 -06:00
|
|
|
|
2020-02-28 05:50:58 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2018-03-07 16:19:35 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/quota"
|
2015-09-18 01:36:58 -05:00
|
|
|
)
|
|
|
|
|
2019-02-11 14:12:01 -06:00
|
|
|
// Quota returns a function that returns a function used to call quotaservice based on target name
|
|
|
|
func Quota(quotaService *quota.QuotaService) func(target string) macaron.Handler {
|
|
|
|
//https://open.spotify.com/track/7bZSoBEAEEUsGEuLOf94Jm?si=T1Tdju5qRSmmR0zph_6RBw fuuuuunky
|
|
|
|
return func(target string) macaron.Handler {
|
2020-02-28 05:50:58 -06:00
|
|
|
return func(c *models.ReqContext) {
|
2019-02-11 14:12:01 -06:00
|
|
|
limitReached, err := quotaService.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
|
|
|
|
}
|
2015-09-18 01:36:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|