From 194ab4b44d9e23a46c6bc07de38a4384bfe32a3e Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 3 Sep 2020 14:29:03 +0200 Subject: [PATCH 01/10] Call the gateway stat method from appprovider --- changelog/unreleased/appprovider-stat.md | 7 +++++++ internal/grpc/services/gateway/appprovider.go | 15 ++------------- 2 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 changelog/unreleased/appprovider-stat.md diff --git a/changelog/unreleased/appprovider-stat.md b/changelog/unreleased/appprovider-stat.md new file mode 100644 index 0000000000..d71b1eb7dd --- /dev/null +++ b/changelog/unreleased/appprovider-stat.md @@ -0,0 +1,7 @@ +Bugfix: Call the gateway stat method from appprovider + +The appprovider service used to directly pass the stat request to the storage +provider bypassing the gateway, which resulted in errors while handling share +children as they are resolved in the gateway path. + +https://github.com/cs3org/reva/pull/1140 diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index aa4c0933a1..22d1706d5a 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -37,22 +37,11 @@ import ( ) func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileInAppProviderRequest) (*providerpb.OpenFileInAppProviderResponse, error) { - c, err := s.find(ctx, req.Ref) - if err != nil { - if _, ok := err.(errtypes.IsNotFound); ok { - return &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewInternal(ctx, err, "storage provider not found"), - }, nil - } - return &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewInternal(ctx, err, "error finding storage provider"), - }, nil - } accessToken, ok := tokenpkg.ContextGetToken(ctx) if !ok || accessToken == "" { return &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewUnauthenticated(ctx, err, "Access token is invalid or empty"), + Status: status.NewUnauthenticated(ctx, errors.New("Access token is invalid or empty"), ""), }, nil } @@ -60,7 +49,7 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn Ref: req.Ref, } - statRes, err := c.Stat(ctx, statReq) + statRes, err := s.Stat(ctx, statReq) if err != nil { return &providerpb.OpenFileInAppProviderResponse{ Status: status.NewInternal(ctx, err, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()), From 41af75af4f499bc390d989a2085e6543fcd5637d Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 3 Sep 2020 15:27:09 +0200 Subject: [PATCH 02/10] Handle listing of expired shares --- internal/grpc/services/gateway/storageprovider.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 7a15d989dd..128c5cc6e5 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -1320,9 +1320,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ if protocol == "webdav" { info, err = s.webdavRefStat(ctx, ref.Target) if err != nil { - return &provider.ListContainerResponse{ - Status: status.NewInternal(ctx, err, "gateway: error resolving webdav reference: "+ref.Target), - }, nil + // Might be the case that the webdav token has expired. In that case, use the reference's info + info = ref } } From 475c40e6ee9da63f7c679c7058bd07deab2d5e65 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 7 Sep 2020 17:32:49 +0200 Subject: [PATCH 03/10] Forward OpenFileInAppProvider calls for OCM shares to remote reva --- internal/grpc/services/gateway/appprovider.go | 137 +++++++++++++++--- .../grpc/services/gateway/ocmshareprovider.go | 20 +-- .../grpc/services/gateway/storageprovider.go | 44 ------ .../services/gateway/webdavstorageprovider.go | 65 +++++---- 4 files changed, 159 insertions(+), 107 deletions(-) diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index 22d1706d5a..8af43a1237 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -20,15 +20,15 @@ package gateway import ( "context" - "fmt" + "net/url" + "strings" providerpb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" registry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" - provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" @@ -37,19 +37,36 @@ import ( ) func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileInAppProviderRequest) (*providerpb.OpenFileInAppProviderResponse, error) { + p, st := s.getPath(ctx, req.Ref) + if st.Code != rpc.Code_CODE_OK { + if st.Code == rpc.Code_CODE_NOT_FOUND { + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewNotFound(ctx, "gateway: file not found:"+req.Ref.String()), + }, nil + } + return &providerpb.OpenFileInAppProviderResponse{ + Status: st, + }, nil + } - accessToken, ok := tokenpkg.ContextGetToken(ctx) - if !ok || accessToken == "" { + if s.isSharedFolder(ctx, p) { return &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewUnauthenticated(ctx, errors.New("Access token is invalid or empty"), ""), + Status: status.NewInvalid(ctx, "gateway: can't open shares folder"), }, nil } - statReq := &provider.StatRequest{ - Ref: req.Ref, + resName, resChild := p, "" + if s.isShareChild(ctx, p) { + resName, resChild = s.splitShare(ctx, p) } - statRes, err := s.Stat(ctx, statReq) + statRes, err := s.stat(ctx, &storageprovider.StatRequest{ + Ref: &storageprovider.Reference{ + Spec: &storageprovider.Reference_Path{ + Path: resName, + }, + }, + }) if err != nil { return &providerpb.OpenFileInAppProviderResponse{ Status: status.NewInternal(ctx, err, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()), @@ -64,7 +81,98 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn fileInfo := statRes.Info - provider, err := s.findAppProvider(ctx, fileInfo) + // The file is a share + if fileInfo.Type == storageprovider.ResourceType_RESOURCE_TYPE_REFERENCE { + uri, err := url.Parse(fileInfo.Target) + if err != nil { + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewInternal(ctx, err, "gateway: error parsing target uri: "+fileInfo.Target), + }, nil + } + if uri.Scheme == "webdav" { + return s.openFederatedShares(ctx, fileInfo.Target, req.ViewMode, resChild) + } + + res, err := s.Stat(ctx, &storageprovider.StatRequest{ + Ref: req.Ref, + }) + if err != nil { + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewInternal(ctx, err, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()), + }, nil + } + if res.Status.Code != rpc.Code_CODE_OK { + err := status.NewErrorFromCode(res.Status.GetCode(), "gateway") + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewInternal(ctx, err, "Stat failed on the resource path for the app provider: "+req.Ref.GetPath()), + }, nil + } + fileInfo = res.Info + } + return s.openLocalResources(ctx, fileInfo, req.ViewMode) +} + +func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenFileInAppProviderRequest_ViewMode, + nameQueries ...string) (*providerpb.OpenFileInAppProviderResponse, error) { + targetURL, err := appendNameQuery(targetURL, nameQueries...) + if err != nil { + return nil, err + } + ep, err := s.extractEndpointInfo(ctx, targetURL) + if err != nil { + return nil, err + } + + ref := &storageprovider.Reference{ + Spec: &storageprovider.Reference_Path{ + Path: ep.filePath, + }, + } + appProviderReq := &gateway.OpenFileInAppProviderRequest{ + Ref: ref, + ViewMode: vm, + } + + meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ + Domain: ep.endpoint, + }) + if err != nil { + return nil, errors.Wrap(err, "gateway: error calling GetInfoByDomain") + } + var gatewayEP string + for _, s := range meshProvider.ProviderInfo.Services { + if strings.ToLower(s.Endpoint.Type.Name) == "gateway" { + gatewayEP = s.Endpoint.Path + } + } + + gatewayClient, err := pool.GetGatewayServiceClient(gatewayEP) + if err != nil { + err = errors.Wrap(err, "gateway: error calling GetGatewayClient") + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewInternal(ctx, err, "error getting gateway client"), + }, nil + } + + ctx = tokenpkg.ContextSetToken(ctx, ep.token) + res, err := gatewayClient.OpenFileInAppProvider(ctx, appProviderReq) + if err != nil { + return nil, errors.Wrap(err, "gateway: error calling OpenFileInAppProvider") + } + return res, nil +} + +func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo, + vm gateway.OpenFileInAppProviderRequest_ViewMode) (*providerpb.OpenFileInAppProviderResponse, error) { + + accessToken, ok := tokenpkg.ContextGetToken(ctx) + if !ok || accessToken == "" { + return &providerpb.OpenFileInAppProviderResponse{ + Status: status.NewUnauthenticated(ctx, errors.New("Access token is invalid or empty"), ""), + }, nil + } + + provider, err := s.findAppProvider(ctx, ri) if err != nil { err = errors.Wrap(err, "gateway: error calling findAppProvider") var st *rpc.Status @@ -86,14 +194,9 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn }, nil } - // build the appProvider specific request with the required extra info that has been obtained - - log := appctx.GetLogger(ctx) - log.Debug().Msg(fmt.Sprintf("request: %s", req)) - appProviderReq := &providerpb.OpenFileInAppProviderRequest{ - ResourceInfo: fileInfo, - ViewMode: providerpb.OpenFileInAppProviderRequest_ViewMode(req.ViewMode), + ResourceInfo: ri, + ViewMode: providerpb.OpenFileInAppProviderRequest_ViewMode(vm), AccessToken: accessToken, } diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go index 5cdb7e70d2..3063d40247 100644 --- a/internal/grpc/services/gateway/ocmshareprovider.go +++ b/internal/grpc/services/gateway/ocmshareprovider.go @@ -22,9 +22,7 @@ import ( "context" "fmt" "path" - "strings" - ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -288,20 +286,6 @@ func (s *svc) createWebdavReference(ctx context.Context, share *ocm.Share) (*rpc log := appctx.GetLogger(ctx) - meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ - Domain: share.Creator.Idp, - }) - if err != nil { - err := errors.Wrap(err, "gateway: error calling GetInfoByDomain") - return status.NewInternal(ctx, err, "error updating received share"), nil - } - var webdavEndpoint string - for _, s := range meshProvider.ProviderInfo.Services { - if strings.ToLower(s.Endpoint.Type.Name) == "webdav" { - webdavEndpoint = s.Endpoint.Path - } - } - var token string tokenOpaque, ok := share.Grantee.Opaque.Map["token"] if !ok { @@ -330,8 +314,8 @@ func (s *svc) createWebdavReference(ctx context.Context, share *ocm.Share) (*rpc createRefReq := &provider.CreateReferenceRequest{ Path: refPath, - // webdav is the scheme, token@webdav_endpoint the opaque part and the share name the query of the URL. - TargetUri: fmt.Sprintf("webdav:%s@%s?name=%s", token, webdavEndpoint, share.Name), + // webdav is the scheme, token@host the opaque part and the share name the query of the URL. + TargetUri: fmt.Sprintf("webdav://%s@%s?name=%s", token, share.Creator.Idp, share.Name), } c, err := s.findByPath(ctx, refPath) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 128c5cc6e5..1a557a54df 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -182,14 +182,6 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info)) - log.Err(err).Msg("gateway: error creating container") - return &gateway.InitiateFileDownloadResponse{ - Status: status.NewInternal(ctx, err, "gateway: error creating container"), - }, nil - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { @@ -347,14 +339,6 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info)) - log.Err(err).Msg("gateway: error creating container") - return &gateway.InitiateFileUploadResponse{ - Status: status.NewInternal(ctx, err, "gateway: error uploading"), - }, nil - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { @@ -558,14 +542,6 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info)) - log.Err(err).Msg("gateway: error creating container") - return &provider.CreateContainerResponse{ - Status: status.NewInternal(ctx, err, "gateway: error creating container"), - }, nil - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { @@ -706,14 +682,6 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info)) - log.Err(err).Msg("gateway: error deleting") - return &provider.DeleteResponse{ - Status: status.NewInternal(ctx, err, "gateway: error deleting"), - }, nil - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { @@ -849,14 +817,6 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info)) - log.Err(err).Msg("gateway: error deleting") - return &provider.MoveResponse{ - Status: status.NewInternal(ctx, err, "gateway: error deleting"), - }, nil - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { @@ -1052,10 +1012,6 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St }, nil } - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE { - panic("gateway: a share name must be of type reference: ref:" + statRes.Info.Path) - } - ri, protocol, err := s.checkRef(ctx, statRes.Info) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { diff --git a/internal/grpc/services/gateway/webdavstorageprovider.go b/internal/grpc/services/gateway/webdavstorageprovider.go index 5c27014571..a4e5a9e3b3 100644 --- a/internal/grpc/services/gateway/webdavstorageprovider.go +++ b/internal/grpc/services/gateway/webdavstorageprovider.go @@ -25,6 +25,7 @@ import ( "path" "strings" + ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/errtypes" @@ -45,7 +46,7 @@ func (s *svc) webdavRefStat(ctx context.Context, targetURL string, nameQueries . return nil, err } - ep, err := extractEndpointInfo(targetURL) + ep, err := s.extractEndpointInfo(ctx, targetURL) if err != nil { return nil, err } @@ -67,7 +68,7 @@ func (s *svc) webdavRefLs(ctx context.Context, targetURL string, nameQueries ... return nil, err } - ep, err := extractEndpointInfo(targetURL) + ep, err := s.extractEndpointInfo(ctx, targetURL) if err != nil { return nil, err } @@ -95,7 +96,7 @@ func (s *svc) webdavRefMkdir(ctx context.Context, targetURL string, nameQueries return err } - ep, err := extractEndpointInfo(targetURL) + ep, err := s.extractEndpointInfo(ctx, targetURL) if err != nil { return err } @@ -114,7 +115,7 @@ func (s *svc) webdavRefMove(ctx context.Context, targetURL, src, destination str if err != nil { return err } - srcEP, err := extractEndpointInfo(srcURL) + srcEP, err := s.extractEndpointInfo(ctx, srcURL) if err != nil { return err } @@ -123,7 +124,7 @@ func (s *svc) webdavRefMove(ctx context.Context, targetURL, src, destination str if err != nil { return err } - destEP, err := extractEndpointInfo(destURL) + destEP, err := s.extractEndpointInfo(ctx, destURL) if err != nil { return err } @@ -144,7 +145,7 @@ func (s *svc) webdavRefDelete(ctx context.Context, targetURL string, nameQueries return err } - ep, err := extractEndpointInfo(targetURL) + ep, err := s.extractEndpointInfo(ctx, targetURL) if err != nil { return err } @@ -164,7 +165,7 @@ func (s *svc) webdavRefTransferEndpoint(ctx context.Context, targetURL string, n return "", nil, err } - ep, err := extractEndpointInfo(targetURL) + ep, err := s.extractEndpointInfo(ctx, targetURL) if err != nil { return "", nil, err } @@ -183,21 +184,7 @@ func (s *svc) webdavRefTransferEndpoint(ctx context.Context, targetURL string, n }, nil } -func normalize(info *gowebdav.File) *provider.ResourceInfo { - return &provider.ResourceInfo{ - // TODO(ishank011): Add Id, PermissionSet, Owner - Path: info.Path(), - Type: getResourceType(info.IsDir()), - Etag: info.ETag(), - MimeType: info.ContentType(), - Size: uint64(info.Size()), - Mtime: &types.Timestamp{ - Seconds: uint64(info.ModTime().Unix()), - }, - } -} - -func extractEndpointInfo(targetURL string) (*webdavEndpoint, error) { +func (s *svc) extractEndpointInfo(ctx context.Context, targetURL string) (*webdavEndpoint, error) { if targetURL == "" { return nil, errors.New("gateway: ref target is an empty uri") } @@ -210,11 +197,19 @@ func extractEndpointInfo(targetURL string) (*webdavEndpoint, error) { return nil, errtypes.NotSupported("ref target does not have the webdav scheme") } - parts := strings.SplitN(uri.Opaque, "@", 2) - if len(parts) < 2 { - err := errors.New("gateway: webdav ref does not follow the layout token@webdav_endpoint?name " + targetURL) - return nil, err + meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ + Domain: uri.Host, + }) + if err != nil { + return nil, errors.Wrap(err, "gateway: error calling GetInfoByDomain") } + var webdavEP string + for _, s := range meshProvider.ProviderInfo.Services { + if strings.ToLower(s.Endpoint.Type.Name) == "webdav" { + webdavEP = s.Endpoint.Path + } + } + m, err := url.ParseQuery(uri.RawQuery) if err != nil { return nil, errors.Wrap(err, "gateway: error parsing target resource name") @@ -222,11 +217,25 @@ func extractEndpointInfo(targetURL string) (*webdavEndpoint, error) { return &webdavEndpoint{ filePath: m["name"][0], - endpoint: parts[1], - token: parts[0], + endpoint: webdavEP, + token: uri.User.String(), }, nil } +func normalize(info *gowebdav.File) *provider.ResourceInfo { + return &provider.ResourceInfo{ + // TODO(ishank011): Add Id, PermissionSet, Owner + Path: info.Path(), + Type: getResourceType(info.IsDir()), + Etag: info.ETag(), + MimeType: info.ContentType(), + Size: uint64(info.Size()), + Mtime: &types.Timestamp{ + Seconds: uint64(info.ModTime().Unix()), + }, + } +} + func getResourceType(isDir bool) provider.ResourceType { if isDir { return provider.ResourceType_RESOURCE_TYPE_CONTAINER From 67c6c9d6ee1e822d9e2efe40ad3445bd0bdbd598 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 7 Sep 2020 18:11:23 +0200 Subject: [PATCH 04/10] Return host from extractEndpointInfo --- .../services/gateway/webdavstorageprovider.go | 80 +++++++++++++------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/internal/grpc/services/gateway/webdavstorageprovider.go b/internal/grpc/services/gateway/webdavstorageprovider.go index a4e5a9e3b3..161ed3e069 100644 --- a/internal/grpc/services/gateway/webdavstorageprovider.go +++ b/internal/grpc/services/gateway/webdavstorageprovider.go @@ -50,14 +50,19 @@ func (s *svc) webdavRefStat(ctx context.Context, targetURL string, nameQueries . if err != nil { return nil, err } - c := gowebdav.NewClient(ep.endpoint, "", "") + webdavEP, err := s.getWebdavEndpoint(ctx, ep.endpoint) + if err != nil { + return nil, err + } + + c := gowebdav.NewClient(webdavEP, "", "") c.SetHeader(token.TokenHeader, ep.token) // TODO(ishank011): We need to call PROPFIND ourselves as we need to retrieve // ownloud-specific fields to get the resource ID and permissions. info, err := c.Stat(ep.filePath) if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("gateway: error statting %s at the webdav endpoint: %s", ep.filePath, ep.endpoint)) + return nil, errors.Wrap(err, fmt.Sprintf("gateway: error statting %s at the webdav endpoint: %s", ep.filePath, webdavEP)) } return normalize(info.(*gowebdav.File)), nil } @@ -72,14 +77,19 @@ func (s *svc) webdavRefLs(ctx context.Context, targetURL string, nameQueries ... if err != nil { return nil, err } - c := gowebdav.NewClient(ep.endpoint, "", "") + webdavEP, err := s.getWebdavEndpoint(ctx, ep.endpoint) + if err != nil { + return nil, err + } + + c := gowebdav.NewClient(webdavEP, "", "") c.SetHeader(token.TokenHeader, ep.token) // TODO(ishank011): We need to call PROPFIND ourselves as we need to retrieve // ownloud-specific fields to get the resource ID and permissions. infos, err := c.ReadDir(ep.filePath) if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("gateway: error listing %s at the webdav endpoint: %s", ep.filePath, ep.endpoint)) + return nil, errors.Wrap(err, fmt.Sprintf("gateway: error listing %s at the webdav endpoint: %s", ep.filePath, webdavEP)) } mds := []*provider.ResourceInfo{} @@ -100,12 +110,17 @@ func (s *svc) webdavRefMkdir(ctx context.Context, targetURL string, nameQueries if err != nil { return err } - c := gowebdav.NewClient(ep.endpoint, "", "") + webdavEP, err := s.getWebdavEndpoint(ctx, ep.endpoint) + if err != nil { + return err + } + + c := gowebdav.NewClient(webdavEP, "", "") c.SetHeader(token.TokenHeader, ep.token) err = c.Mkdir(ep.filePath, 0700) if err != nil { - return errors.Wrap(err, fmt.Sprintf("gateway: error creating dir %s at the webdav endpoint: %s", ep.filePath, ep.endpoint)) + return errors.Wrap(err, fmt.Sprintf("gateway: error creating dir %s at the webdav endpoint: %s", ep.filePath, webdavEP)) } return nil } @@ -119,6 +134,10 @@ func (s *svc) webdavRefMove(ctx context.Context, targetURL, src, destination str if err != nil { return err } + srcWebdavEP, err := s.getWebdavEndpoint(ctx, srcEP.endpoint) + if err != nil { + return err + } destURL, err := appendNameQuery(targetURL, destination) if err != nil { @@ -129,12 +148,12 @@ func (s *svc) webdavRefMove(ctx context.Context, targetURL, src, destination str return err } - c := gowebdav.NewClient(srcEP.endpoint, "", "") + c := gowebdav.NewClient(srcWebdavEP, "", "") c.SetHeader(token.TokenHeader, srcEP.token) err = c.Rename(srcEP.filePath, destEP.filePath, true) if err != nil { - return errors.Wrap(err, fmt.Sprintf("gateway: error renaming %s to %s at the webdav endpoint: %s", srcEP.filePath, destEP.filePath, srcEP.endpoint)) + return errors.Wrap(err, fmt.Sprintf("gateway: error renaming %s to %s at the webdav endpoint: %s", srcEP.filePath, destEP.filePath, srcWebdavEP)) } return nil } @@ -149,12 +168,17 @@ func (s *svc) webdavRefDelete(ctx context.Context, targetURL string, nameQueries if err != nil { return err } - c := gowebdav.NewClient(ep.endpoint, "", "") + webdavEP, err := s.getWebdavEndpoint(ctx, ep.endpoint) + if err != nil { + return err + } + + c := gowebdav.NewClient(webdavEP, "", "") c.SetHeader(token.TokenHeader, ep.token) err = c.Remove(ep.filePath) if err != nil { - return errors.Wrap(err, fmt.Sprintf("gateway: error removing %s at the webdav endpoint: %s", ep.filePath, ep.endpoint)) + return errors.Wrap(err, fmt.Sprintf("gateway: error removing %s at the webdav endpoint: %s", ep.filePath, webdavEP)) } return nil } @@ -169,8 +193,12 @@ func (s *svc) webdavRefTransferEndpoint(ctx context.Context, targetURL string, n if err != nil { return "", nil, err } + webdavEP, err := s.getWebdavEndpoint(ctx, ep.endpoint) + if err != nil { + return "", nil, err + } - return ep.endpoint, &types.Opaque{ + return webdavEP, &types.Opaque{ Map: map[string]*types.OpaqueEntry{ "webdav-file-path": { Decoder: "plain", @@ -197,19 +225,6 @@ func (s *svc) extractEndpointInfo(ctx context.Context, targetURL string) (*webda return nil, errtypes.NotSupported("ref target does not have the webdav scheme") } - meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ - Domain: uri.Host, - }) - if err != nil { - return nil, errors.Wrap(err, "gateway: error calling GetInfoByDomain") - } - var webdavEP string - for _, s := range meshProvider.ProviderInfo.Services { - if strings.ToLower(s.Endpoint.Type.Name) == "webdav" { - webdavEP = s.Endpoint.Path - } - } - m, err := url.ParseQuery(uri.RawQuery) if err != nil { return nil, errors.Wrap(err, "gateway: error parsing target resource name") @@ -217,11 +232,26 @@ func (s *svc) extractEndpointInfo(ctx context.Context, targetURL string) (*webda return &webdavEndpoint{ filePath: m["name"][0], - endpoint: webdavEP, + endpoint: uri.Host, token: uri.User.String(), }, nil } +func (s *svc) getWebdavEndpoint(ctx context.Context, domain string) (string, error) { + meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ + Domain: domain, + }) + if err != nil { + return "", errors.Wrap(err, "gateway: error calling GetInfoByDomain") + } + for _, s := range meshProvider.ProviderInfo.Services { + if strings.ToLower(s.Endpoint.Type.Name) == "webdav" { + return s.Endpoint.Path, nil + } + } + return "", errtypes.NotFound(domain) +} + func normalize(info *gowebdav.File) *provider.ResourceInfo { return &provider.ResourceInfo{ // TODO(ishank011): Add Id, PermissionSet, Owner From 9aefc0913290b22068340403b3630185172c3c18 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 7 Sep 2020 19:21:29 +0200 Subject: [PATCH 05/10] Add token to grpc metadata --- examples/ocmd/providers.demo.json | 52 +++++++++++++++++++ internal/grpc/services/gateway/appprovider.go | 10 ++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/examples/ocmd/providers.demo.json b/examples/ocmd/providers.demo.json index 79e82355e1..05aa6c78d3 100644 --- a/examples/ocmd/providers.demo.json +++ b/examples/ocmd/providers.demo.json @@ -32,6 +32,19 @@ }, "api_version": "0.0.1", "host": "http://127.0.0.1:19001/" + }, + { + "endpoint": { + "type": { + "name": "Gateway", + "description": "CERNBox GRPC Gateway" + }, + "name": "CERNBox - GRPC Gateway", + "path": "127.0.0.1:19000", + "is_monitored": true + }, + "api_version": "0.0.1", + "host": "127.0.0.1:19000" } ] }, @@ -68,6 +81,19 @@ }, "api_version": "0.0.1", "host": "http://127.0.0.1:17001/" + }, + { + "endpoint": { + "type": { + "name": "Gateway", + "description": "CESNET GRPC Gateway" + }, + "name": "CESNET - GRPC Gateway", + "path": "127.0.0.1:17000", + "is_monitored": true + }, + "api_version": "0.0.1", + "host": "127.0.0.1:17000" } ] }, @@ -104,6 +130,19 @@ }, "api_version": "0.0.1", "host": "http://127.0.0.1:19001/" + }, + { + "endpoint": { + "type": { + "name": "Gateway", + "description": "Example GRPC Gateway" + }, + "name": "Example - GRPC Gateway", + "path": "127.0.0.1:19000", + "is_monitored": true + }, + "api_version": "0.0.1", + "host": "127.0.0.1:19000" } ] }, @@ -140,6 +179,19 @@ }, "api_version": "0.0.1", "host": "http://127.0.0.1:19001/" + }, + { + "endpoint": { + "type": { + "name": "Gateway", + "description": "Test GRPC Gateway" + }, + "name": "Test - GRPC Gateway", + "path": "127.0.0.1:19000", + "is_monitored": true + }, + "api_version": "0.0.1", + "host": "127.0.0.1:19000" } ] } diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index 8af43a1237..c59e703d9f 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -32,8 +32,9 @@ import ( "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" - tokenpkg "github.com/cs3org/reva/pkg/token" + "github.com/cs3org/reva/pkg/token" "github.com/pkg/errors" + "google.golang.org/grpc/metadata" ) func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileInAppProviderRequest) (*providerpb.OpenFileInAppProviderResponse, error) { @@ -154,8 +155,9 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate }, nil } - ctx = tokenpkg.ContextSetToken(ctx, ep.token) - res, err := gatewayClient.OpenFileInAppProvider(ctx, appProviderReq) + remoteCtx := token.ContextSetToken(context.Background(), ep.token) + remoteCtx = metadata.AppendToOutgoingContext(remoteCtx, token.TokenHeader, ep.token) + res, err := gatewayClient.OpenFileInAppProvider(remoteCtx, appProviderReq) if err != nil { return nil, errors.Wrap(err, "gateway: error calling OpenFileInAppProvider") } @@ -165,7 +167,7 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo, vm gateway.OpenFileInAppProviderRequest_ViewMode) (*providerpb.OpenFileInAppProviderResponse, error) { - accessToken, ok := tokenpkg.ContextGetToken(ctx) + accessToken, ok := token.ContextGetToken(ctx) if !ok || accessToken == "" { return &providerpb.OpenFileInAppProviderResponse{ Status: status.NewUnauthenticated(ctx, errors.New("Access token is invalid or empty"), ""), From 809b91d2757ece1c53b55a7bd8ada3025a87eed9 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 8 Sep 2020 13:49:34 +0200 Subject: [PATCH 06/10] Don't overwrite directories when uploading --- cmd/reva/configure.go | 4 ++-- internal/grpc/services/storageprovider/storageprovider.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/reva/configure.go b/cmd/reva/configure.go index 04b009299a..0795a84daa 100644 --- a/cmd/reva/configure.go +++ b/cmd/reva/configure.go @@ -36,8 +36,8 @@ var configureCommand = func() *command { return err } - c := &config{Host: text} - if err := writeConfig(c); err != nil { + conf = &config{Host: text} + if err := writeConfig(conf); err != nil { return err } fmt.Println("config saved at ", getConfigFile()) diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 845f7a0e71..321706f7a2 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -275,7 +275,7 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate } if newRef.GetPath() == "/" { return &provider.InitiateFileUploadResponse{ - Status: status.NewInternal(ctx, errors.New("can't upload to mount path"), ""), + Status: status.NewInternal(ctx, errors.New("can't upload to mount path"), "can't upload to mount path"), }, nil } url := *s.dataServerURL @@ -401,6 +401,11 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro Status: status.NewInternal(ctx, err, "error unwrapping path"), }, nil } + if newRef.GetPath() == "/" { + return &provider.DeleteResponse{ + Status: status.NewInternal(ctx, errors.New("can't delete mount path"), "can't delete mount path"), + }, nil + } if err := s.storage.Delete(ctx, newRef); err != nil { var st *rpc.Status From 08924fe8835b94d201bc77b92db74c52be44eb8a Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 8 Sep 2020 16:53:27 +0200 Subject: [PATCH 07/10] Use secure GRPC connection for call to remote reva --- internal/grpc/services/gateway/appprovider.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index c59e703d9f..01b8f27fa8 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -29,11 +29,13 @@ import ( ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" "github.com/pkg/errors" + "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -115,6 +117,7 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenFileInAppProviderRequest_ViewMode, nameQueries ...string) (*providerpb.OpenFileInAppProviderResponse, error) { + log := appctx.GetLogger(ctx) targetURL, err := appendNameQuery(targetURL, nameQueries...) if err != nil { return nil, err @@ -146,19 +149,22 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate gatewayEP = s.Endpoint.Path } } + log.Debug().Msgf("Forwarding OpenFileInAppProvider request to: %s", gatewayEP) - gatewayClient, err := pool.GetGatewayServiceClient(gatewayEP) + conn, err := grpc.Dial(gatewayEP) if err != nil { - err = errors.Wrap(err, "gateway: error calling GetGatewayClient") + err = errors.Wrap(err, "gateway: error connecting to remote reva") return &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewInternal(ctx, err, "error getting gateway client"), + Status: status.NewInternal(ctx, err, "error error connecting to remote reva"), }, nil } + gatewayClient := gateway.NewGatewayAPIClient(conn) remoteCtx := token.ContextSetToken(context.Background(), ep.token) remoteCtx = metadata.AppendToOutgoingContext(remoteCtx, token.TokenHeader, ep.token) res, err := gatewayClient.OpenFileInAppProvider(remoteCtx, appProviderReq) if err != nil { + log.Err(err).Msg("error reaching remote reva") return nil, errors.Wrap(err, "gateway: error calling OpenFileInAppProvider") } return res, nil From 601ab720b805240ba7ff7b02b7caf4347c503c70 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 8 Sep 2020 19:06:59 +0200 Subject: [PATCH 08/10] Add options for insecure conns and skipping cert check for GRPC --- cmd/reva/main.go | 4 +-- cmd/reva/open-file-in-app-provider.go | 17 +++++++++- internal/grpc/services/gateway/appprovider.go | 34 ++++++++++++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/cmd/reva/main.go b/cmd/reva/main.go index ae85318b09..992c5cfee1 100644 --- a/cmd/reva/main.go +++ b/cmd/reva/main.go @@ -75,8 +75,8 @@ var ( func init() { flag.StringVar(&host, "host", "", "address of the GRPC gateway host") flag.BoolVar(&insecure, "insecure", false, "disables grpc transport security") - flag.BoolVar(&skipverify, "skip-verify", false, "whether a client verifies the server's certificate chain and host name.") - flag.BoolVar(&disableargprompt, "disable-arg-prompt", false, "whether to disable prompts for command arguments.") + flag.BoolVar(&skipverify, "skip-verify", false, "whether to skip verifying the server's certificate chain and host name") + flag.BoolVar(&disableargprompt, "disable-arg-prompt", false, "whether to disable prompts for command arguments") flag.IntVar(&timeout, "timout", -1, "the timeout in seconds for executing the commands, -1 means no timeout") flag.Parse() } diff --git a/cmd/reva/open-file-in-app-provider.go b/cmd/reva/open-file-in-app-provider.go index 0a04dd9a76..9c23f53e7e 100644 --- a/cmd/reva/open-file-in-app-provider.go +++ b/cmd/reva/open-file-in-app-provider.go @@ -25,6 +25,7 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/pkg/errors" ) @@ -35,9 +36,13 @@ func openFileInAppProviderCommand() *command { return "Usage: open-file-in-app-provider [-flags] [-viewmode view|read|write] " } viewMode := cmd.String("viewmode", "view", "the view permissions, defaults to view") + insecureFlag := cmd.Bool("insecure", false, "disables grpc transport security") + skipVerifyFlag := cmd.Bool("skip-verify", false, "whether to skip verifying remote reva's certificate chain and host name") cmd.ResetFlags = func() { *viewMode = "view" + *insecureFlag = false + *skipVerifyFlag = false } cmd.Action = func(w ...io.Writer) error { @@ -58,7 +63,17 @@ func openFileInAppProviderCommand() *command { Spec: &provider.Reference_Path{Path: path}, } - openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: vm} + opaqueObj := &typespb.Opaque{ + Map: map[string]*typespb.OpaqueEntry{}, + } + if *insecureFlag { + opaqueObj.Map["insecure"] = &typespb.OpaqueEntry{} + } + if *skipVerifyFlag { + opaqueObj.Map["skip-verify"] = &typespb.OpaqueEntry{} + } + + openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: vm, Opaque: opaqueObj} openRes, err := client.OpenFileInAppProvider(ctx, openRequest) if err != nil { diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index 01b8f27fa8..57e98453e2 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -20,6 +20,7 @@ package gateway import ( "context" + "crypto/tls" "net/url" "strings" @@ -29,6 +30,7 @@ import ( ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/status" @@ -36,6 +38,7 @@ import ( "github.com/cs3org/reva/pkg/token" "github.com/pkg/errors" "google.golang.org/grpc" + "google.golang.org/grpc/credentials" "google.golang.org/grpc/metadata" ) @@ -93,7 +96,8 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn }, nil } if uri.Scheme == "webdav" { - return s.openFederatedShares(ctx, fileInfo.Target, req.ViewMode, resChild) + insecure, skipVerify := getGRPCConfig(req.Opaque) + return s.openFederatedShares(ctx, fileInfo.Target, req.ViewMode, insecure, skipVerify, resChild) } res, err := s.Stat(ctx, &storageprovider.StatRequest{ @@ -116,7 +120,7 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn } func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenFileInAppProviderRequest_ViewMode, - nameQueries ...string) (*providerpb.OpenFileInAppProviderResponse, error) { + insecure, skipVerify bool, nameQueries ...string) (*providerpb.OpenFileInAppProviderResponse, error) { log := appctx.GetLogger(ctx) targetURL, err := appendNameQuery(targetURL, nameQueries...) if err != nil { @@ -151,17 +155,18 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate } log.Debug().Msgf("Forwarding OpenFileInAppProvider request to: %s", gatewayEP) - conn, err := grpc.Dial(gatewayEP) + conn, err := getConn(gatewayEP, insecure, skipVerify) if err != nil { err = errors.Wrap(err, "gateway: error connecting to remote reva") return &providerpb.OpenFileInAppProviderResponse{ Status: status.NewInternal(ctx, err, "error error connecting to remote reva"), }, nil } - gatewayClient := gateway.NewGatewayAPIClient(conn) + gatewayClient := gateway.NewGatewayAPIClient(conn) remoteCtx := token.ContextSetToken(context.Background(), ep.token) remoteCtx = metadata.AppendToOutgoingContext(remoteCtx, token.TokenHeader, ep.token) + res, err := gatewayClient.OpenFileInAppProvider(remoteCtx, appProviderReq) if err != nil { log.Err(err).Msg("error reaching remote reva") @@ -243,3 +248,24 @@ func (s *svc) findAppProvider(ctx context.Context, ri *storageprovider.ResourceI return nil, errors.New("gateway: error finding a storage provider") } + +func getGRPCConfig(opaque *typespb.Opaque) (bool, bool) { + if opaque == nil { + return false, false + } + _, insecure := opaque.Map["insecure"] + _, skipVerify := opaque.Map["skip-verify"] + return insecure, skipVerify +} + +func getConn(host string, insecure, skipverify bool) (*grpc.ClientConn, error) { + if insecure { + return grpc.Dial(host, grpc.WithInsecure()) + } + + // TODO(labkode): if in the future we want client-side certificate validation, + // we need to load the client cert here + tlsconf := &tls.Config{InsecureSkipVerify: skipverify} + creds := credentials.NewTLS(tlsconf) + return grpc.Dial(host, grpc.WithTransportCredentials(creds)) +} From 52919704656da8c5bc4466bb4d3fd95b55be9a19 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 15 Sep 2020 11:35:27 +0200 Subject: [PATCH 09/10] Fix error formatting --- .../en/docs/config/grpc/services/appprovider/_index.md | 5 ++--- go.sum | 1 + internal/grpc/services/appprovider/appprovider.go | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/content/en/docs/config/grpc/services/appprovider/_index.md b/docs/content/en/docs/config/grpc/services/appprovider/_index.md index 2e892a3851..beb9ef8ea5 100644 --- a/docs/content/en/docs/config/grpc/services/appprovider/_index.md +++ b/docs/content/en/docs/config/grpc/services/appprovider/_index.md @@ -9,7 +9,7 @@ description: > # _struct: config_ {{% dir name="iopsecret" type="string" default="" %}} -The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L60) +The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L57) {{< highlight toml >}} [grpc.services.appprovider] iopsecret = "" @@ -17,10 +17,9 @@ iopsecret = "" {{% /dir %}} {{% dir name="wopiurl" type="string" default="" %}} -The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61) +The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L58) {{< highlight toml >}} [grpc.services.appprovider] wopiurl = "" {{< /highlight >}} {{% /dir %}} - diff --git a/go.sum b/go.sum index 03faf26194..2e64be9143 100644 --- a/go.sum +++ b/go.sum @@ -892,6 +892,7 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index 993180caf7..a3bc5463bb 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -22,14 +22,12 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "io/ioutil" "net/http" "net/url" "os" "path" - "strconv" "strings" "time" @@ -135,7 +133,7 @@ func (s *service) getWopiAppEndpoints(ctx context.Context) (map[string]interface } defer appsRes.Body.Close() if appsRes.StatusCode != http.StatusOK { - return nil, errors.New("Request to WOPI server returned " + string(appsRes.StatusCode)) + return nil, fmt.Errorf("Request to WOPI server returned %d", appsRes.StatusCode) } appsBody, err := ioutil.ReadAll(appsRes.Body) if err != nil { @@ -207,7 +205,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope if openRes.StatusCode != http.StatusOK { res := &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewInvalid(ctx, "appprovider: error performing open request to WOPI, status code: "+strconv.Itoa(openRes.StatusCode)), + Status: status.NewInvalid(ctx, fmt.Sprintf("appprovider: error performing open request to WOPI, status code: %d", openRes.StatusCode)), } return res, nil } From d6fd596a5feee4110d0bb13a5834b6975c8d00ee Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Wed, 16 Sep 2020 11:11:53 +0200 Subject: [PATCH 10/10] Run cato --- .../en/docs/config/grpc/services/appprovider/_index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/content/en/docs/config/grpc/services/appprovider/_index.md b/docs/content/en/docs/config/grpc/services/appprovider/_index.md index beb9ef8ea5..69b18917b6 100644 --- a/docs/content/en/docs/config/grpc/services/appprovider/_index.md +++ b/docs/content/en/docs/config/grpc/services/appprovider/_index.md @@ -9,7 +9,7 @@ description: > # _struct: config_ {{% dir name="iopsecret" type="string" default="" %}} -The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L57) +The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L58) {{< highlight toml >}} [grpc.services.appprovider] iopsecret = "" @@ -17,9 +17,10 @@ iopsecret = "" {{% /dir %}} {{% dir name="wopiurl" type="string" default="" %}} -The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L58) +The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L59) {{< highlight toml >}} [grpc.services.appprovider] wopiurl = "" {{< /highlight >}} {{% /dir %}} +