use spaceID
This commit is contained in:
@@ -113,7 +113,14 @@ func (g Graph) getRemoteItem(ctx context.Context, root *storageprovider.Resource
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item.WebDavUrl = libregraph.PtrString(baseURL.String() + storagespace.FormatResourceID(*root))
|
||||
if baseURL != nil {
|
||||
// TODO read from StorageSpace ... needs Opaque for now
|
||||
// TODO how do we build the url?
|
||||
// for now: read from request
|
||||
webDavURL := *baseURL
|
||||
webDavURL.Path = path.Join(webDavURL.Path, storagespace.FormatResourceID(*root))
|
||||
item.WebDavUrl = libregraph.PtrString(webDavURL.String())
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -231,7 +238,7 @@ func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL,
|
||||
|
||||
func (g Graph) getSpecialDriveItem(ctx context.Context, id storageprovider.ResourceId, itemName string, baseURL *url.URL, space *storageprovider.StorageSpace) *libregraph.DriveItem {
|
||||
var spaceItem *libregraph.DriveItem
|
||||
if id.StorageId == "" && id.OpaqueId == "" {
|
||||
if id.SpaceId == "" && id.OpaqueId == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -285,18 +285,13 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
root := &storageprovider.ResourceId{}
|
||||
|
||||
identifierParts := strings.Split(driveID, "!")
|
||||
switch len(identifierParts) {
|
||||
case 1:
|
||||
_, sID := storagespace.SplitStorageID(identifierParts[0])
|
||||
root.StorageId, root.OpaqueId = identifierParts[0], sID
|
||||
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))
|
||||
rid, err := storagespace.ParseID(driveID)
|
||||
if err != nil {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", rid))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
root = &rid
|
||||
|
||||
client := g.GetGatewayClient()
|
||||
|
||||
@@ -305,7 +300,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
// the original storage space.
|
||||
StorageSpace: &storageprovider.StorageSpace{
|
||||
Id: &storageprovider.StorageSpaceId{
|
||||
OpaqueId: root.StorageId + "!" + root.OpaqueId,
|
||||
OpaqueId: storagespace.FormatResourceID(rid),
|
||||
},
|
||||
Root: root,
|
||||
},
|
||||
@@ -453,25 +448,15 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor
|
||||
return res, err
|
||||
}
|
||||
|
||||
func generateSpaceId(id *storageprovider.ResourceId) (spaceID string) {
|
||||
spaceID = id.GetStorageId()
|
||||
// 2nd ID to compare is the opaque ID of the Space Root
|
||||
spaceID2 := id.GetOpaqueId()
|
||||
if strings.Contains(spaceID, "$") {
|
||||
_, spaceID2 = storagespace.SplitStorageID(spaceID)
|
||||
}
|
||||
// Append opaqueID only if it is different from the spaceID2
|
||||
if id.OpaqueId != spaceID2 {
|
||||
spaceID += "!" + id.OpaqueId
|
||||
}
|
||||
return spaceID
|
||||
}
|
||||
|
||||
func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, space *storageprovider.StorageSpace) (*libregraph.Drive, error) {
|
||||
if space.Root == nil {
|
||||
return nil, fmt.Errorf("space has no root")
|
||||
}
|
||||
spaceID := generateSpaceId(space.Root)
|
||||
spaceRid := *space.Root
|
||||
if space.Root.GetSpaceId() == space.Root.GetOpaqueId() {
|
||||
spaceRid.OpaqueId = ""
|
||||
}
|
||||
spaceID := storagespace.FormatResourceID(spaceRid)
|
||||
|
||||
var permissions []libregraph.Permission
|
||||
if space.Opaque != nil {
|
||||
@@ -540,7 +525,7 @@ func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, spa
|
||||
//"description": "string", // TODO read from StorageSpace ... needs Opaque for now
|
||||
DriveType: &space.SpaceType,
|
||||
Root: &libregraph.DriveItem{
|
||||
Id: libregraph.PtrString(storagespace.FormatResourceID(*space.Root)),
|
||||
Id: libregraph.PtrString(storagespace.FormatResourceID(spaceRid)),
|
||||
Permissions: permissions,
|
||||
},
|
||||
}
|
||||
@@ -548,9 +533,10 @@ func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, spa
|
||||
var remoteItem *libregraph.RemoteItem
|
||||
grantID := storageprovider.ResourceId{
|
||||
StorageId: utils.ReadPlainFromOpaque(space.Opaque, "grantStorageID"),
|
||||
SpaceId: utils.ReadPlainFromOpaque(space.Opaque, "grantSpaceID"),
|
||||
OpaqueId: utils.ReadPlainFromOpaque(space.Opaque, "grantOpaqueID"),
|
||||
}
|
||||
if grantID.StorageId != "" && grantID.OpaqueId != "" {
|
||||
if grantID.SpaceId != "" && grantID.OpaqueId != "" {
|
||||
var err error
|
||||
remoteItem, err = g.getRemoteItem(ctx, &grantID, baseURL)
|
||||
if err != nil {
|
||||
@@ -625,11 +611,8 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage
|
||||
|
||||
req := &gateway.GetQuotaRequest{
|
||||
Ref: &storageprovider.Reference{
|
||||
ResourceId: &storageprovider.ResourceId{
|
||||
StorageId: space.Root.StorageId,
|
||||
OpaqueId: space.Root.OpaqueId,
|
||||
},
|
||||
Path: ".",
|
||||
ResourceId: space.Root,
|
||||
Path: ".",
|
||||
},
|
||||
}
|
||||
res, err := client.GetQuota(ctx, req)
|
||||
@@ -771,17 +754,9 @@ func (g Graph) DeleteDrive(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
root := &storageprovider.ResourceId{}
|
||||
|
||||
identifierParts := strings.Split(driveID, "!")
|
||||
_, sID := storagespace.SplitStorageID(identifierParts[0])
|
||||
switch len(identifierParts) {
|
||||
case 1:
|
||||
root.StorageId, root.OpaqueId = identifierParts[0], sID
|
||||
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))
|
||||
rid, err := storagespace.ParseID(driveID)
|
||||
if err != nil {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", rid))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -800,7 +775,7 @@ func (g Graph) DeleteDrive(w http.ResponseWriter, r *http.Request) {
|
||||
dRes, err := g.gatewayClient.DeleteStorageSpace(r.Context(), &storageprovider.DeleteStorageSpaceRequest{
|
||||
Opaque: opaque,
|
||||
Id: &storageprovider.StorageSpaceId{
|
||||
OpaqueId: root.StorageId,
|
||||
OpaqueId: storagespace.FormatResourceID(rid),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -76,7 +76,8 @@ var _ = Describe("Graph", func() {
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "sameID"},
|
||||
SpaceType: "aspacetype",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "sameID",
|
||||
StorageId: "pro-1",
|
||||
SpaceId: "sameID",
|
||||
OpaqueId: "sameID",
|
||||
},
|
||||
Name: "aspacename",
|
||||
@@ -102,11 +103,11 @@ var _ = Describe("Graph", func() {
|
||||
"value":[
|
||||
{
|
||||
"driveType":"aspacetype",
|
||||
"id":"sameID",
|
||||
"id":"pro-1$sameID",
|
||||
"name":"aspacename",
|
||||
"root":{
|
||||
"id":"sameID!sameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/sameID"
|
||||
"id":"pro-1$sameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/pro-1$sameID"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -121,7 +122,8 @@ var _ = Describe("Graph", func() {
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "bsameID"},
|
||||
SpaceType: "bspacetype",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "bsameID",
|
||||
StorageId: "pro-1",
|
||||
SpaceId: "bsameID",
|
||||
OpaqueId: "bsameID",
|
||||
},
|
||||
Name: "bspacename",
|
||||
@@ -136,7 +138,8 @@ var _ = Describe("Graph", func() {
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "asameID"},
|
||||
SpaceType: "aspacetype",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "asameID",
|
||||
StorageId: "pro-1",
|
||||
SpaceId: "asameID",
|
||||
OpaqueId: "asameID",
|
||||
},
|
||||
Name: "aspacename",
|
||||
@@ -169,23 +172,23 @@ var _ = Describe("Graph", func() {
|
||||
{
|
||||
"driveAlias":"aspacetype/aspacename",
|
||||
"driveType":"aspacetype",
|
||||
"id":"asameID",
|
||||
"id":"pro-1$asameID",
|
||||
"name":"aspacename",
|
||||
"root":{
|
||||
"eTag":"101112131415",
|
||||
"id":"asameID!asameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/asameID"
|
||||
"id":"pro-1$asameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/pro-1$asameID"
|
||||
}
|
||||
},
|
||||
{
|
||||
"driveAlias":"bspacetype/bspacename",
|
||||
"driveType":"bspacetype",
|
||||
"id":"bsameID",
|
||||
"id":"pro-1$bsameID",
|
||||
"name":"bspacename",
|
||||
"root":{
|
||||
"eTag":"123456789",
|
||||
"id":"bsameID!bsameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/bsameID"
|
||||
"id":"pro-1$bsameID",
|
||||
"webDavUrl":"https://localhost:9200/dav/spaces/pro-1$bsameID"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -197,10 +200,11 @@ var _ = Describe("Graph", func() {
|
||||
Status: status.NewOK(ctx),
|
||||
StorageSpaces: []*provider.StorageSpace{
|
||||
{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "aID!differentID"},
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "prID$aID!differentID"},
|
||||
SpaceType: "mountpoint",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "prID$aID",
|
||||
StorageId: "prID",
|
||||
SpaceId: "aID",
|
||||
OpaqueId: "differentID",
|
||||
},
|
||||
Name: "New Folder",
|
||||
@@ -209,6 +213,7 @@ var _ = Describe("Graph", func() {
|
||||
"spaceAlias": {Decoder: "plain", Value: []byte("mountpoint/new-folder")},
|
||||
"etag": {Decoder: "plain", Value: []byte("101112131415")},
|
||||
"grantStorageID": {Decoder: "plain", Value: []byte("ownerStorageID")},
|
||||
"grantSpaceID": {Decoder: "plain", Value: []byte("spaceID")},
|
||||
"grantOpaqueID": {Decoder: "plain", Value: []byte("opaqueID")},
|
||||
},
|
||||
},
|
||||
@@ -220,7 +225,7 @@ var _ = Describe("Graph", func() {
|
||||
Info: &provider.ResourceInfo{
|
||||
Etag: "123456789",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
Id: &provider.ResourceId{StorageId: "ownerStorageID", OpaqueId: "opaqueID"},
|
||||
Id: &provider.ResourceId{StorageId: "ownerStorageID", SpaceId: "spaceID", OpaqueId: "opaqueID"},
|
||||
Path: "New Folder",
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1648327606, Nanos: 0},
|
||||
Size: uint64(1234),
|
||||
@@ -252,12 +257,12 @@ var _ = Describe("Graph", func() {
|
||||
Expect(*value.Root.ETag).To(Equal("101112131415"))
|
||||
Expect(*value.Root.Id).To(Equal("prID$aID!differentID"))
|
||||
Expect(*value.Root.RemoteItem.ETag).To(Equal("123456789"))
|
||||
Expect(*value.Root.RemoteItem.Id).To(Equal("ownerStorageID!opaqueID"))
|
||||
Expect(*value.Root.RemoteItem.Id).To(Equal("ownerStorageID$spaceID!opaqueID"))
|
||||
Expect(value.Root.RemoteItem.LastModifiedDateTime.UTC()).To(Equal(time.Unix(1648327606, 0).UTC()))
|
||||
Expect(*value.Root.RemoteItem.Folder).To(Equal(libregraph.Folder{}))
|
||||
Expect(*value.Root.RemoteItem.Name).To(Equal("New Folder"))
|
||||
Expect(*value.Root.RemoteItem.Size).To(Equal(int64(1234)))
|
||||
Expect(*value.Root.RemoteItem.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/ownerStorageID!opaqueID"))
|
||||
Expect(*value.Root.RemoteItem.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/ownerStorageID$spaceID%21opaqueID"))
|
||||
})
|
||||
It("can not list spaces with wrong sort parameter", func() {
|
||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||
|
||||
Reference in New Issue
Block a user