mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
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:
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user