Storage: limit the number of uploaded files (#50796)

* #50608: sql file upload quotas

* rename `files_in_sql` to `file`

* merge conflict
This commit is contained in:
Artur Wierzbicki
2022-07-18 15:24:39 +04:00
committed by GitHub
parent 67ea2da57e
commit b2736ac1fe
6 changed files with 42 additions and 9 deletions
+16 -3
View File
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
)
@@ -26,12 +27,14 @@ type HTTPStorageService interface {
}
type httpStorage struct {
store StorageService
store StorageService
quotaService quota.Service
}
func ProvideHTTPService(store StorageService) HTTPStorageService {
func ProvideHTTPService(store StorageService, quotaService quota.Service) HTTPStorageService {
return &httpStorage{
store: store,
store: store,
quotaService: quotaService,
}
}
@@ -58,6 +61,16 @@ func UploadErrorToStatusCode(err error) int {
}
func (s *httpStorage) Upload(c *models.ReqContext) response.Response {
// assumes we are only uploading to the SQL database - TODO: refactor once we introduce object stores
quotaReached, err := s.quotaService.CheckQuotaReached(c.Req.Context(), "file", nil)
if err != nil {
return response.Error(500, "Internal server error", err)
}
if quotaReached {
return response.Error(400, "File quota reached", errors.New("file quota reached"))
}
type rspInfo struct {
Message string `json:"message,omitempty"`
Path string `json:"path,omitempty"`