Skip to content

Commit

Permalink
Rename authorizer and topaz structs and bump go-edge-ds
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel committed Oct 26, 2023
1 parent 96f5147 commit c52cefb
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 54 deletions.
24 changes: 12 additions & 12 deletions cmd/topazd/topaz_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
},
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.20231026130222-a815068c0859
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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -658,8 +658,10 @@ 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-edge-ds v0.21.10-0.20231026130222-a815068c0859 h1:vAEvyU7gqOp1ajiQTARqTt7jDrX3OFxOvtPKxVFhq0o=
github.com/aserto-dev/go-edge-ds v0.21.10-0.20231026130222-a815068c0859/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=
Expand Down
12 changes: 6 additions & 6 deletions pkg/app/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"google.golang.org/grpc"
)

type Topaz struct {
type Authorizer struct {
Resolver *resolvers.Resolvers
AuthorizerServer *impl.AuthorizerServer

Expand Down Expand Up @@ -54,25 +54,25 @@ 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,
AuthorizerServer: authServer,
}, 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
Expand All @@ -91,7 +91,7 @@ func (e *Topaz) GetGatewayRegistration(services ...string) builder.HandlerRegist
}
}

func (e *Topaz) Cleanups() []func() {
func (e *Authorizer) Cleanups() []func() {
return nil
}

Expand Down
25 changes: 11 additions & 14 deletions pkg/app/topaz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/topaz/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions pkg/app/topaz/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/testing/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c52cefb

Please sign in to comment.