From dce0c7a32f455caf4f68c985fe2ed3577c530294 Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Thu, 26 Oct 2023 15:31:09 +0300 Subject: [PATCH] Rename authorizer and topaz structs and bump go-edge-ds --- cmd/topazd/topaz_run.go | 24 ++++++++++++------------ go.mod | 5 +++-- go.sum | 8 ++++---- pkg/app/authorizer.go | 12 ++++++------ pkg/app/topaz.go | 25 +++++++++++-------------- pkg/app/topaz/wire.go | 10 +++++----- pkg/app/topaz/wire_gen.go | 14 +++++++------- pkg/testing/engine.go | 8 ++++---- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/cmd/topazd/topaz_run.go b/cmd/topazd/topaz_run.go index 71f5a7060..7df9799f6 100644 --- a/cmd/topazd/topaz_run.go +++ b/cmd/topazd/topaz_run.go @@ -24,7 +24,7 @@ var cmdRun = &cobra.Command{ Long: `Start instance of the Topaz authorization service.`, RunE: func(cmd *cobra.Command, args []string) error { configPath := config.Path(flagRunConfigFile) - authorizer, cleanup, err := topaz.BuildApp(os.Stdout, os.Stderr, configPath, func(cfg *config.Config) { + topazApp, cleanup, err := topaz.BuildApp(os.Stdout, os.Stderr, configPath, func(cfg *config.Config) { cfg.Command.Mode = config.CommandModeRun if len(flagRunBundleFiles) > 0 { @@ -41,43 +41,43 @@ var cmdRun = &cobra.Command{ }) defer func() { if cleanup != nil { - authorizer.Manager.StopServers(authorizer.Context) + topazApp.Manager.StopServers(topazApp.Context) cleanup() } }() if err != nil { return err } - err = authorizer.ConfigServices() + err = topazApp.ConfigServices() if err != nil { return err } - if _, ok := authorizer.Services["authorizer"]; ok { - directory := topaz.DirectoryResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration) - decisionlog, err := authorizer.GetDecisionLogger(authorizer.Configuration.DecisionLogger) + if _, ok := topazApp.Services["authorizer"]; ok { + directory := topaz.DirectoryResolver(topazApp.Context, topazApp.Logger, topazApp.Configuration) + decisionlog, err := topazApp.GetDecisionLogger(topazApp.Configuration.DecisionLogger) if err != nil { return err } - controllerFactory := controller.NewFactory(authorizer.Logger, authorizer.Configuration.ControllerConfig, client.NewDialOptionsProvider()) + controllerFactory := controller.NewFactory(topazApp.Logger, topazApp.Configuration.ControllerConfig, client.NewDialOptionsProvider()) - runtime, runtimeCleanup, err := topaz.NewRuntimeResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration, controllerFactory, decisionlog, directory) + runtime, runtimeCleanup, err := topaz.NewRuntimeResolver(topazApp.Context, topazApp.Logger, topazApp.Configuration, controllerFactory, decisionlog, directory) if err != nil { return err } defer runtimeCleanup() - authorizer.Services["authorizer"].(*app.Topaz).Resolver.SetRuntimeResolver(runtime) - authorizer.Services["authorizer"].(*app.Topaz).Resolver.SetDirectoryResolver(directory) + topazApp.Services["authorizer"].(*app.Authorizer).Resolver.SetRuntimeResolver(runtime) + topazApp.Services["authorizer"].(*app.Authorizer).Resolver.SetDirectoryResolver(directory) } - err = authorizer.Start() + err = topazApp.Start() if err != nil { return err } - <-authorizer.Context.Done() + <-topazApp.Context.Done() return nil }, diff --git a/go.mod b/go.mod index 976130db3..afa0c24ba 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 // replace github.com/aserto-dev/go-directory => ../go-directory // replace github.com/aserto-dev/go-edge-ds => ../go-edge-ds + // replace github.com/aserto-dev/service-host => ../service-host // replace github.com/aserto-dev/runtime => ../runtime @@ -18,7 +19,7 @@ require ( github.com/aserto-dev/go-authorizer v0.20.3 github.com/aserto-dev/go-directory v0.21.8-0.20231015213014-2bac9fa0ff01 github.com/aserto-dev/go-directory-cli v0.20.14-0.20230913232053-927068a67595 - github.com/aserto-dev/go-edge-ds v0.21.10-0.20231016010552-b43dd36f22a0 + github.com/aserto-dev/go-edge-ds v0.21.10-0.20231026075825-ed941455e1de github.com/aserto-dev/go-grpc v0.8.57 github.com/aserto-dev/header v0.0.5 github.com/aserto-dev/logger v0.0.4 @@ -55,7 +56,7 @@ require ( ) require ( - buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1 // indirect + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231017183020-0de7443d03cf.2 // indirect contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/Masterminds/semver v1.5.0 // indirect diff --git a/go.sum b/go.sum index 1b8685e39..3a67e74ac 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1 h1:2gmp+PRca1fqQHf/WMKOgu9inVb0R0N07TucgY3QZCQ= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230914171853-63dfe56cc2c4.1/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231017183020-0de7443d03cf.2 h1:t3Bq7+sq30Ga31zuUZVk02meAYwhiZ9SGMRVQPJJgqs= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231017183020-0de7443d03cf.2/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -658,8 +658,8 @@ github.com/aserto-dev/go-directory v0.21.8-0.20231015213014-2bac9fa0ff01 h1:glYq github.com/aserto-dev/go-directory v0.21.8-0.20231015213014-2bac9fa0ff01/go.mod h1:xkZFWZ0u0RcYRBkJLTqantIG/jnVxYhzd2+kIQf8PnU= github.com/aserto-dev/go-directory-cli v0.20.14-0.20230913232053-927068a67595 h1:t/L3jN8AhLQsqbJq7AD/zFMNQDH3sT+lKiM7VoIfMk4= github.com/aserto-dev/go-directory-cli v0.20.14-0.20230913232053-927068a67595/go.mod h1:+tWMBAzEd+TW7m0PEhVYTX50h4Nju1au+J151yeEUdA= -github.com/aserto-dev/go-edge-ds v0.21.10-0.20231016010552-b43dd36f22a0 h1:RbQdTunSrivb8e9GAsvWCm0EHt9o6iHQlNJxxnrYIPQ= -github.com/aserto-dev/go-edge-ds v0.21.10-0.20231016010552-b43dd36f22a0/go.mod h1:efUarhzP1Lay6WxAoLphyaa7VmvkNf1D0E10M0P4Ew4= +github.com/aserto-dev/go-edge-ds v0.21.10-0.20231026075825-ed941455e1de h1:joTGVt7uj+LzrrPcBkcFEnQqMtcfiGrVInuZzDAN+0M= +github.com/aserto-dev/go-edge-ds v0.21.10-0.20231026075825-ed941455e1de/go.mod h1:fnsTvulHubkpEJkhUK/SM5UNnQGKlDMGpAgpW0kyHQM= github.com/aserto-dev/go-grpc v0.8.57 h1:CjQVxZ2HkBvJrfCtaDeq2kZSn2yLmRel5kHCVzqRMLs= github.com/aserto-dev/go-grpc v0.8.57/go.mod h1:2FcclMDheTsEvYCY72o+EwTaoO0ti3/it4G6xIlzNIM= github.com/aserto-dev/go-http-metrics v0.10.1-20221024-1 h1:nONd24V5nyJ0IIw8QE+OKv30YuHOTNbJ4FsvczLaM8o= diff --git a/pkg/app/authorizer.go b/pkg/app/authorizer.go index 1e070c5c3..789fd5338 100644 --- a/pkg/app/authorizer.go +++ b/pkg/app/authorizer.go @@ -22,7 +22,7 @@ import ( "google.golang.org/grpc" ) -type Topaz struct { +type Authorizer struct { Resolver *resolvers.Resolvers AuthorizerServer *impl.AuthorizerServer @@ -54,7 +54,7 @@ func NewAuthorizer(cfg *builder.API, commonConfig *config.Common, authorizerOpts authServer := impl.NewAuthorizerServer(logger, commonConfig, authResolvers) - return &Topaz{ + return &Authorizer{ cfg: cfg, opts: authorizerOpts, Resolver: authResolvers, @@ -62,17 +62,17 @@ func NewAuthorizer(cfg *builder.API, commonConfig *config.Common, authorizerOpts }, nil } -func (e *Topaz) AvailableServices() []string { +func (e *Authorizer) AvailableServices() []string { return []string{authorizerService} } -func (e *Topaz) GetGRPCRegistrations(services ...string) builder.GRPCRegistrations { +func (e *Authorizer) GetGRPCRegistrations(services ...string) builder.GRPCRegistrations { return func(server *grpc.Server) { authz.RegisterAuthorizerServer(server, e.AuthorizerServer) } } -func (e *Topaz) GetGatewayRegistration(services ...string) builder.HandlerRegistrations { +func (e *Authorizer) GetGatewayRegistration(services ...string) builder.HandlerRegistrations { return func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error { if err := authz.RegisterAuthorizerHandlerFromEndpoint(ctx, mux, grpcEndpoint, opts); err != nil { return err @@ -91,7 +91,7 @@ func (e *Topaz) GetGatewayRegistration(services ...string) builder.HandlerRegist } } -func (e *Topaz) Cleanups() []func() { +func (e *Authorizer) Cleanups() []func() { return nil } diff --git a/pkg/app/topaz.go b/pkg/app/topaz.go index 9011d872b..28890584b 100644 --- a/pkg/app/topaz.go +++ b/pkg/app/topaz.go @@ -7,6 +7,7 @@ import ( "time" "github.com/aserto-dev/go-aserto/client" + eds "github.com/aserto-dev/go-edge-ds" "github.com/aserto-dev/self-decision-logger/logger/self" decisionlog "github.com/aserto-dev/topaz/decision_log" "github.com/aserto-dev/topaz/decision_log/logger/file" @@ -23,16 +24,12 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/health/grpc_health_v1" - edge "github.com/aserto-dev/go-edge-ds/pkg/server" - builder "github.com/aserto-dev/service-host" ) -var locker edge.EdgeDirLock - -// Authorizer is an authorizer service instance, responsible for managing +// Topaz is an authorizer service instance, responsible for managing // the authorizer API, user directory instance and the OPA plugins. -type Authorizer struct { +type Topaz struct { Context context.Context Logger *zerolog.Logger ServerOptions []grpc.ServerOption @@ -49,12 +46,12 @@ type ServiceTypes interface { Cleanups() []func() } -func (e *Authorizer) AddGRPCServerOptions(grpcOptions ...grpc.ServerOption) { +func (e *Topaz) AddGRPCServerOptions(grpcOptions ...grpc.ServerOption) { e.ServerOptions = append(e.ServerOptions, grpcOptions...) } // Start starts all services required by the engine. -func (e *Authorizer) Start() error { +func (e *Topaz) Start() error { // build dependencies map. for _, cfg := range e.Configuration.APIConfig.Services { if len(cfg.Needs) > 0 { @@ -84,7 +81,7 @@ func (e *Authorizer) Start() error { return nil } -func (e *Authorizer) ConfigServices() error { +func (e *Topaz) ConfigServices() error { metricsMiddleware, err := e.setupHealthAndMetrics() if err != nil { return err @@ -164,7 +161,7 @@ func (e *Authorizer) ConfigServices() error { return nil } -func (e *Authorizer) setupHealthAndMetrics() ([]grpc.ServerOption, error) { +func (e *Topaz) setupHealthAndMetrics() ([]grpc.ServerOption, error) { if e.Configuration.APIConfig.Health.ListenAddress != "" { err := e.Manager.SetupHealthServer(e.Configuration.APIConfig.Health.ListenAddress, e.Configuration.APIConfig.Health.Certificates) if err != nil { @@ -183,10 +180,10 @@ func (e *Authorizer) setupHealthAndMetrics() ([]grpc.ServerOption, error) { return nil, nil } -func (e *Authorizer) prepareServices() error { +func (e *Topaz) prepareServices() error { // prepare services if e.Configuration.Edge.DBPath != "" { - dir, err := locker.New(&e.Configuration.Edge, e.Logger) + dir, err := eds.New(e.Context, &e.Configuration.Edge, e.Logger) if err != nil { return err } @@ -255,7 +252,7 @@ func contains[T comparable](slice []T, item T) bool { return false } -func (e *Authorizer) GetDecisionLogger(cfg config.DecisionLogConfig) (decisionlog.DecisionLogger, error) { +func (e *Topaz) GetDecisionLogger(cfg config.DecisionLogConfig) (decisionlog.DecisionLogger, error) { var decisionlogger decisionlog.DecisionLogger var err error @@ -294,7 +291,7 @@ func (e *Authorizer) GetDecisionLogger(cfg config.DecisionLogConfig) (decisionlo return decisionlogger, err } -func (e *Authorizer) validateConfig() error { +func (e *Topaz) validateConfig() error { if readerConfig, ok := e.Configuration.APIConfig.Services["reader"]; ok { if readerConfig.GRPC.ListenAddress != e.Configuration.DirectoryResolver.Address { return errors.New("remote directory resolver address is different from reader grpc address") diff --git a/pkg/app/topaz/wire.go b/pkg/app/topaz/wire.go index 74a4c1e79..5fff0fc46 100644 --- a/pkg/app/topaz/wire.go +++ b/pkg/app/topaz/wire.go @@ -29,7 +29,7 @@ var ( wire.FieldsOf(new(*cc.CC), "Config", "Log", "Context", "ErrGroup"), wire.FieldsOf(new(*config.Config), "Common", "DecisionLogger"), - wire.Struct(new(app.Authorizer), "*"), + wire.Struct(new(app.Topaz), "*"), ) appTestSet = wire.NewSet( @@ -43,14 +43,14 @@ var ( ) ) -func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Authorizer, func(), error) { +func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Topaz, func(), error) { wire.Build(appSet) - return &app.Authorizer{}, func() {}, nil + return &app.Topaz{}, func() {}, nil } -func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Authorizer, func(), error) { +func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Topaz, func(), error) { wire.Build(appTestSet) - return &app.Authorizer{}, func() {}, nil + return &app.Topaz{}, func() {}, nil } func DefaultGRPCOptions() []grpc.ServerOption { diff --git a/pkg/app/topaz/wire_gen.go b/pkg/app/topaz/wire_gen.go index 1b83c7ad0..0e0441158 100644 --- a/pkg/app/topaz/wire_gen.go +++ b/pkg/app/topaz/wire_gen.go @@ -20,7 +20,7 @@ import ( // Injectors from wire.go: -func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Authorizer, func(), error) { +func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Topaz, func(), error) { ccCC, cleanup, err := cc.NewCC(logOutput, errOutput, configPath, overrides) if err != nil { return nil, nil, err @@ -32,7 +32,7 @@ func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath co serviceFactory := builder.NewServiceFactory() serviceManager := builder.NewServiceManager(zerologLogger) v2 := DefaultServices() - authorizer := &app.Authorizer{ + topaz := &app.Topaz{ Context: context, Logger: zerologLogger, ServerOptions: v, @@ -41,12 +41,12 @@ func BuildApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath co Manager: serviceManager, Services: v2, } - return authorizer, func() { + return topaz, func() { cleanup() }, nil } -func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Authorizer, func(), error) { +func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPath config.Path, overrides config.Overrider) (*app.Topaz, func(), error) { ccCC, cleanup, err := cc.NewTestCC(logOutput, errOutput, configPath, overrides) if err != nil { return nil, nil, err @@ -58,7 +58,7 @@ func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPat serviceFactory := builder.NewServiceFactory() serviceManager := builder.NewServiceManager(zerologLogger) v2 := DefaultServices() - authorizer := &app.Authorizer{ + topaz := &app.Topaz{ Context: context, Logger: zerologLogger, ServerOptions: v, @@ -67,7 +67,7 @@ func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPat Manager: serviceManager, Services: v2, } - return authorizer, func() { + return topaz, func() { cleanup() }, nil } @@ -76,7 +76,7 @@ func BuildTestApp(logOutput logger.Writer, errOutput logger.ErrWriter, configPat var ( commonSet = wire.NewSet(resolvers.New, impl.NewAuthorizerServer, builder.NewServiceFactory, builder.NewServiceManager, DefaultGRPCOptions, - DefaultServices, wire.FieldsOf(new(*cc.CC), "Config", "Log", "Context", "ErrGroup"), wire.FieldsOf(new(*config.Config), "Common", "DecisionLogger"), wire.Struct(new(app.Authorizer), "*"), + DefaultServices, wire.FieldsOf(new(*cc.CC), "Config", "Log", "Context", "ErrGroup"), wire.FieldsOf(new(*config.Config), "Common", "DecisionLogger"), wire.Struct(new(app.Topaz), "*"), ) appTestSet = wire.NewSet( diff --git a/pkg/testing/engine.go b/pkg/testing/engine.go index 762379019..a5a89257d 100644 --- a/pkg/testing/engine.go +++ b/pkg/testing/engine.go @@ -22,7 +22,7 @@ const ( // EngineHarness wraps an Aserto Runtime Engine so we can set it up easily // and monitor its logs. type EngineHarness struct { - Engine *app.Authorizer + Engine *app.Topaz LogDebugger *LogDebugger cleanup func() @@ -54,7 +54,7 @@ func (h *EngineHarness) Cleanup() { func (h *EngineHarness) Runtime() *runtime.Runtime { if _, ok := h.Engine.Services["authorizer"]; ok { - result, err := h.Engine.Services["authorizer"].(*app.Topaz).Resolver.GetRuntimeResolver().RuntimeFromContext(h.Engine.Context, "", "") + result, err := h.Engine.Services["authorizer"].(*app.Authorizer).Resolver.GetRuntimeResolver().RuntimeFromContext(h.Engine.Context, "", "") require.NoError(h.t, err) return result } @@ -114,8 +114,8 @@ func setup(t *testing.T, configOverrides func(*config.Config), online bool) *Eng err = h.Engine.ConfigServices() assert.NoError(err) if _, ok := h.Engine.Services["authorizer"]; ok { - h.Engine.Services["authorizer"].(*app.Topaz).Resolver.SetRuntimeResolver(rt) - h.Engine.Services["authorizer"].(*app.Topaz).Resolver.SetDirectoryResolver(directory) + h.Engine.Services["authorizer"].(*app.Authorizer).Resolver.SetRuntimeResolver(rt) + h.Engine.Services["authorizer"].(*app.Authorizer).Resolver.SetDirectoryResolver(directory) } err = h.Engine.Start() assert.NoError(err)