Skip to content

Commit

Permalink
use spaceID
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Jul 8, 2022
1 parent 84d9b39 commit 3288c16
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 119 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/space-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Use the spaceID on the cs3 resource

We cleaned up the CS3Api to use a proper attribute for the space id.

https://github.com/owncloud/ocis/pull/4748
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/blevesearch/bleve/v2 v2.3.3
github.com/blevesearch/bleve_index_api v1.0.2
github.com/coreos/go-oidc/v3 v3.2.0
github.com/cs3org/go-cs3apis v0.0.0-20220512100524-551800f020d8
github.com/cs3org/reva/v2 v2.6.2-0.20220706093852-e2232b5a63df
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2
github.com/cs3org/reva/v2 v2.0.0-00010101000000-000000000000
github.com/disintegration/imaging v1.6.2
github.com/ggwhite/go-masker v1.0.9
github.com/go-chi/chi/v5 v5.0.7
Expand Down Expand Up @@ -267,4 +267,4 @@ require (
stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect
)

replace github.com/cs3org/go-cs3apis => github.com/micbar/go-cs3apis v0.0.0-20220617090231-703c04619761 // temp fork
replace github.com/cs3org/reva/v2 => github.com/micbar/reva/v2 v2.0.0-20220707134919-48dff299b296
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p
github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/reva/v2 v2.6.2-0.20220706093852-e2232b5a63df h1:qbfO+xipOcpPsKbzoRAzgq3+JvKkc0JjQR6ov/rE2+I=
github.com/cs3org/reva/v2 v2.6.2-0.20220706093852-e2232b5a63df/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c=
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2 h1:o/ovJzS4pyL/rZgp0MtC4Q7JIle5DikimilTLBw2TjY=
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -889,8 +889,8 @@ github.com/maxymania/go-system v0.0.0-20170110133659-647cc364bf0b h1:Q53idHrTuQD
github.com/maxymania/go-system v0.0.0-20170110133659-647cc364bf0b/go.mod h1:KirJrATYGbTyUwVR26xIkaipRqRcMRXBf8N5dacvGus=
github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103 h1:Z/i1e+gTZrmcGeZyWckaLfucYG6KYOXLWo4co8pZYNY=
github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103/go.mod h1:o9YPB5aGP8ob35Vy6+vyq3P3bWe7NQWzf+JLiXCiMaE=
github.com/micbar/go-cs3apis v0.0.0-20220617090231-703c04619761 h1:vpejExni287rOeBsJxzCDSYJ4d981KXq7HnnaCt2Wn4=
github.com/micbar/go-cs3apis v0.0.0-20220617090231-703c04619761/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/micbar/reva/v2 v2.0.0-20220707134919-48dff299b296 h1:Q6Fdtv+LRG5pSa1ipW940AgtjeqQh9tISD1u3mdzMSk=
github.com/micbar/reva/v2 v2.0.0-20220707134919-48dff299b296/go.mod h1:GlPiCJmt6nDrbPm6lL7pShonSUZ0Ld2GLtR+lATjLCE=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.40/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
Expand Down
88 changes: 49 additions & 39 deletions protogen/gen/ocis/messages/search/v0/search.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions protogen/gen/ocis/services/search/v0/search.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@
},
"opaqueId": {
"type": "string"
},
"spaceId": {
"type": "string"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions protogen/proto/ocis/messages/search/v0/search.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option go_package = "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/sear
message ResourceID {
string storage_id = 1;
string opaque_id = 2;
string space_id = 3;
}

message Reference {
Expand Down
2 changes: 1 addition & 1 deletion services/graph/pkg/service/v0/driveitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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
}

Expand Down
57 changes: 14 additions & 43 deletions services/graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
},
Expand Down Expand Up @@ -453,25 +448,11 @@ 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)
spaceID := storagespace.FormatResourceID(*space.Root)

var permissions []libregraph.Permission
if space.Opaque != nil {
Expand Down Expand Up @@ -548,9 +529,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 {
Expand Down Expand Up @@ -625,11 +607,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)
Expand Down Expand Up @@ -771,17 +750,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
}
Expand All @@ -800,7 +771,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 {
Expand Down
Loading

0 comments on commit 3288c16

Please sign in to comment.