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
|
|
|
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/quota"
|
2015-09-18 01:36:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2015-09-18 01:36:58 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|