Storage: add basic storage service (#46604)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
// HTTPStorageService passes raw HTTP requests to a well typed storage service
|
||||
type HTTPStorageService interface {
|
||||
List(c *models.ReqContext) response.Response
|
||||
Read(c *models.ReqContext) response.Response
|
||||
Delete(c *models.ReqContext) response.Response
|
||||
Upload(c *models.ReqContext) response.Response
|
||||
}
|
||||
|
||||
type httpStorage struct {
|
||||
store StorageService
|
||||
}
|
||||
|
||||
func ProvideHTTPService(store StorageService) HTTPStorageService {
|
||||
return &httpStorage{
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *httpStorage) Upload(c *models.ReqContext) response.Response {
|
||||
action := "Upload"
|
||||
scope, path := getPathAndScope(c)
|
||||
|
||||
return response.JSON(200, map[string]string{
|
||||
"action": action,
|
||||
"scope": scope,
|
||||
"path": path,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *httpStorage) Read(c *models.ReqContext) response.Response {
|
||||
action := "Read"
|
||||
scope, path := getPathAndScope(c)
|
||||
|
||||
return response.JSON(200, map[string]string{
|
||||
"action": action,
|
||||
"scope": scope,
|
||||
"path": path,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *httpStorage) Delete(c *models.ReqContext) response.Response {
|
||||
action := "Delete"
|
||||
scope, path := getPathAndScope(c)
|
||||
|
||||
return response.JSON(200, map[string]string{
|
||||
"action": action,
|
||||
"scope": scope,
|
||||
"path": path,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *httpStorage) List(c *models.ReqContext) response.Response {
|
||||
params := web.Params(c.Req)
|
||||
path := params["*"]
|
||||
frame, err := s.store.List(c.Req.Context(), c.SignedInUser, path)
|
||||
if err != nil {
|
||||
return response.Error(400, "error reading path", err)
|
||||
}
|
||||
if frame == nil {
|
||||
return response.Error(404, "not found", nil)
|
||||
}
|
||||
return response.JSONStreaming(200, frame)
|
||||
}
|
||||
Reference in New Issue
Block a user