Skip to content

Commit

Permalink
Disable local directory services when using a remote directory
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel committed May 8, 2024
1 parent 74cd948 commit 3bcb9d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
17 changes: 8 additions & 9 deletions pkg/app/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ func (e *ConsoleService) Cleanups() []func() {
}

func (e *ConsoleService) PrepareConfig(cfg *config.Config) *handlers.TopazCfg {
directoryServiceURL := serviceAddress(fmt.Sprintf("https://%s", strings.Split(cfg.DirectoryResolver.Address, ":")[0]))

authorizerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[authorizerService]; ok {
authorizerURL = getGatewayAddress(serviceConfig)
}

readerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[readerService]; ok {
readerURL = getGatewayAddress(serviceConfig)
if cfg.DirectoryResolver.Address == serviceConfig.GRPC.ListenAddress {
directoryServiceURL = readerURL
}
}
writerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[writerService]; ok {
Expand Down Expand Up @@ -86,19 +92,12 @@ func (e *ConsoleService) PrepareConfig(cfg *config.Config) *handlers.TopazCfg {
}
}

directoryAPIKey := ""
if _, ok := cfg.APIConfig.Services[readerService]; ok {
for key := range cfg.Auth.APIKeys {
// we only need a key
directoryAPIKey = key
break
}
}
directoryAPIKey := cfg.DirectoryResolver.APIKey

return &handlers.TopazCfg{
AuthorizerServiceURL: authorizerURL,
AuthorizerAPIKey: authorizerAPIKey,
DirectoryServiceURL: readerURL,
DirectoryServiceURL: directoryServiceURL,
DirectoryAPIKey: directoryAPIKey,
DirectoryTenantID: cfg.DirectoryResolver.TenantID,
DirectoryReaderServiceURL: readerURL,
Expand Down
19 changes: 16 additions & 3 deletions pkg/app/topaz.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ type ServiceTypes interface {
Cleanups() []func()
}

var (
ErrBadDirResolverConfig = errors.New("remote directory resolver address is different from reader grpc address")
ErrNeedsModelService = errors.New("console needs the model service to be configured")
)

func (e *Topaz) AddGRPCServerOptions(grpcOptions ...grpc.ServerOption) {
e.ServerOptions = append(e.ServerOptions, grpcOptions...)
}
Expand Down Expand Up @@ -96,7 +101,15 @@ func (e *Topaz) ConfigServices() error {
}

if err := e.validateConfig(); err != nil {
return err
if errors.Is(err, ErrBadDirResolverConfig) {
for _, serviceName := range e.Services["edge"].AvailableServices() {
delete(e.Configuration.APIConfig.Services, serviceName)
}
delete(e.Services, "edge")
e.Logger.Info().Msg("disabling local directory services")
} else {
return err
}
}

serviceMap := mapToGRPCPorts(e.Configuration.APIConfig.Services)
Expand Down Expand Up @@ -306,14 +319,14 @@ func (e *Topaz) GetDecisionLogger(cfg config.DecisionLogConfig) (decisionlog.Dec
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")
return ErrBadDirResolverConfig
}
}

if _, ok := e.Configuration.APIConfig.Services["console"]; ok {
if _, ok := e.Configuration.APIConfig.Services["reader"]; ok {
if _, ok := e.Configuration.APIConfig.Services["model"]; !ok {
return errors.New("console needs the model service to be configured")
return ErrNeedsModelService
}
}
}
Expand Down

0 comments on commit 3bcb9d3

Please sign in to comment.