use spaceID

This commit is contained in:
Michael Barz
2022-07-11 10:44:09 +02:00
parent 84d9b390a6
commit 2a113e9f7d
15 changed files with 216 additions and 178 deletions
+36 -35
View File
@@ -29,7 +29,7 @@ var testCases = []struct {
Sharer: userID("sharing-userid"),
GranteeUserID: userID("beshared-userid"),
GranteeGroupID: nil,
ItemID: resourceID("storage-1", "itemid-1"),
ItemID: resourceID("provider-1", "storage-1", "itemid-1"),
CTime: timestamp(0),
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -56,7 +56,7 @@ var testCases = []struct {
Sharer: userID("sharing-userid"),
GranteeUserID: nil,
GranteeGroupID: groupID("beshared-groupid"),
ItemID: resourceID("storage-1", "itemid-1"),
ItemID: resourceID("provider-1", "storage-1", "itemid-1"),
CTime: timestamp(10e8),
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -85,7 +85,7 @@ var testCases = []struct {
Sharer: userID("sharing-userid"),
GranteeUserID: nil,
GranteeGroupID: groupID("beshared-groupid"),
ItemID: resourceID("storage-1", "itemid-1"),
ItemID: resourceID("provider-1", "storage-1", "itemid-1"),
Permissions: sharePermissions("stat", "get_quota"),
MTime: timestamp(10e8),
Updated: "permissions",
@@ -113,7 +113,7 @@ var testCases = []struct {
SystemEvent: events.LinkUpdated{
ShareID: linkID("shareid"),
Sharer: userID("sharing-userid"),
ItemID: resourceID("storage-1", "itemid-1"),
ItemID: resourceID("provider-1", "storage-1", "itemid-1"),
Permissions: linkPermissions("stat"),
CTime: timestamp(10e8),
DisplayName: "link",
@@ -203,7 +203,7 @@ var testCases = []struct {
Alias: "Share accepted",
SystemEvent: events.ReceivedShareUpdated{
ShareID: shareID("shareid"),
ItemID: resourceID("storageid-1", "itemid-1"),
ItemID: resourceID("provider-1", "storageid-1", "itemid-1"),
Permissions: sharePermissions("get_quota"),
GranteeUserID: userID("beshared-userid"),
GranteeGroupID: nil,
@@ -228,7 +228,7 @@ var testCases = []struct {
Alias: "Share declined",
SystemEvent: events.ReceivedShareUpdated{
ShareID: shareID("shareid"),
ItemID: resourceID("storageid-1", "itemid-1"),
ItemID: resourceID("provider-1", "storageid-1", "itemid-1"),
Permissions: sharePermissions("get_quota"),
GranteeUserID: userID("beshared-userid"),
GranteeGroupID: nil,
@@ -254,7 +254,7 @@ var testCases = []struct {
SystemEvent: events.LinkAccessed{
ShareID: linkID("shareid"),
Sharer: userID("sharing-userid"),
ItemID: resourceID("storage-1", "itemid-1"),
ItemID: resourceID("provider-1", "storage-1", "itemid-1"),
Permissions: linkPermissions("stat"),
DisplayName: "link",
Expiration: timestamp(10e8 + 10e5),
@@ -300,7 +300,7 @@ var testCases = []struct {
Alias: "File created",
SystemEvent: events.FileUploaded{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -308,15 +308,15 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' created file 'sto-123!iid-123/item'", "file_create")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' created file 'pro-1$sto-123!iid-123/item'", "file_create")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
},
}, {
Alias: "File read",
SystemEvent: events.FileDownloaded{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -324,15 +324,15 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' read file 'sto-123!iid-123/item'", "file_read")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' read file 'pro-1$sto-123!iid-123/item'", "file_read")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
},
}, {
Alias: "File trashed",
SystemEvent: events.ItemTrashed{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -340,16 +340,16 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' trashed file 'sto-123!iid-123/item'", "file_delete")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' trashed file 'pro-1$sto-123!iid-123/item'", "file_delete")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
},
}, {
Alias: "File renamed",
SystemEvent: events.ItemMoved{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
OldReference: reference("sto-123", "iid-123", "./anotheritem"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
OldReference: reference("pro-1", "sto-123", "iid-123", "./anotheritem"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -357,9 +357,9 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' moved file 'sto-123!iid-123/item' from './anotheritem' to './item'", "file_rename")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' moved file 'pro-1$sto-123!iid-123/item' from './anotheritem' to './item'", "file_rename")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
// AuditEventFileRenamed fields
require.Equal(t, "./anotheritem", ev.OldPath)
@@ -368,7 +368,7 @@ var testCases = []struct {
Alias: "File purged",
SystemEvent: events.ItemPurged{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -376,17 +376,17 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' removed file 'sto-123!iid-123/item' from trashbin", "file_trash_delete")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' removed file 'pro-1$sto-123!iid-123/item' from trashbin", "file_trash_delete")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
},
}, {
Alias: "File restored",
SystemEvent: events.ItemRestored{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
OldReference: reference("sto-123", "sto-123!iid-123/item", "./oldpath"),
OldReference: reference("pro-1", "sto-123", "sto-123!iid-123/item", "./oldpath"),
Key: "",
},
CheckAuditEvent: func(t *testing.T, b []byte) {
@@ -394,9 +394,9 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' restored file 'sto-123!iid-123/item' from trashbin to './item'", "file_trash_restore")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' restored file 'pro-1$sto-123!iid-123/item' from trashbin to './item'", "file_trash_restore")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
// AuditEventFileRestored fields
require.Equal(t, "./oldpath", ev.OldPath)
@@ -405,7 +405,7 @@ var testCases = []struct {
Alias: "File version restored",
SystemEvent: events.FileVersionRestored{
Executant: userID("uid-123"),
Ref: reference("sto-123", "iid-123", "./item"),
Ref: reference("pro-1", "sto-123", "iid-123", "./item"),
Owner: userID("uid-123"), // NOTE: owner not yet implemented in reva
Key: "v1",
},
@@ -414,9 +414,9 @@ var testCases = []struct {
require.NoError(t, json.Unmarshal(b, &ev))
// AuditEvent fields
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' restored file 'sto-123!iid-123/item' in version 'v1'", "file_version_restore")
checkBaseAuditEvent(t, ev.AuditEvent, "uid-123", "", "user 'uid-123' restored file 'pro-1$sto-123!iid-123/item' in version 'v1'", "file_version_restore")
// AuditEventSharing fields
checkFilesAuditEvent(t, ev.AuditEventFiles, "sto-123!iid-123/item", "uid-123", "./item")
checkFilesAuditEvent(t, ev.AuditEventFiles, "pro-1$sto-123!iid-123/item", "uid-123", "./item")
// AuditEventFileRestored fields
require.Equal(t, "v1", ev.Key)
@@ -427,7 +427,7 @@ var testCases = []struct {
Executant: userID("uid-123"),
ID: &provider.StorageSpaceId{OpaqueId: "space-123"},
Owner: userID("uid-123"),
Root: resourceID("sto-123", "iid-123"),
Root: resourceID("pro-1", "sto-123", "iid-123"),
Name: "test-space",
Type: "project",
Quota: nil, // Quota not interesting atm
@@ -443,7 +443,7 @@ var testCases = []struct {
checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123")
// AuditEventFileRestored fields
require.Equal(t, "uid-123", ev.Owner)
require.Equal(t, "sto-123!iid-123", ev.RootItem)
require.Equal(t, "pro-1$sto-123!iid-123", ev.RootItem)
require.Equal(t, "test-space", ev.Name)
require.Equal(t, "project", ev.Type)
},
@@ -595,16 +595,17 @@ func groupID(id string) *group.GroupId {
}
}
func resourceID(sid, oid string) *provider.ResourceId {
func resourceID(sid, spid, oid string) *provider.ResourceId {
return &provider.ResourceId{
StorageId: sid,
SpaceId: spid,
OpaqueId: oid,
}
}
func reference(sid, oid, path string) *provider.Reference {
func reference(sid, spid, oid, path string) *provider.Reference {
return &provider.Reference{
ResourceId: resourceID(sid, oid),
ResourceId: resourceID(sid, spid, oid),
Path: path,
}
}
+9 -2
View File
@@ -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
}
+19 -44
View File
@@ -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 {
+22 -17
View File
@@ -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{
+25 -13
View File
@@ -33,6 +33,7 @@ import (
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
"github.com/blevesearch/bleve/v2/analysis/tokenizer/single"
"github.com/blevesearch/bleve/v2/mapping"
"github.com/cs3org/reva/v2/pkg/storagespace"
"google.golang.org/protobuf/types/known/timestamppb"
sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -218,7 +219,11 @@ func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) (
query := bleve.NewConjunctionQuery(
bleve.NewQueryStringQuery(req.Query),
deletedQuery, // Skip documents that have been marked as deleted
bleve.NewQueryStringQuery("RootID:"+req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId), // Limit search to the space
bleve.NewQueryStringQuery("RootID:"+idToBleveId(&sprovider.ResourceId{
StorageId: req.Ref.GetResourceId().GetStorageId(),
SpaceId: req.Ref.GetResourceId().GetSpaceId(),
OpaqueId: req.Ref.GetResourceId().GetOpaqueId(),
})), // Limit search to the space
bleve.NewQueryStringQuery("Path:"+queryEscape(utils.MakeRelativePath(path.Join(req.Ref.Path, "/"))+"*")), // Limit search to this directory in the space
)
bleveReq := bleve.NewSearchRequest(query)
@@ -307,22 +312,22 @@ func fieldsToEntity(fields map[string]interface{}) *indexDocument {
}
func fromFields(fields map[string]interface{}) (*searchmsg.Match, error) {
rootIDParts := strings.SplitN(fields["RootID"].(string), "!", 2)
IDParts := strings.SplitN(fields["ID"].(string), "!", 2)
rootID, err := storagespace.ParseID(fields["RootID"].(string))
if err != nil {
return nil, err
}
rID, err := storagespace.ParseID(fields["ID"].(string))
if err != nil {
return nil, err
}
match := &searchmsg.Match{
Entity: &searchmsg.Entity{
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: rootIDParts[0],
OpaqueId: rootIDParts[1],
},
Path: fields["Path"].(string),
},
Id: &searchmsg.ResourceID{
StorageId: IDParts[0],
OpaqueId: IDParts[1],
ResourceId: resourceIDtoSearchID(rootID),
Path: fields["Path"].(string),
},
Id: resourceIDtoSearchID(rID),
Name: fields["Name"].(string),
Size: uint64(fields["Size"].(float64)),
Type: uint64(fields["Type"].(float64)),
@@ -342,7 +347,14 @@ func idToBleveId(id *sprovider.ResourceId) string {
if id == nil {
return ""
}
return id.StorageId + "!" + id.OpaqueId
return storagespace.FormatResourceID(*id)
}
func resourceIDtoSearchID(id sprovider.ResourceId) *searchmsg.ResourceID {
return &searchmsg.ResourceID{
StorageId: id.GetStorageId(),
SpaceId: id.GetSpaceId(),
OpaqueId: id.GetOpaqueId()}
}
func queryEscape(s string) string {
+21 -10
View File
@@ -21,7 +21,8 @@ var _ = Describe("Index", func() {
ctx context.Context
rootId = &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "rootopaqueid",
}
filename string
@@ -33,7 +34,8 @@ var _ = Describe("Index", func() {
}
parentRi = &sprovider.ResourceInfo{
Id: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "parentopaqueid",
},
Path: "sub d!r",
@@ -47,11 +49,13 @@ var _ = Describe("Index", func() {
}
childRi = &sprovider.ResourceInfo{
Id: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "childopaqueid",
},
ParentId: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "parentopaqueid",
},
Path: "child.pdf",
@@ -65,7 +69,8 @@ var _ = Describe("Index", func() {
Query: query,
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: rootId.StorageId,
StorageId: "provider-1",
SpaceId: rootId.SpaceId,
OpaqueId: rootId.OpaqueId,
},
},
@@ -96,11 +101,13 @@ var _ = Describe("Index", func() {
}
ri = &sprovider.ResourceInfo{
Id: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "opaqueid",
},
ParentId: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "someopaqueid",
},
Path: filename,
@@ -172,7 +179,8 @@ var _ = Describe("Index", func() {
It("scopes the search to the specified space", func() {
resourceId := &sprovider.ResourceId{
StorageId: "differentstorageid",
StorageId: "provider-1",
SpaceId: "differentspaceid",
OpaqueId: "differentopaqueid",
}
assertDocCount(resourceId, `Name:foo.pdf`, 0)
@@ -222,14 +230,16 @@ var _ = Describe("Index", func() {
BeforeEach(func() {
nestedRef = &sprovider.Reference{
ResourceId: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "rootopaqueid",
},
Path: "./nested/nestedpdf.pdf",
}
nestedRI = &sprovider.ResourceInfo{
Id: &sprovider.ResourceId{
StorageId: "storageid",
StorageId: "provider-1",
SpaceId: "spaceid",
OpaqueId: "nestedopaqueid",
},
Path: "nestedpdf.pdf",
@@ -251,6 +261,7 @@ var _ = Describe("Index", func() {
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: ref.ResourceId.StorageId,
SpaceId: ref.ResourceId.SpaceId,
OpaqueId: ref.ResourceId.OpaqueId,
},
Path: "./nested/",
@@ -92,6 +92,7 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s
opaqueMap := sdk.DecodeOpaqueMap(space.Opaque)
grantSpaceId := storagespace.FormatResourceID(provider.ResourceId{
StorageId: opaqueMap["grantStorageID"],
SpaceId: opaqueMap["grantSpaceID"],
OpaqueId: opaqueMap["grantOpaqueID"],
})
mountpointMap[grantSpaceId] = space.Id.OpaqueId
@@ -122,25 +123,26 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s
continue
}
mountpointPrefix = utils.MakeRelativePath(gpRes.Path)
sid, oid, err := storagespace.SplitID(mountpointId)
sid, spid, oid, err := storagespace.SplitID(mountpointId)
if err != nil {
p.logger.Error().Err(err).Str("space", space.Id.OpaqueId).Str("mountpointId", mountpointId).Msg("invalid mountpoint space id")
continue
}
mountpointRootId = &searchmsg.ResourceID{
StorageId: sid,
SpaceId: spid,
OpaqueId: oid,
}
p.logger.Debug().Interface("grantSpace", space).Interface("mountpointRootId", mountpointRootId).Msg("searching a grant")
}
_, rootStorageID := storagespace.SplitStorageID(space.Root.StorageId)
res, err := p.indexClient.Search(ctx, &searchsvc.SearchIndexRequest{
Query: formatQuery(req.Query),
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: space.Root.StorageId,
OpaqueId: rootStorageID,
SpaceId: space.Root.SpaceId,
OpaqueId: space.Root.OpaqueId,
},
Path: mountpointPrefix,
},
@@ -197,14 +199,18 @@ func (p *Provider) IndexSpace(ctx context.Context, req *searchsvc.IndexSpaceRequ
// Walk the space and index all files
walker := walker.NewWalker(p.gwClient)
rootId := &provider.ResourceId{StorageId: req.SpaceId, OpaqueId: req.SpaceId}
err = walker.Walk(ownerCtx, rootId, func(wd string, info *provider.ResourceInfo, err error) error {
rootId, err := storagespace.ParseID(req.SpaceId)
if err != nil {
p.logger.Error().Err(err).Msg(err.Error())
return nil, err
}
err = walker.Walk(ownerCtx, &rootId, func(wd string, info *provider.ResourceInfo, err error) error {
if err != nil {
p.logger.Error().Err(err).Msg("error walking the tree")
}
ref := &provider.Reference{
Path: utils.MakeRelativePath(filepath.Join(wd, info.Path)),
ResourceId: rootId,
ResourceId: &rootId,
}
err = p.indexClient.Add(ref, info)
if err != nil {