diff --git a/changelog/unreleased/collaboration-gateway-selector.md b/changelog/unreleased/collaboration-gateway-selector.md new file mode 100644 index 000000000..c58869813 --- /dev/null +++ b/changelog/unreleased/collaboration-gateway-selector.md @@ -0,0 +1,3 @@ +Bugfix: Make collaboration service use a gateway selector + +https://github.com/owncloud/ocis/pull/10584 diff --git a/services/collaboration/pkg/service/grpc/v0/option.go b/services/collaboration/pkg/service/grpc/v0/option.go index 2fafbee81..c2e5e70c8 100644 --- a/services/collaboration/pkg/service/grpc/v0/option.go +++ b/services/collaboration/pkg/service/grpc/v0/option.go @@ -2,9 +2,11 @@ package service import ( gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" - microstore "go-micro.dev/v4/store" ) // Option defines a single option function. @@ -12,11 +14,11 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { - Logger log.Logger - Config *config.Config - AppURLs map[string]map[string]string - Gwc gatewayv1beta1.GatewayAPIClient - Store microstore.Store + Logger log.Logger + Config *config.Config + AppURLs map[string]map[string]string + GatewaySelector pool.Selectable[gatewayv1beta1.GatewayAPIClient] + Store microstore.Store } // newOptions initializes the available default options. @@ -51,10 +53,10 @@ func AppURLs(val map[string]map[string]string) Option { } } -// GatewayAPIClient provides a function to set the GatewayAPIClient option. -func GatewayAPIClient(val gatewayv1beta1.GatewayAPIClient) Option { +// GatewaySelector provides a function to set the GatewaySelector option. +func GatewaySelector(val pool.Selectable[gatewayv1beta1.GatewayAPIClient]) Option { return func(o *Options) { - o.Gwc = val + o.GatewaySelector = val } } diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index 74e12be13..f1b3ae1b9 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -16,13 +16,13 @@ import ( "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" - "github.com/owncloud/ocis/v2/services/collaboration/pkg/wopisrc" + microstore "go-micro.dev/v4/store" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" "github.com/owncloud/ocis/v2/services/collaboration/pkg/helpers" "github.com/owncloud/ocis/v2/services/collaboration/pkg/middleware" - microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/services/collaboration/pkg/wopisrc" ) // NewHandler creates a new grpc service implementing the OpenInApp interface @@ -33,33 +33,33 @@ func NewHandler(opts ...Option) (*Service, func(), error) { } options := newOptions(opts...) - gwc := options.Gwc + gatewaySelector := options.GatewaySelector var err error - if gwc == nil { - gwc, err = pool.GetGatewayServiceClient(options.Config.CS3Api.Gateway.Name) + if gatewaySelector == nil { + gatewaySelector, err = pool.GatewaySelector(options.Config.CS3Api.Gateway.Name) if err != nil { return nil, teardown, err } } return &Service{ - id: options.Config.GRPC.Namespace + "." + options.Config.Service.Name + "." + options.Config.App.Name, - appURLs: options.AppURLs, - logger: options.Logger, - config: options.Config, - gwc: gwc, - store: options.Store, + id: options.Config.GRPC.Namespace + "." + options.Config.Service.Name + "." + options.Config.App.Name, + appURLs: options.AppURLs, + logger: options.Logger, + config: options.Config, + gatewaySelector: gatewaySelector, + store: options.Store, }, teardown, nil } // Service implements the OpenInApp interface type Service struct { - id string - appURLs map[string]map[string]string - logger log.Logger - config *config.Config - gwc gatewayv1beta1.GatewayAPIClient - store microstore.Store + id string + appURLs map[string]map[string]string + logger log.Logger + config *config.Config + gatewaySelector pool.Selectable[gatewayv1beta1.GatewayAPIClient] + store microstore.Store } // OpenInApp will implement the OpenInApp interface of the app provider @@ -73,7 +73,13 @@ func (s *Service) OpenInApp( meReq := &gatewayv1beta1.WhoAmIRequest{ Token: req.GetAccessToken(), } - meResp, err := s.gwc.WhoAmI(ctx, meReq) + gwc, err := s.gatewaySelector.Next() + if err != nil { + s.logger.Error().Err(err).Msg("OpenInApp: could not select a gateway client") + return nil, err + } + + meResp, err := gwc.WhoAmI(ctx, meReq) if err == nil { if meResp.GetStatus().GetCode() == rpcv1beta1.Code_CODE_OK { user = meResp.GetUser() diff --git a/services/collaboration/pkg/service/grpc/v0/service_test.go b/services/collaboration/pkg/service/grpc/v0/service_test.go index 1c2359ad8..414c45ed8 100644 --- a/services/collaboration/pkg/service/grpc/v0/service_test.go +++ b/services/collaboration/pkg/service/grpc/v0/service_test.go @@ -5,12 +5,6 @@ import ( "strconv" "time" - "github.com/cs3org/reva/v2/pkg/utils" - "github.com/golang-jwt/jwt/v5" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/stretchr/testify/mock" - appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" @@ -18,10 +12,16 @@ import ( rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/v2/pkg/rgrpc/status" + "github.com/cs3org/reva/v2/pkg/utils" cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" + "github.com/golang-jwt/jwt/v5" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/stretchr/testify/mock" + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/collaboration/mocks" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" service "github.com/owncloud/ocis/v2/services/collaboration/pkg/service/grpc/v0" ) @@ -77,23 +77,26 @@ var _ = Describe("Discovery", func() { cfg = &config.Config{} gatewayClient = &cs3mocks.GatewayAPIClient{} + gatewaySelector := mocks.NewSelectable[gatewayv1beta1.GatewayAPIClient](GinkgoT()) + gatewaySelector.On("Next").Return(gatewayClient, nil) + srv, srvTear, _ = service.NewHandler( service.Logger(log.NopLogger()), service.Config(cfg), service.AppURLs(map[string]map[string]string{ - "view": map[string]string{ + "view": { ".pdf": "https://test.server.prv/hosting/wopi/word/view", ".djvu": "https://test.server.prv/hosting/wopi/word/view", ".docx": "https://test.server.prv/hosting/wopi/word/view", ".xls": "https://test.server.prv/hosting/wopi/cell/view", ".xlsb": "https://test.server.prv/hosting/wopi/cell/view", }, - "edit": map[string]string{ + "edit": { ".docx": "https://test.server.prv/hosting/wopi/word/edit", ".invalid": "://test.server.prv/hosting/wopi/cell/edit", }, }), - service.GatewayAPIClient(gatewayClient), + service.GatewaySelector(gatewaySelector), ) })