diff --git a/go.mod b/go.mod index f41356c9dff..4f2f0c7aafa 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( go 1.16 replace ( - github.com/cs3org/go-cs3apis => github.com/ishank011/go-cs3apis v0.0.0-20210628124432-b0cb570ff3ee + github.com/cs3org/go-cs3apis => github.com/ishank011/go-cs3apis v0.0.0-20210701122052-bb129518b297 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 google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade diff --git a/go.sum b/go.sum index 1bcf8978e1a..85b9e5627b4 100644 --- a/go.sum +++ b/go.sum @@ -670,8 +670,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/inhies/go-bytesize v0.0.0-20201103132853-d0aed0d254f8/go.mod h1:KrtyD5PFj++GKkFS/7/RRrfnRhAMGQwy75GLCHWrCNs= -github.com/ishank011/go-cs3apis v0.0.0-20210628124432-b0cb570ff3ee h1:kAhkI0AB13WyGT1eAYmGK9f7bT9pNQLpNeQUurREAu8= -github.com/ishank011/go-cs3apis v0.0.0-20210628124432-b0cb570ff3ee/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/ishank011/go-cs3apis v0.0.0-20210701122052-bb129518b297 h1:v20yOPhlP4pPuoe1i1UNQzynZzSpf2c+j4zHHPM7620= +github.com/ishank011/go-cs3apis v0.0.0-20210701122052-bb129518b297/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index b1f8261b203..fe2479d4335 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -143,7 +143,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.App, req.AccessToken) + appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken) if err != nil { err := errors.Wrap(err, "appprovider: error calling GetAppURL") res := &providerpb.OpenInAppResponse{ diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index f7921c9520d..304e36f0384 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -183,7 +183,7 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour }, nil } - provider, err := s.findAppProvider(ctx, ri) + provider, err := s.findAppProvider(ctx, ri, app) if err != nil { err = errors.Wrap(err, "gateway: error calling findAppProvider") var st *rpc.Status @@ -208,7 +208,6 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour appProviderReq := &providerpb.OpenInAppRequest{ ResourceInfo: ri, ViewMode: providerpb.OpenInAppRequest_ViewMode(vm), - App: app, AccessToken: accessToken, } @@ -220,32 +219,49 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour return res, nil } -func (s *svc) findAppProvider(ctx context.Context, ri *storageprovider.ResourceInfo) (*registry.ProviderInfo, error) { +func (s *svc) findAppProvider(ctx context.Context, ri *storageprovider.ResourceInfo, app string) (*registry.ProviderInfo, error) { c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint) if err != nil { err = errors.Wrap(err, "gateway: error getting appregistry client") return nil, err } + + if app == "" { + // We need to get the default provider in case app is not set + // If the default isn't set as well, we'll return the first provider which matches the mimetype + res, err := c.GetDefaultAppProviderForMimeType(ctx, ®istry.GetDefaultAppProviderForMimeTypeRequest{ + MimeType: ri.MimeType, + }) + if err == nil && res.Status.Code == rpc.Code_CODE_OK && res.Provider != nil { + return res.Provider, nil + } + } + res, err := c.GetAppProviders(ctx, ®istry.GetAppProvidersRequest{ ResourceInfo: ri, }) - if err != nil { err = errors.Wrap(err, "gateway: error calling GetAppProviders") return nil, err } - - // TODO(labkode): when sending an Open to the proxy we need to choose one - // provider from the list of available as the client - if res.Status.Code == rpc.Code_CODE_OK { - return res.Providers[0], nil + if res.Status.Code != rpc.Code_CODE_OK { + if res.Status.Code == rpc.Code_CODE_NOT_FOUND { + return nil, errtypes.NotFound("gateway: app provider not found for resource: " + ri.String()) + } + return nil, errtypes.InternalError("gateway: error finding app providers") } - if res.Status.Code == rpc.Code_CODE_NOT_FOUND { - return nil, errtypes.NotFound("gateway: app provider not found for resource: " + ri.String()) + if app != "" { + for _, p := range res.Providers { + if p.Name == app { + return p, nil + } + } + return nil, errtypes.NotFound("gateway: app provider not found: " + app) } - return nil, errtypes.InternalError("gateway: error finding a storage provider") + // As a fallback, return the first provider in the list + return res.Providers[0], nil } func getGRPCConfig(opaque *typespb.Opaque) (bool, bool) { diff --git a/pkg/app/app.go b/pkg/app/app.go index a3595ffba57..b4ff68925c9 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -39,6 +39,6 @@ type Registry interface { // Provider is the interface that application providers implement // for providing the URL of the app which will serve the requested resource. type Provider interface { - GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, app, token string) (string, error) + GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (string, 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 39d75fba2b3..4805f2b1b94 100644 --- a/pkg/app/provider/demo/demo.go +++ b/pkg/app/provider/demo/demo.go @@ -39,7 +39,7 @@ type demoProvider struct { iframeUIProvider string } -func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, app, token string) (string, error) { +func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (string, error) { msg := fmt.Sprintf("