Merge pull request #10583 from owncloud/reusee-go-micro-service
reuse go-micro service clients
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
Bugfix: Reuse go-micro service clients
|
||||||
|
|
||||||
|
go micro clients must not be reinitialized. The internal selector will spawn a new go routine to watch for registry changes.
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/10582
|
||||||
@@ -18,6 +18,9 @@ import (
|
|||||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||||
|
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/utils"
|
||||||
"github.com/go-chi/render"
|
"github.com/go-chi/render"
|
||||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -25,12 +28,7 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
|
||||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
|
||||||
"github.com/cs3org/reva/v2/pkg/utils"
|
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
|
||||||
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
||||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||||
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
|
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
|
||||||
@@ -697,18 +695,8 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, storageSpaces
|
|||||||
|
|
||||||
// ListStorageSpacesWithFilters List Storage Spaces using filters
|
// ListStorageSpacesWithFilters List Storage Spaces using filters
|
||||||
func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*storageprovider.ListStorageSpacesRequest_Filter, unrestricted bool) (*storageprovider.ListStorageSpacesResponse, error) {
|
func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*storageprovider.ListStorageSpacesRequest_Filter, unrestricted bool) (*storageprovider.ListStorageSpacesResponse, error) {
|
||||||
gatewayClient, err := g.gatewaySelector.Next()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(g.config.GRPCClientTLS), grpc.WithTraceProvider(g.traceProvider))...)
|
_, err := g.permissionsService.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s := settingssvc.NewPermissionService("com.owncloud.api.settings", grpcClient)
|
|
||||||
|
|
||||||
_, err = s.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{
|
|
||||||
PermissionId: settingsServiceExt.ListSpacesPermission(0).Id,
|
PermissionId: settingsServiceExt.ListSpacesPermission(0).Id,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -734,6 +722,11 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor
|
|||||||
}},
|
}},
|
||||||
Filters: filters,
|
Filters: filters,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gatewayClient, err := g.gatewaySelector.Next()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
res, err := gatewayClient.ListStorageSpaces(ctx, lReq)
|
res, err := gatewayClient.ListStorageSpaces(ctx, lReq)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import (
|
|||||||
userprovider "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
userprovider "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||||
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/conversions"
|
||||||
|
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/utils"
|
||||||
|
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@@ -23,12 +29,6 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/cs3org/reva/v2/pkg/conversions"
|
|
||||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
|
||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
|
||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
|
||||||
"github.com/cs3org/reva/v2/pkg/utils"
|
|
||||||
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||||
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
||||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||||
@@ -96,6 +96,13 @@ var _ = Describe("Graph", func() {
|
|||||||
|
|
||||||
Describe("Drives", func() {
|
Describe("Drives", func() {
|
||||||
Describe("GetDrivesV1 and GetAllDrivesV1", func() {
|
Describe("GetDrivesV1 and GetAllDrivesV1", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
permissionService.On("GetPermissionByID", mock.Anything, mock.Anything).Return(&settingssvc.GetPermissionByIDResponse{
|
||||||
|
Permission: &v0.Permission{
|
||||||
|
// the permission is not relevant for this test
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
It("can list an empty list of spaces", func() {
|
It("can list an empty list of spaces", func() {
|
||||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||||
Status: status.NewOK(ctx),
|
Status: status.NewOK(ctx),
|
||||||
@@ -482,6 +489,11 @@ var _ = Describe("Graph", func() {
|
|||||||
})
|
})
|
||||||
DescribeTable("GetDrivesV1Beta1 and GetAllDrivesV1Beta1",
|
DescribeTable("GetDrivesV1Beta1 and GetAllDrivesV1Beta1",
|
||||||
func(check func(gjson.Result), resourcePermissions provider.ResourcePermissions) {
|
func(check func(gjson.Result), resourcePermissions provider.ResourcePermissions) {
|
||||||
|
permissionService.On("GetPermissionByID", mock.Anything, mock.Anything).Return(&settingssvc.GetPermissionByIDResponse{
|
||||||
|
Permission: &v0.Permission{
|
||||||
|
// the permission is not relevant for this test
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Times(1).Return(&provider.ListStorageSpacesResponse{
|
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Times(1).Return(&provider.ListStorageSpacesResponse{
|
||||||
Status: status.NewOK(ctx),
|
Status: status.NewOK(ctx),
|
||||||
StorageSpaces: []*provider.StorageSpace{
|
StorageSpaces: []*provider.StorageSpace{
|
||||||
@@ -823,6 +835,11 @@ var _ = Describe("Graph", func() {
|
|||||||
Status: status.NewOK(ctx),
|
Status: status.NewOK(ctx),
|
||||||
TotalBytes: 500,
|
TotalBytes: 500,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
permissionService.On("GetPermissionByID", mock.Anything, mock.Anything).Return(&settingssvc.GetPermissionByIDResponse{
|
||||||
|
Permission: &v0.Permission{
|
||||||
|
// the permission is not relevant for this test
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("handles missing drive id", func() {
|
It("handles missing drive id", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user