fix: proxy policies middleware tus filename evaluation

when uploading files via uppy (tus), the path does not give any information about the file, PUT contains the filename in the path, tus POST not.

this pr extracts the HeaderUploadMetadata from that POST request and enhances the policies grpc environment request with that information.

Therefore, the policies service is now able to evaluate proxy requests for tus uploads too.
This commit is contained in:
Florian Schade
2023-04-18 20:26:52 +02:00
parent e759840401
commit fdaf39f5d1
6 changed files with 25 additions and 12 deletions
@@ -8,6 +8,8 @@ import (
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
pMessage "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/policies/v0"
pService "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/policies/v0"
"github.com/owncloud/ocis/v2/services/webdav/pkg/net"
tusd "github.com/tus/tusd/pkg/handler"
)
// Policies verifies if a request is granted or not.
@@ -32,6 +34,11 @@ func Policies(logger log.Logger, qs string) func(next http.Handler) http.Handler
},
}
meta := tusd.ParseMetadataHeader(r.Header.Get(net.HeaderUploadMetadata))
req.Environment.Resource = &pMessage.Resource{
Name: meta["filename"],
}
if user, ok := revactx.ContextGetUser(r.Context()); ok {
req.Environment.User = &pMessage.User{
Id: &pMessage.User_ID{