Skip to content

Commit

Permalink
Move keystore auth into NewApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
4of9 committed Nov 1, 2024
1 parent aaf3db4 commit 1169073
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
9 changes: 7 additions & 2 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *Shell) configExitErr(validateFn func() error) cli.ExitCoder {

// AppFactory implements the NewApplication method.
type AppFactory interface {
NewApplication(ctx context.Context, cfg chainlink.GeneralConfig, appLggr logger.Logger, db *sqlx.DB) (chainlink.Application, error)
NewApplication(ctx context.Context, cfg chainlink.GeneralConfig, appLggr logger.Logger, db *sqlx.DB, keyStoreAuthenticator TerminalKeyStoreAuthenticator) (chainlink.Application, error)
}

// ChainlinkAppFactory is used to create a new Application.
Expand All @@ -197,8 +197,13 @@ func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.G
}

ds := sqlutil.WrapDataSource(db, appLggr, sqlutil.TimeoutHook(cfg.Database().DefaultQueryTimeout), sqlutil.MonitorHook(cfg.Database().LogSQL))

keyStore := keystore.New(ds, utils.GetScryptParams(cfg), appLggr)

err = keyStoreAuthenticator.authenticate(ctx, keyStore, cfg.Password())
if err != nil {
return nil, errors.Wrap(err, "error authenticating keystore")
}

mailMon := mailbox.NewMonitor(cfg.AppID().String(), appLggr.Named("Mailbox"))

loopRegistry := plugins.NewLoopRegistry(appLggr, cfg.Tracing(), cfg.Telemetry())
Expand Down
11 changes: 3 additions & 8 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,13 @@ func (s *Shell) runNode(c *cli.Context) error {
// From now on, DB locks and DB connection will be released on every return.
// Keep watching on logger.Fatal* calls and os.Exit(), because defer will not be executed.

app, err := s.AppFactory.NewApplication(rootCtx, s.Config, s.Logger, ldb.DB())
app, err := s.AppFactory.NewApplication(rootCtx, s.Config, s.Logger, ldb.DB(), s.KeyStoreAuthenticator)
if err != nil {
return s.errorOut(errors.Wrap(err, "fatal error instantiating application"))
}

// Local shell initialization always uses local auth users table for admin auth
authProviderORM := app.BasicAdminUsersORM()
keyStore := app.GetKeyStore()
err = s.KeyStoreAuthenticator.authenticate(rootCtx, keyStore, s.Config.Password())
if err != nil {
return errors.Wrap(err, "error authenticating keystore")
}

legacyEVMChains := app.GetRelayers().LegacyEVMChains()

Expand Down Expand Up @@ -627,7 +622,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
}
defer lggr.ErrorIfFn(db.Close, "Error closing db")

app, err := s.AppFactory.NewApplication(ctx, s.Config, lggr, db)
app, err := s.AppFactory.NewApplication(ctx, s.Config, lggr, db, s.KeyStoreAuthenticator)
if err != nil {
return s.errorOut(errors.Wrap(err, "fatal error instantiating application"))
}
Expand Down Expand Up @@ -1272,7 +1267,7 @@ func (s *Shell) RemoveBlocks(c *cli.Context) error {
// From now on, DB locks and DB connection will be released on every return.
// Keep watching on logger.Fatal* calls and os.Exit(), because defer will not be executed.

app, err := s.AppFactory.NewApplication(ctx, s.Config, s.Logger, ldb.DB())
app, err := s.AppFactory.NewApplication(ctx, s.Config, s.Logger, ldb.DB(), s.KeyStoreAuthenticator)
if err != nil {
return s.errorOut(errors.Wrap(err, "fatal error instantiating application"))
}
Expand Down
4 changes: 2 additions & 2 deletions core/internal/cltest/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ type InstanceAppFactory struct {
}

// NewApplication creates a new application with specified config
func (f InstanceAppFactory) NewApplication(context.Context, chainlink.GeneralConfig, logger.Logger, *sqlx.DB) (chainlink.Application, error) {
func (f InstanceAppFactory) NewApplication(context.Context, chainlink.GeneralConfig, logger.Logger, *sqlx.DB, cmd.TerminalKeyStoreAuthenticator) (chainlink.Application, error) {
return f.App, nil
}

type seededAppFactory struct {
Application chainlink.Application
}

func (s seededAppFactory) NewApplication(context.Context, chainlink.GeneralConfig, logger.Logger, *sqlx.DB) (chainlink.Application, error) {
func (s seededAppFactory) NewApplication(context.Context, chainlink.GeneralConfig, logger.Logger, *sqlx.DB, cmd.TerminalKeyStoreAuthenticator) (chainlink.Application, error) {
return noopStopApplication{s.Application}, nil
}

Expand Down

0 comments on commit 1169073

Please sign in to comment.