From eedcdf5d8e3b999e45310e9b7e6f0d87df8d67b5 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Tue, 8 Sep 2020 15:39:16 +0200 Subject: [PATCH 1/2] Provide role service in service handler for grpc server --- pkg/server/grpc/server.go | 22 +++++++++++++++++++++- pkg/service/v0/accounts.go | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/server/grpc/server.go b/pkg/server/grpc/server.go index 8238614151..22717a3d8b 100644 --- a/pkg/server/grpc/server.go +++ b/pkg/server/grpc/server.go @@ -1,9 +1,14 @@ package grpc import ( + "time" + + mclient "github.com/micro/go-micro/v2/client" "github.com/owncloud/ocis-accounts/pkg/proto/v0" svc "github.com/owncloud/ocis-accounts/pkg/service/v0" + "github.com/owncloud/ocis-pkg/v2/roles" "github.com/owncloud/ocis-pkg/v2/service/grpc" + settings "github.com/owncloud/ocis-settings/pkg/proto/v0" ) // Server initializes a new go-micro service ready to run @@ -22,7 +27,22 @@ func Server(opts ...Option) grpc.Service { var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(options.Logger), svc.Config(options.Config)); err != nil { + // TODO this won't work with a registry other than mdns. Look into Micro's client initialization. + // https://github.com/owncloud/ocis-proxy/issues/38 + rs := settings.NewRoleService("com.owncloud.api.settings", mclient.DefaultClient) + roleManager := roles.NewManager( + roles.CacheSize(1024), + roles.CacheTTL(time.Hour*24*7), + roles.Logger(options.Logger), + roles.RoleService(rs), + ) + + if hdlr, err = svc.New( + svc.Logger(options.Logger), + svc.Config(options.Config), + svc.RoleManager(&roleManager), + svc.RoleService(rs), + ); err != nil { options.Logger.Fatal().Err(err).Msg("could not initialize service handler") } if err = proto.RegisterAccountsServiceHandler(service.Server(), hdlr); err != nil { diff --git a/pkg/service/v0/accounts.go b/pkg/service/v0/accounts.go index 1b25c2027f..92cc2db22a 100644 --- a/pkg/service/v0/accounts.go +++ b/pkg/service/v0/accounts.go @@ -351,6 +351,9 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque } // TODO: assign user role to all new users for now, as create Account request does not have any role field + if s.RoleService == nil { + return merrors.InternalServerError(s.id, "could not assign role to account: roleService not configured") + } _, err = s.RoleService.AssignRoleToUser(ctx, &settings.AssignRoleToUserRequest{ AccountUuid: acc.Id, RoleId: settings_svc.BundleUUIDRoleUser, From e6bc8126926749daf55a54f854e2a3a146ab6305 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Tue, 8 Sep 2020 15:51:24 +0200 Subject: [PATCH 2/2] Changelog --- changelog/unreleased/fix-role-service-grpc.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/fix-role-service-grpc.md diff --git a/changelog/unreleased/fix-role-service-grpc.md b/changelog/unreleased/fix-role-service-grpc.md new file mode 100644 index 0000000000..f42655a1ff --- /dev/null +++ b/changelog/unreleased/fix-role-service-grpc.md @@ -0,0 +1,6 @@ +Bugfix: initialize roleService client in GRPC server + +We fixed the initialization of the GRPC server by also providing a roleService client and a roleManager instance. + +https://github.com/owncloud/ocis-accounts/pull/114 +