Skip to content

Commit

Permalink
Merge branch 'develop' into golangci-lint-2023-06-8-#2
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Jun 9, 2023
2 parents f5f65fb + f95df17 commit 8b52e27
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 100 deletions.
56 changes: 23 additions & 33 deletions core/chains/evm/config/mocks/chain_scoped_config.go

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

21 changes: 12 additions & 9 deletions core/cmd/key_store_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
Expand All @@ -17,34 +16,38 @@ type TerminalKeyStoreAuthenticator struct {
Prompter Prompter
}

func (auth TerminalKeyStoreAuthenticator) authenticate(keyStore keystore.Master, cfg config.Keystore) error {
type keystorePassword interface {
Keystore() string
}

func (auth TerminalKeyStoreAuthenticator) authenticate(keyStore keystore.Master, password keystorePassword) error {
isEmpty, err := keyStore.IsEmpty()
if err != nil {
return errors.Wrap(err, "error determining if keystore is empty")
}
password := cfg.KeystorePassword()
pw := password.Keystore()

if len(password) != 0 {
if len(pw) != 0 {
// Because we changed password requirements to increase complexity, to
// not break backward compatibility we enforce this only for empty key
// stores.
if err = auth.validatePasswordStrength(password); err != nil && isEmpty {
if err = auth.validatePasswordStrength(pw); err != nil && isEmpty {
return err
}
return keyStore.Unlock(password)
return keyStore.Unlock(pw)
}
interactive := auth.Prompter.IsTerminal()
if !interactive {
return errors.New("no password provided")
} else if !isEmpty {
password = auth.promptExistingPassword()
pw = auth.promptExistingPassword()
} else {
password, err = auth.promptNewPassword()
pw, err = auth.promptNewPassword()
}
if err != nil {
return err
}
return keyStore.Unlock(password)
return keyStore.Unlock(pw)
}

func (auth TerminalKeyStoreAuthenticator) validatePasswordStrength(password string) error {
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/ocr2vrf_configure_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (s *Shell) ConfigureOCR2VRFNode(c *cli.Context, owner *bind.TransactOpts, e
}

func setupKeystore(cli *Shell, app chainlink.Application, keyStore keystore.Master) error {
err := cli.KeyStoreAuthenticator.authenticate(keyStore, cli.Config)
err := cli.KeyStoreAuthenticator.authenticate(keyStore, cli.Config.Password())
if err != nil {
return errors.Wrap(err, "error authenticating keystore")
}
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var (
func initGlobals(cfg config.Prometheus) {
// Avoid double initializations.
initGlobalsOnce.Do(func() {
prometheus = ginprom.New(ginprom.Namespace("service"), ginprom.Token(cfg.PrometheusAuthToken()))
prometheus = ginprom.New(ginprom.Namespace("service"), ginprom.Token(cfg.AuthToken()))
grpcOpts = loop.SetupTelemetry(nil) // default prometheus.Registerer
})
}
Expand Down Expand Up @@ -132,7 +132,7 @@ type ChainlinkAppFactory struct{}

// NewApplication returns a new instance of the node with the given config.
func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.GeneralConfig, appLggr logger.Logger, db *sqlx.DB) (app chainlink.Application, err error) {
initGlobals(cfg)
initGlobals(cfg.Prometheus())

err = handleNodeVersioning(db, appLggr, cfg.RootDir(), cfg.Database())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (s *Shell) runNode(c *cli.Context) error {

sessionORM := app.SessionORM()
keyStore := app.GetKeyStore()
err = s.KeyStoreAuthenticator.authenticate(keyStore, s.Config)
err = s.KeyStoreAuthenticator.authenticate(keyStore, s.Config.Password())
if err != nil {
return errors.Wrap(err, "error authenticating keystore")
}
Expand All @@ -358,7 +358,7 @@ func (s *Shell) runNode(c *cli.Context) error {
}
return def.ID(), nil
}
err = keyStore.Migrate(s.Config.VRFPassword(), DefaultEVMChainIDFunc)
err = keyStore.Migrate(s.Config.Password().VRF(), DefaultEVMChainIDFunc)

if s.Config.EVMEnabled() {
if err != nil {
Expand Down Expand Up @@ -607,7 +607,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
return s.errorOut(fmt.Errorf("error validating configuration: %+v", err))
}

err = keyStore.Unlock(s.Config.KeystorePassword())
err = keyStore.Unlock(s.Config.Password().Keystore())
if err != nil {
return s.errorOut(errors.Wrap(err, "error authenticating keystore"))
}
Expand Down
4 changes: 2 additions & 2 deletions core/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ type AppConfig interface {
SetPasswords(keystore, vrf *string)

FeatureFlags
Keystore
OCR1Config
OCR2Config
P2PNetworking
P2PV1Networking
P2PV2Networking
Prometheus
Pyroscope
Secrets

Expand All @@ -53,6 +51,8 @@ type AppConfig interface {
AutoPprof() AutoPprof
Insecure() Insecure
Explorer() Explorer
Password() Password
Prometheus() Prometheus
}

type DatabaseBackupMode string
Expand Down
5 changes: 0 additions & 5 deletions core/config/keystore.go

This file was deleted.

6 changes: 6 additions & 0 deletions core/config/password_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

type Password interface {
Keystore() string
VRF() string
}
2 changes: 1 addition & 1 deletion core/config/prometheus.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package config

type Prometheus interface {
PrometheusAuthToken() string
AuthToken() string
}
1 change: 0 additions & 1 deletion core/config/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import ocr2models "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/m
type Secrets interface {
MercuryCredentials(credName string) *ocr2models.MercuryCredentials
ThresholdKeyShare() string
VRFPassword() string
}
8 changes: 8 additions & 0 deletions core/services/chainlink/config_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ func (g *generalConfig) Sentry() coreconfig.Sentry {
return sentryConfig{g.c.Sentry}
}

func (g *generalConfig) Password() coreconfig.Password {
return &passwordConfig{keystore: g.keystorePassword, vrf: g.vrfPassword}
}

func (g *generalConfig) Prometheus() coreconfig.Prometheus {
return &prometheusConfig{s: g.secrets.Prometheus}
}

var (
zeroURL = url.URL{}
zeroSha256Hash = models.Sha256Hash{}
Expand Down
7 changes: 0 additions & 7 deletions core/services/chainlink/config_general_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ func (g *generalConfig) PyroscopeAuthToken() string {
return string(*g.secrets.Pyroscope.AuthToken)
}

func (g *generalConfig) PrometheusAuthToken() string {
if g.secrets.Prometheus.AuthToken == nil {
return ""
}
return string(*g.secrets.Prometheus.AuthToken)
}

func (g *generalConfig) MercuryCredentials(credName string) *models.MercuryCredentials {
if mc, ok := g.secrets.Mercury.Credentials[credName]; ok {
return &models.MercuryCredentials{
Expand Down
4 changes: 2 additions & 2 deletions core/services/chainlink/config_general_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (g *generalConfig) SetPasswords(keystore, vrf *string) {
}
}

func (g *generalConfig) KeystorePassword() string {
func (g *generalConfig) keystorePassword() string {
g.passwordMu.RLock()
defer g.passwordMu.RUnlock()
if g.secrets.Password.Keystore == nil {
Expand All @@ -65,7 +65,7 @@ func (g *generalConfig) KeystorePassword() string {
return string(*g.secrets.Password.Keystore)
}

func (g *generalConfig) VRFPassword() string {
func (g *generalConfig) vrfPassword() string {
g.passwordMu.RLock()
defer g.passwordMu.RUnlock()
if g.secrets.Password.VRF == nil {
Expand Down
10 changes: 10 additions & 0 deletions core/services/chainlink/config_password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chainlink

type passwordConfig struct {
keystore func() string
vrf func() string
}

func (p *passwordConfig) Keystore() string { return p.keystore() }

func (p *passwordConfig) VRF() string { return p.vrf() }
20 changes: 20 additions & 0 deletions core/services/chainlink/config_password_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package chainlink

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPasswordConfig(t *testing.T) {
opts := GeneralConfigOpts{
ConfigStrings: []string{fullTOML},
}
cfg, err := opts.New()
require.NoError(t, err)

p := cfg.Password()
assert.Equal(t, "", p.VRF())
assert.Equal(t, "", p.Keystore())
}
16 changes: 16 additions & 0 deletions core/services/chainlink/config_prometheus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chainlink

import (
v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2"
)

type prometheusConfig struct {
s v2.PrometheusSecrets
}

func (p *prometheusConfig) AuthToken() string {
if p.s.AuthToken == nil {
return ""
}
return string(*p.s.AuthToken)
}
19 changes: 19 additions & 0 deletions core/services/chainlink/config_prometheus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package chainlink

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPrometheusConfig(t *testing.T) {
opts := GeneralConfigOpts{
ConfigStrings: []string{fullTOML},
}
cfg, err := opts.New()
require.NoError(t, err)

p := cfg.Prometheus()
assert.Equal(t, "", p.AuthToken())
}
2 changes: 1 addition & 1 deletion core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ func TestNewGeneralConfig_SecretsOverrides(t *testing.T) {
c, err := opts.New()
assert.NoError(t, err)
c.SetPasswords(ptr(PWD_OVERRIDE), nil)
assert.Equal(t, PWD_OVERRIDE, c.KeystorePassword())
assert.Equal(t, PWD_OVERRIDE, c.Password().Keystore())
dbURL := c.Database().URL()
assert.Equal(t, DBURL_OVERRIDE, (&dbURL).String())
}
Expand Down
Loading

0 comments on commit 8b52e27

Please sign in to comment.