mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 04:09:40 -06:00
implement graph endpoint to delete spaces
This commit is contained in:
@@ -735,3 +735,55 @@ func generateCs3Filters(request *godata.GoDataRequest) ([]*storageprovider.ListS
|
||||
}
|
||||
return filters, nil
|
||||
}
|
||||
|
||||
func (g Graph) DeleteDrive(w http.ResponseWriter, r *http.Request) {
|
||||
driveID, err := url.PathUnescape(chi.URLParam(r, "driveID"))
|
||||
if err != nil {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping drive id failed")
|
||||
return
|
||||
}
|
||||
|
||||
if driveID == "" {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing drive id")
|
||||
return
|
||||
}
|
||||
|
||||
root := &storageprovider.ResourceId{}
|
||||
|
||||
identifierParts := strings.Split(driveID, "!")
|
||||
switch len(identifierParts) {
|
||||
case 1:
|
||||
root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[0]
|
||||
case 2:
|
||||
root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[1]
|
||||
default:
|
||||
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", driveID))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
purge := parsePurgeHeader(r.Header)
|
||||
|
||||
var opaque *types.Opaque
|
||||
if purge {
|
||||
opaque = &types.Opaque{
|
||||
Map: map[string]*types.OpaqueEntry{
|
||||
"purge": {},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
dRes, err := g.gatewayClient.DeleteStorageSpace(r.Context(), &storageprovider.DeleteStorageSpaceRequest{
|
||||
Opaque: opaque,
|
||||
Id: &storageprovider.StorageSpaceId{
|
||||
OpaqueId: root.StorageId,
|
||||
},
|
||||
})
|
||||
if err != nil || dRes.Status.Code != cs3rpc.Code_CODE_OK {
|
||||
g.logger.Error().Err(err).Msg("error deleting storage space")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package svc
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/ReneKroon/ttlcache/v2"
|
||||
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
|
||||
@@ -15,6 +16,11 @@ import (
|
||||
opkgm "github.com/owncloud/ocis/ocis-pkg/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
// HeaderPurge defines the header name for the purge header.
|
||||
HeaderPurge = "Purge"
|
||||
)
|
||||
|
||||
// Service defines the extension handlers.
|
||||
type Service interface {
|
||||
ServeHTTP(http.ResponseWriter, *http.Request)
|
||||
@@ -118,6 +124,7 @@ func NewService(opts ...Option) Service {
|
||||
r.Route("/{driveID}", func(r chi.Router) {
|
||||
r.Patch("/", svc.UpdateDrive)
|
||||
r.Get("/", svc.GetSingleDrive)
|
||||
r.Delete("/", svc.DeleteDrive)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -126,3 +133,15 @@ func NewService(opts ...Option) Service {
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
// parseHeaderPurge parses the 'Purge' header.
|
||||
// '1', 't', 'T', 'TRUE', 'true', 'True' are parsed as true
|
||||
// all other values are false.
|
||||
func parsePurgeHeader(h http.Header) bool {
|
||||
val := h.Get(HeaderPurge)
|
||||
|
||||
if b, err := strconv.ParseBool(val); err == nil {
|
||||
return b
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
30
graph/pkg/service/v0/service_test.go
Normal file
30
graph/pkg/service/v0/service_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePurgeHeader(t *testing.T) {
|
||||
tests := map[string]bool{
|
||||
"": false,
|
||||
"f": false,
|
||||
"F": false,
|
||||
"anything": false,
|
||||
"t": true,
|
||||
"T": true,
|
||||
}
|
||||
|
||||
for input, expected := range tests {
|
||||
h := make(http.Header)
|
||||
h.Add(HeaderPurge, input)
|
||||
|
||||
if expected != parsePurgeHeader(h) {
|
||||
t.Errorf("parsePurgeHeader with input %s got %t expected %t", input, !expected, expected)
|
||||
}
|
||||
}
|
||||
|
||||
if h := make(http.Header); parsePurgeHeader(h) {
|
||||
t.Error("parsePurgeHeader without Purge header set got true expected false")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user