From 84168f063a6b4fb333b577069358924127c0c4e4 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 28 Nov 2022 14:21:17 +0100 Subject: [PATCH] appprovider: pass any other query parameters in /app/open as Opaque to OpenInApp --- .../grpc/services/appprovider/appprovider.go | 2 +- internal/grpc/services/gateway/appprovider.go | 20 ++++++++++--------- .../http/services/appprovider/appprovider.go | 11 ++++++++++ pkg/app/app.go | 3 ++- pkg/app/provider/demo/demo.go | 3 ++- pkg/app/provider/wopi/wopi.go | 8 +++++++- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index 6160603e66d..e26deca71cc 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -212,7 +212,7 @@ func getProvider(c *config) (app.Provider, error) { } func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) { - appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, s.conf.Language) + appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, req.Opaque.Map, s.conf.Language) if err != nil { res := &providerpb.OpenInAppResponse{ Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()), diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index b8fdf61b70a..2c2e24aebbb 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -95,7 +95,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr } if uri.Scheme == "webdav" { insecure, skipVerify := getGRPCConfig(req.Opaque) - return s.openFederatedShares(ctx, fileInfo.Target, req.ViewMode, req.App, insecure, skipVerify, resChild) + return s.openFederatedShares(ctx, fileInfo.Target, req, insecure, skipVerify, resChild) } res, err := s.Stat(ctx, &storageprovider.StatRequest{ @@ -114,10 +114,10 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr } fileInfo = res.Info } - return s.openLocalResources(ctx, fileInfo, req.ViewMode, req.App) + return s.openLocalResources(ctx, fileInfo, req) } -func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenInAppRequest_ViewMode, app string, +func (s *svc) openFederatedShares(ctx context.Context, targetURL string, req *gateway.OpenInAppRequest, insecure, skipVerify bool, nameQueries ...string) (*providerpb.OpenInAppResponse, error) { log := appctx.GetLogger(ctx) targetURL, err := appendNameQuery(targetURL, nameQueries...) @@ -132,8 +132,9 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate ref := &storageprovider.Reference{Path: ep.filePath} appProviderReq := &gateway.OpenInAppRequest{ Ref: ref, - ViewMode: vm, - App: app, + ViewMode: req.ViewMode, + App: req.App, + Opaque: req.Opaque, } meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ @@ -168,8 +169,8 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate return res, nil } -func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo, - vm gateway.OpenInAppRequest_ViewMode, app string) (*providerpb.OpenInAppResponse, error) { +func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo, req *gateway.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) { + accessToken, ok := ctxpkg.ContextGetToken(ctx) if !ok || accessToken == "" { return &providerpb.OpenInAppResponse{ @@ -177,7 +178,7 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour }, nil } - provider, err := s.findAppProvider(ctx, ri, app) + provider, err := s.findAppProvider(ctx, ri, req.App) if err != nil { err = errors.Wrap(err, "gateway: error calling findAppProvider") if _, ok := err.(errtypes.IsNotFound); ok { @@ -195,8 +196,9 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour appProviderReq := &providerpb.OpenInAppRequest{ ResourceInfo: ri, - ViewMode: providerpb.OpenInAppRequest_ViewMode(vm), + ViewMode: providerpb.OpenInAppRequest_ViewMode(req.ViewMode), AccessToken: accessToken, + Opaque: req.Opaque, } res, err := appProviderClient.OpenInApp(ctx, appProviderReq) diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index 2c8c8f94663..42741be2fd1 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -378,10 +378,21 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { return } + opaqueMap := make(map[string]*typespb.OpaqueEntry) + for k, v := range r.Form { + if k != "file_id" && k != "view_mode" && k != "app_name" { + opaqueMap[k] = &typespb.OpaqueEntry{ + Decoder: "plain", + Value: []byte(v[0]), + } + } + } + openReq := gateway.OpenInAppRequest{ Ref: fileRef, ViewMode: viewMode, App: r.Form.Get("app_name"), + Opaque: &typespb.Opaque{Map: opaqueMap}, } openRes, err := client.OpenInApp(ctx, &openReq) if err != nil { diff --git a/pkg/app/app.go b/pkg/app/app.go index b4874d0cef2..587eb594368 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -24,6 +24,7 @@ import ( appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" registry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ) // Registry is the interface that application registries implement @@ -40,6 +41,6 @@ type Registry interface { // Provider is the interface that application providers implement // for interacting with external apps that serve the requested resource. type Provider interface { - GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) + GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string, opaqueMap map[string]*typespb.OpaqueEntry, language string) (*appprovider.OpenInAppURL, error) GetAppProviderInfo(ctx context.Context) (*registry.ProviderInfo, error) } diff --git a/pkg/app/provider/demo/demo.go b/pkg/app/provider/demo/demo.go index ce367381888..cf82267e996 100644 --- a/pkg/app/provider/demo/demo.go +++ b/pkg/app/provider/demo/demo.go @@ -26,6 +26,7 @@ import ( appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/app" "github.com/cs3org/reva/pkg/app/provider/registry" "github.com/mitchellh/mapstructure" @@ -39,7 +40,7 @@ type demoProvider struct { iframeUIProvider string } -func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) { +func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string, opaqueMap map[string]*typespb.OpaqueEntry, language string) (*appprovider.OpenInAppURL, error) { url := fmt.Sprintf("