@@ -68,11 +68,11 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
68
68
ctx := r .Context ()
69
69
log := appctx .GetLogger (ctx )
70
70
req , err := getCreateShareRequest (r )
71
+ log .Info ().Any ("req" , req ).Msg ("OCM /shares request received" )
71
72
if err != nil {
72
73
reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , err .Error (), nil )
73
74
return
74
75
}
75
- log .Info ().Any ("req" , req ).Msg ("OCM /shares request received" )
76
76
77
77
_ , meshProvider , err := getIDAndMeshProvider (req .Sender )
78
78
log .Debug ().Msgf ("Determined Mesh Provider '%s' from req.Sender '%s'" , meshProvider , req .Sender )
@@ -99,7 +99,7 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
99
99
Provider : & providerInfo ,
100
100
})
101
101
if err != nil {
102
- reqres .WriteError (w , r , reqres .APIErrorServerError , "error sending a grpc is provider allowed request" , err )
102
+ reqres .WriteError (w , r , reqres .APIErrorServerError , "error sending a grpc isProviderAllowed request" , err )
103
103
return
104
104
}
105
105
if providerAllowedResp .Status .Code != rpc .Code_CODE_OK {
@@ -109,7 +109,7 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
109
109
110
110
shareWith , _ , err := getIDAndMeshProvider (req .ShareWith )
111
111
if err != nil {
112
- reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , err . Error (), nil )
112
+ reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , "error with mesh provider" , err )
113
113
return
114
114
}
115
115
@@ -127,19 +127,19 @@ func (h *sharesHandler) CreateShare(w http.ResponseWriter, r *http.Request) {
127
127
128
128
owner , err := getUserIDFromOCMUser (req .Owner )
129
129
if err != nil {
130
- reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , err . Error (), nil )
130
+ reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , "error with remote owner" , err )
131
131
return
132
132
}
133
133
134
134
sender , err := getUserIDFromOCMUser (req .Sender )
135
135
if err != nil {
136
- reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , err . Error (), nil )
136
+ reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , "error with remote sender" , err )
137
137
return
138
138
}
139
139
140
140
protocols , err := getAndResolveProtocols (req .Protocols , r )
141
141
if err != nil {
142
- reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , err . Error (), nil )
142
+ reqres .WriteError (w , r , reqres .APIErrorInvalidParameter , "error with protocols payload" , err )
143
143
return
144
144
}
145
145
@@ -249,45 +249,46 @@ func getOCMShareType(t string) ocm.ShareType {
249
249
func getAndResolveProtocols (p Protocols , r * http.Request ) ([]* ocm.Protocol , error ) {
250
250
protos := make ([]* ocm.Protocol , 0 , len (p ))
251
251
for _ , data := range p {
252
+ var uri string
252
253
ocmProto := data .ToOCMProtocol ()
253
254
protocolName := GetProtocolName (data )
254
- var uri string
255
- var isLocalhost bool
256
-
257
255
switch protocolName {
258
256
case "webdav" :
259
257
uri = ocmProto .GetWebdavOptions ().Uri
260
- isLocalhost = strings .Contains (uri , "localhost" )
258
+ reqs := ocmProto .GetWebdavOptions ().Requirements
259
+ if len (reqs ) > 0 {
260
+ // we currently do not support any kind of requirement
261
+ return nil , errtypes .BadRequest (fmt .Sprintf ("incoming OCM share with requirements %+v not supported at this endpoint" , reqs ))
262
+ }
261
263
case "webapp" :
262
- uri = ocmProto .GetWebappOptions ().UriTemplate
263
- isLocalhost = strings .Contains (uri , "localhost" )
264
+ uri = ocmProto .GetWebappOptions ().Uri
264
265
}
265
266
266
- // Irrespective from the presence of a full `uri` in the payload (deprecated), resolve the remote root
267
+ // Irrespective from the presence of a full `uri` in the payload (deprecated), validate the
268
+ // remote is an OCM server and resolve the remote root
267
269
// yet skip this if the remote is localhost (for integration tests)
268
- if isLocalhost {
270
+ if strings . Contains ( uri , "localhost" ) {
269
271
protos = append (protos , ocmProto )
270
272
continue
271
273
}
272
274
remoteRoot , err := discoverOcmRoot (r , protocolName )
273
275
if err != nil {
274
276
return nil , err
275
277
}
276
- uri , _ = url .JoinPath (remoteRoot , uri [strings .LastIndex (uri , "/" )+ 1 :])
277
278
279
+ uri , _ = url .JoinPath (remoteRoot , uri [strings .LastIndex (uri , "/" )+ 1 :])
278
280
switch protocolName {
279
281
case "webdav" :
280
282
ocmProto .GetWebdavOptions ().Uri = uri
281
283
case "webapp" :
282
- ocmProto .GetWebappOptions ().UriTemplate = uri
284
+ ocmProto .GetWebappOptions ().Uri = uri
283
285
}
284
286
protos = append (protos , ocmProto )
285
287
}
286
288
287
289
return protos , nil
288
290
}
289
291
290
-
291
292
func discoverOcmRoot (r * http.Request , proto string ) (string , error ) {
292
293
// implements the OCM discovery logic to fetch the root at the remote host that sent the share for the given proto, see
293
294
// https://cs3org.github.io/OCM-API/docs.html?branch=v1.1.0&repo=OCM-API&user=cs3org#/paths/~1ocm-provider/get
0 commit comments