Skip to content

Commit

Permalink
Implemented new ListExisting*Shares functions
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Aug 2, 2024
1 parent 1077617 commit 9310d4c
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,32 @@ user_layout = "{{.Username}}"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="tmp_folder" type="string" default="/var/tmp" %}}
Path to temporary folder. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L65)
{{< highlight toml >}}
[grpc.services.storageprovider]
tmp_folder = "/var/tmp"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="data_server_url" type="string" default="http://localhost/data" %}}
The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L66)
The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L65)
{{< highlight toml >}}
[grpc.services.storageprovider]
data_server_url = "http://localhost/data"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="expose_data_server" type="bool" default=false %}}
Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L67)
Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L66)
{{< highlight toml >}}
[grpc.services.storageprovider]
expose_data_server = false
{{< /highlight >}}
{{% /dir %}}

{{% dir name="available_checksums" type="map[string]uint32" default=nil %}}
List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L68)
List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L67)
{{< highlight toml >}}
[grpc.services.storageprovider]
available_checksums = nil
{{< /highlight >}}
{{% /dir %}}

{{% dir name="custom_mime_types_json" type="string" default="nil" %}}
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L69)
An optional mapping file with the list of supported custom file extensions and corresponding mime types. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L68)
{{< highlight toml >}}
[grpc.services.storageprovider]
custom_mime_types_json = "nil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ description: >
# _struct: Config_

{{% dir name="insecure" type="bool" default=false %}}
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/owncloud/ocdav/ocdav.go#L110)
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/owncloud/ocdav/ocdav.go#L114)
{{< highlight toml >}}
[http.services.owncloud.ocdav]
insecure = false
{{< /highlight >}}
{{% /dir %}}

{{% dir name="notifications" type="map[string]interface{}" default=nil %}}
settings for the notification helper [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/owncloud/ocdav/ocdav.go#L123)
settings for the notification helper [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/owncloud/ocdav/ocdav.go#L127)
{{< highlight toml >}}
[http.services.owncloud.ocdav]
notifications = nil
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/coreos/go-oidc/v3 v3.9.0
github.com/creasty/defaults v1.7.0
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20231219091702-aa0d20fe6e00
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795
github.com/dgraph-io/ristretto v0.1.1
github.com/dolthub/go-mysql-server v0.14.0
github.com/gdexlab/go-render v1.0.1
Expand Down Expand Up @@ -138,7 +138,6 @@ require (
go 1.21

replace (
github.com/cs3org/go-cs3apis => github.com/gmgigi96/go-cs3apis v0.0.0-20240424151533-8e7c31f06d27
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdB
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795 h1:8WkweBxMQ1W6IhcK0X3eWY+aQCjEktGwVt/4KLrtOZ8=
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -954,8 +956,6 @@ github.com/gdexlab/go-render v1.0.1/go.mod h1:wRi5nW2qfjiGj4mPukH4UV0IknS1cHD4Vg
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9 h1:3um08ooi0/lyRmK2eE1XTKmRQHDzPu0IvpCPMljyMZ8=
github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9/go.mod h1:EJaddanP+JfU3UkVvn0rYYF3b/gD7eZRejbTHqiQExA=
github.com/gmgigi96/go-cs3apis v0.0.0-20240424151533-8e7c31f06d27 h1:4TevraFqK/NVqMZss8pPdSeRS2UAt5LHcAi1qj9D+Mw=
github.com/gmgigi96/go-cs3apis v0.0.0-20240424151533-8e7c31f06d27/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD50WnA=
github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
Expand Down
58 changes: 58 additions & 0 deletions internal/grpc/services/gateway/publicshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ package gateway
import (
"context"

"github.com/alitto/pond"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -121,6 +125,60 @@ func (s *svc) ListPublicShares(ctx context.Context, req *link.ListPublicSharesRe
return res, nil
}

func (s *svc) ListExistingPublicShares(ctx context.Context, req *link.ListPublicSharesRequest) (*gateway.ListExistingPublicSharesResponse, error) {
shares, err := s.ListPublicShares(ctx, req)
if err != nil {
err := errors.Wrap(err, "gateway: error calling ListExistingReceivedShares")
return &gateway.ListExistingPublicSharesResponse{
Status: status.NewInternal(ctx, err, "error listing received shares"),
}, nil
}

sharesCh := make(chan *gateway.PublicShareResourceInfo, len(shares.Share))
pool := pond.New(50, len(shares.Share))
for _, share := range shares.Share {
share := share
// TODO (gdelmont): we should report any eventual error raised by the goroutines
pool.Submit(func() {
// TODO(lopresti) incorporate the cache layer from internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go
stat, err := s.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{
ResourceId: share.ResourceId,
},
})
if err != nil {
return
}
if stat.Status.Code != rpc.Code_CODE_OK {
return
}

sharesCh <- &gateway.PublicShareResourceInfo{
ResourceInfo: stat.Info,
PublicShare: share,
}
})
}

sris := make([]*gateway.PublicShareResourceInfo, 0, len(shares.Share))
done := make(chan struct{})
go func() {
for s := range sharesCh {
sris = append(sris, s)
}
done <- struct{}{}
}()
pool.StopAndWait()
close(sharesCh)
<-done
close(done)

return &gateway.ListExistingPublicSharesResponse{
ShareInfos: sris,
Status: status.NewOK(ctx),
}, nil
}

func (s *svc) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicShareRequest) (*link.UpdatePublicShareResponse, error) {
log := appctx.GetLogger(ctx)
log.Info().Msg("update public share")
Expand Down
68 changes: 61 additions & 7 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,60 @@ func (s *svc) ListShares(ctx context.Context, req *collaboration.ListSharesReque
return res, nil
}

func (s *svc) ListExistingShares(ctx context.Context, req *collaboration.ListSharesRequest) (*gateway.ListExistingSharesResponse, error) {
shares, err := s.ListShares(ctx, req)
if err != nil {
err := errors.Wrap(err, "gateway: error calling ListExistingReceivedShares")
return &gateway.ListExistingSharesResponse{
Status: status.NewInternal(ctx, err, "error listing received shares"),
}, nil
}

sharesCh := make(chan *gateway.ShareResourceInfo, len(shares.Shares))
pool := pond.New(50, len(shares.Shares))
for _, share := range shares.Shares {
share := share
// TODO (gdelmont): we should report any eventual error raised by the goroutines
pool.Submit(func() {
// TODO(lopresti) incorporate the cache layer from internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go
stat, err := s.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{
ResourceId: share.ResourceId,
},
})
if err != nil {
return
}
if stat.Status.Code != rpc.Code_CODE_OK {
return
}

sharesCh <- &gateway.ShareResourceInfo{
ResourceInfo: stat.Info,
Share: share,
}
})
}

sris := make([]*gateway.ShareResourceInfo, 0, len(shares.Shares))
done := make(chan struct{})
go func() {
for s := range sharesCh {
sris = append(sris, s)
}
done <- struct{}{}
}()
pool.StopAndWait()
close(sharesCh)
<-done
close(done)

return &gateway.ListExistingSharesResponse{
ShareInfos: sris,
Status: status.NewOK(ctx),
}, nil
}

func (s *svc) UpdateShare(ctx context.Context, req *collaboration.UpdateShareRequest) (*collaboration.UpdateShareResponse, error) {
c, err := pool.GetUserShareProviderClient(pool.Endpoint(s.c.UserShareProviderEndpoint))
if err != nil {
Expand Down Expand Up @@ -263,7 +317,7 @@ func (s *svc) ListExistingReceivedShares(ctx context.Context, req *collaboration
}, nil
}

sharesCh := make(chan *gateway.SharedResourceInfo, len(rshares.Shares))
sharesCh := make(chan *gateway.ReceivedShareResourceInfo, len(rshares.Shares))
pool := pond.New(50, len(rshares.Shares))
for _, rs := range rshares.Shares {
rs := rs
Expand All @@ -286,14 +340,14 @@ func (s *svc) ListExistingReceivedShares(ctx context.Context, req *collaboration
return
}

sharesCh <- &gateway.SharedResourceInfo{
ResourceInfo: stat.Info,
Share: rs,
sharesCh <- &gateway.ReceivedShareResourceInfo{
ResourceInfo: stat.Info,
ReceivedShare: rs,
}
})
}

sris := make([]*gateway.SharedResourceInfo, 0, len(rshares.Shares))
sris := make([]*gateway.ReceivedShareResourceInfo, 0, len(rshares.Shares))
done := make(chan struct{})
go func() {
for s := range sharesCh {
Expand All @@ -307,8 +361,8 @@ func (s *svc) ListExistingReceivedShares(ctx context.Context, req *collaboration
close(done)

return &gateway.ListExistingReceivedSharesResponse{
Shares: sris,
Status: status.NewOK(ctx),
ShareInfos: sris,
Status: status.NewOK(ctx),
}, nil
}

Expand Down
36 changes: 18 additions & 18 deletions internal/http/services/owncloud/ocgraph/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func getDrivesForShares(ctx context.Context, gw gateway.GatewayAPIClient) ([]*li
return nil, errors.New(res.Status.Message)
}

spacesRes := make([]*libregraph.Drive, 0, len(res.Shares))
for _, s := range res.Shares {
spacesRes := make([]*libregraph.Drive, 0, len(res.ShareInfos))
for _, s := range res.ShareInfos {
spacesRes = append(spacesRes, convertShareToSpace(s))
}
return spacesRes, nil
Expand All @@ -139,34 +139,34 @@ func libregraphShareID(shareID *collaborationv1beta1.ShareId) string {
return fmt.Sprintf("%s$%s!%s", shareJailID, shareJailID, shareID.OpaqueId)
}

func convertShareToSpace(share *gateway.SharedResourceInfo) *libregraph.Drive {
func convertShareToSpace(rsi *gateway.ReceivedShareResourceInfo) *libregraph.Drive {
// the prefix of the remote_item.id and rootid
return &libregraph.Drive{
Id: libregraph.PtrString(libregraphShareID(share.Share.Share.Id)),
Id: libregraph.PtrString(libregraphShareID(rsi.ReceivedShare.Share.Id)),
DriveType: libregraph.PtrString("mountpoint"),
DriveAlias: libregraph.PtrString(share.Share.Share.Id.OpaqueId), // this is not used, but must not be the same alias as the drive item
Name: filepath.Base(share.ResourceInfo.Path),
DriveAlias: libregraph.PtrString(rsi.ReceivedShare.Share.Id.OpaqueId), // this is not used, but must not be the same alias as the drive item
Name: filepath.Base(rsi.ResourceInfo.Path),
Quota: &libregraph.Quota{
Total: libregraph.PtrInt64(24154390300000),
Used: libregraph.PtrInt64(3141592),
Remaining: libregraph.PtrInt64(24154387158408),
},
Root: &libregraph.DriveItem{
Id: libregraph.PtrString(fmt.Sprintf("%s$%s!%s", shareJailID, shareJailID, share.Share.Share.Id.OpaqueId)),
Id: libregraph.PtrString(fmt.Sprintf("%s$%s!%s", shareJailID, shareJailID, rsi.ReceivedShare.Share.Id.OpaqueId)),
RemoteItem: &libregraph.RemoteItem{
DriveAlias: libregraph.PtrString(strings.TrimSuffix(strings.TrimPrefix(share.ResourceInfo.Path, "/"), relativePathToSpaceID(share.ResourceInfo))), // the drive alias must not start with /
ETag: libregraph.PtrString(share.ResourceInfo.Etag),
DriveAlias: libregraph.PtrString(strings.TrimSuffix(strings.TrimPrefix(rsi.ResourceInfo.Path, "/"), relativePathToSpaceID(rsi.ResourceInfo))), // the drive alias must not start with /
ETag: libregraph.PtrString(rsi.ResourceInfo.Etag),
Folder: &libregraph.Folder{},
// The Id must correspond to the id in the OCS response, for the time being
// It is in the form <something>!<something-else>
Id: libregraph.PtrString(spaces.EncodeResourceID(share.ResourceInfo.Id)),
LastModifiedDateTime: libregraph.PtrTime(time.Unix(int64(share.ResourceInfo.Mtime.Seconds), int64(share.ResourceInfo.Mtime.Nanos))),
Name: libregraph.PtrString(filepath.Base(share.ResourceInfo.Path)),
Path: libregraph.PtrString(relativePathToSpaceID(share.ResourceInfo)),
Id: libregraph.PtrString(spaces.EncodeResourceID(rsi.ResourceInfo.Id)),
LastModifiedDateTime: libregraph.PtrTime(time.Unix(int64(rsi.ResourceInfo.Mtime.Seconds), int64(rsi.ResourceInfo.Mtime.Nanos))),
Name: libregraph.PtrString(filepath.Base(rsi.ResourceInfo.Path)),
Path: libregraph.PtrString(relativePathToSpaceID(rsi.ResourceInfo)),
// RootId must have the same token before ! as Id
// the second part for the time being is not used
RootId: libregraph.PtrString(fmt.Sprintf("%s!unused_root_id", spaces.EncodeSpaceID(share.ResourceInfo.Id.StorageId, share.ResourceInfo.Id.SpaceId))),
Size: libregraph.PtrInt64(int64(share.ResourceInfo.Size)),
RootId: libregraph.PtrString(fmt.Sprintf("%s!unused_root_id", spaces.EncodeSpaceID(rsi.ResourceInfo.Id.StorageId, rsi.ResourceInfo.Id.SpaceId))),
Size: libregraph.PtrInt64(int64(rsi.ResourceInfo.Size)),
},
},
}
Expand Down Expand Up @@ -287,9 +287,9 @@ func (s *svc) getSpace(w http.ResponseWriter, r *http.Request) {
return
}

space := convertShareToSpace(&gateway.SharedResourceInfo{
ResourceInfo: stat.Info,
Share: shareRes.Share,
space := convertShareToSpace(&gateway.ReceivedShareResourceInfo{
ResourceInfo: stat.Info,
ReceivedShare: shareRes.Share,
})
_ = json.NewEncoder(w).Encode(space)
return
Expand Down
Loading

0 comments on commit 9310d4c

Please sign in to comment.