Skip to content

Commit

Permalink
Fix validation and spin-up if authorizer is not configured (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel authored Aug 10, 2023
1 parent 467e091 commit 27d0195
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
25 changes: 12 additions & 13 deletions cmd/topazd/topaz_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,24 @@ var cmdRun = &cobra.Command{
if err != nil {
return err
}
directory := topaz.DirectoryResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration)
decisionlog, err := authorizer.GetDecisionLogger(authorizer.Configuration.DecisionLogger)
err = authorizer.ConfigServices()
if err != nil {
return err
}
if _, ok := authorizer.Services["topaz"]; ok {
directory := topaz.DirectoryResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration)
decisionlog, err := authorizer.GetDecisionLogger(authorizer.Configuration.DecisionLogger)
if err != nil {
return err
}

controllerFactory := controller.NewFactory(authorizer.Logger, authorizer.Configuration.ControllerConfig, client.NewDialOptionsProvider())

runtime, _, err := topaz.NewRuntimeResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration, controllerFactory, decisionlog, directory)
if err != nil {
return err
}
controllerFactory := controller.NewFactory(authorizer.Logger, authorizer.Configuration.ControllerConfig, client.NewDialOptionsProvider())

err = authorizer.ConfigServices()
if err != nil {
return err
}
runtime, _, err := topaz.NewRuntimeResolver(authorizer.Context, authorizer.Logger, authorizer.Configuration, controllerFactory, decisionlog, directory)
if err != nil {
return err
}

if _, ok := authorizer.Services["topaz"]; ok {
authorizer.Services["topaz"].(*app.Topaz).Resolver.SetRuntimeResolver(runtime)
authorizer.Services["topaz"].(*app.Topaz).Resolver.SetDirectoryResolver(directory)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/cc/config/topaz_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ func (c *Config) validation() error {
if c.Version != ConfigFileVersion {
return errors.New("unsupported config version")
}
if c.Command.Mode == CommandModeRun && c.OPA.InstanceID == "" {
return errors.New("opa.instance_id not set")
}
if len(c.OPA.Config.Bundles) > 1 {
return errors.New("opa.config.bundles - too many bundles")
if _, ok := c.Services["authorizer"]; ok {
if c.Command.Mode == CommandModeRun && c.OPA.InstanceID == "" {
return errors.New("opa.instance_id not set")
}
if len(c.OPA.Config.Bundles) > 1 {
return errors.New("opa.config.bundles - too many bundles")
}
}

if len(c.Services) == 0 {
Expand Down

0 comments on commit 27d0195

Please sign in to comment.