Skip to content

Commit 0c688ab

Browse files
Rasmus Welanderglpatcern
authored andcommitted
Add processing of embedded share
1 parent 59512a0 commit 0c688ab

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Add processing endpoint for an embedded share
2+
3+
- For now this only changes the state to accepted (or pending if you want to "unprocess" the share)
4+
- Eventually we want the downloaded content to arrive in the target folder, the target is just logged for now.
5+
6+
https://github.com/cs3org/reva/pull/5489

internal/http/services/sciencemesh/embedded.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/cs3org/reva/v3/pkg/trace"
3333
"google.golang.org/grpc/codes"
3434
rpcstatus "google.golang.org/grpc/status"
35+
"google.golang.org/protobuf/types/known/fieldmaskpb"
3536

3637
ocmconversions "github.com/cs3org/reva/v3/pkg/ocm/conversions"
3738
"github.com/cs3org/reva/v3/pkg/rgrpc/todo/pool"
@@ -54,6 +55,47 @@ func (h *embeddedHandler) init(c *config) error {
5455
return nil
5556
}
5657

58+
func (h *embeddedHandler) ProcessEmbeddedShare(w http.ResponseWriter, r *http.Request) {
59+
ctx := r.Context()
60+
log := appctx.GetLogger(ctx)
61+
queryParams := r.URL.Query()
62+
63+
dest_path := queryParams.Get("destination")
64+
share_id := queryParams.Get("share_id")
65+
process := queryParams.Get("process")
66+
67+
// For now we just log the destination path, but we don't use it yet.
68+
log.Debug().Str("share_id", share_id).Str("dest_path", dest_path).Msg("processing embedded share")
69+
70+
req := ocm.UpdateReceivedOCMShareRequest{
71+
Share: &ocm.ReceivedShare{
72+
Id: &ocm.ShareId{
73+
OpaqueId: share_id,
74+
},
75+
},
76+
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}},
77+
}
78+
79+
// Accept the embedded share or set it back to pending
80+
// depending on the "process" query parameter
81+
switch process {
82+
case "true":
83+
req.Share.State = ocm.ShareState_SHARE_STATE_ACCEPTED
84+
case "false":
85+
req.Share.State = ocm.ShareState_SHARE_STATE_PENDING
86+
}
87+
88+
_, err := h.gatewayClient.UpdateReceivedOCMShare(ctx, &req)
89+
90+
if err != nil {
91+
log.Error().Err(err).Msg("error accepting embedded share")
92+
reqres.WriteError(w, r, reqres.APIErrorServerError, "error accepting embedded share", err)
93+
return
94+
}
95+
96+
w.WriteHeader(http.StatusOK)
97+
}
98+
5799
// ListEmbeddedShares lists all embedded ocm shares for the current user.
58100
func (h *embeddedHandler) ListEmbeddedShares(w http.ResponseWriter, r *http.Request) {
59101
ctx := r.Context()

internal/http/services/sciencemesh/sciencemesh.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (s *svc) routerInit() error {
127127
s.router.Get("/federations", wayfHandler.GetFederations)
128128
s.router.Post("/discover", wayfHandler.DiscoverProvider)
129129
s.router.Get("/embedded-shares", embeddedHandler.ListEmbeddedShares)
130+
s.router.Post("/process-embedded-share", embeddedHandler.ProcessEmbeddedShare)
130131
return nil
131132
}
132133

0 commit comments

Comments
 (0)