From 00b76e0a640fc8185ca08153a9bb3634cab7d900 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 9 Jun 2020 12:47:31 +0200 Subject: [PATCH] Initialize selector before we make an auth.Generate call (#1693) --- config/cmd/cmd.go | 44 ++++++++++++++++++++++---------------------- util/auth/auth.go | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 51ffaad5..568a0c97 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -580,6 +580,28 @@ func (c *cmd) Before(ctx *cli.Context) error { (*c.opts.Auth).Init(authOpts...) } + // Set the registry + if name := ctx.String("registry"); len(name) > 0 && (*c.opts.Registry).String() != name { + r, ok := c.opts.Registries[name] + if !ok { + return fmt.Errorf("Registry %s not found", name) + } + + *c.opts.Registry = r(registrySrv.WithClient(microClient)) + serverOpts = append(serverOpts, server.Registry(*c.opts.Registry)) + clientOpts = append(clientOpts, client.Registry(*c.opts.Registry)) + + if err := (*c.opts.Selector).Init(selector.Registry(*c.opts.Registry)); err != nil { + logger.Fatalf("Error configuring registry: %v", err) + } + + clientOpts = append(clientOpts, client.Selector(*c.opts.Selector)) + + if err := (*c.opts.Broker).Init(broker.Registry(*c.opts.Registry)); err != nil { + logger.Fatalf("Error configuring broker: %v", err) + } + } + // generate the services auth account serverID := (*c.opts.Server).Options().Id if err := authutil.Generate(serverID, c.App().Name, (*c.opts.Auth)); err != nil { @@ -608,28 +630,6 @@ func (c *cmd) Before(ctx *cli.Context) error { clientOpts = append(clientOpts, client.Broker(*c.opts.Broker)) } - // Set the registry - if name := ctx.String("registry"); len(name) > 0 && (*c.opts.Registry).String() != name { - r, ok := c.opts.Registries[name] - if !ok { - return fmt.Errorf("Registry %s not found", name) - } - - *c.opts.Registry = r(registrySrv.WithClient(microClient)) - serverOpts = append(serverOpts, server.Registry(*c.opts.Registry)) - clientOpts = append(clientOpts, client.Registry(*c.opts.Registry)) - - if err := (*c.opts.Selector).Init(selector.Registry(*c.opts.Registry)); err != nil { - logger.Fatalf("Error configuring registry: %v", err) - } - - clientOpts = append(clientOpts, client.Selector(*c.opts.Selector)) - - if err := (*c.opts.Broker).Init(broker.Registry(*c.opts.Registry)); err != nil { - logger.Fatalf("Error configuring broker: %v", err) - } - } - // Set the selector if name := ctx.String("selector"); len(name) > 0 && (*c.opts.Selector).String() != name { s, ok := c.opts.Selectors[name] diff --git a/util/auth/auth.go b/util/auth/auth.go index c41c6a0e..d74bc708 100644 --- a/util/auth/auth.go +++ b/util/auth/auth.go @@ -28,7 +28,7 @@ func Generate(id string, name string, a auth.Auth) error { if err != nil { return err } - logger.Infof("Auth [%v] Authenticated as %v issued by %v", a, name, acc.Issuer) + logger.Debugf("Auth [%v] Authenticated as %v issued by %v", a, name, acc.Issuer) accID = acc.ID accSecret = acc.Secret