Skip to content

Commit

Permalink
Remove vlogger, add log.Logger to PolicyStore struct (#3813)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn authored and jefferai committed Jan 18, 2018
1 parent 54f2458 commit b907a2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 0 additions & 4 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ var (
startReplication = startReplicationImpl
stopReplication = stopReplicationImpl
LastRemoteWAL = lastRemoteWALImpl
// A package-available logger function, mainly to have access in ACL for
// error conditions
vlogger log.Logger
)

// NonFatalError is an error that can be returned during NewCore that should be
Expand Down Expand Up @@ -468,7 +465,6 @@ func NewCore(conf *CoreConfig) (*Core, error) {
if conf.Logger == nil {
conf.Logger = logformat.NewVaultLogger(log.LevelTrace)
}
vlogger = conf.Logger

// Setup the core
c := &Core{
Expand Down
12 changes: 8 additions & 4 deletions vault/policy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/helper/strutil"
"github.com/hashicorp/vault/logical"
log "github.com/mgutz/logxi/v1"
)

const (
Expand Down Expand Up @@ -143,6 +144,8 @@ type PolicyStore struct {
modifyLock *sync.RWMutex
// Stores whether a token policy is ACL or RGP
policyTypeMap sync.Map
// logger is the server logger copied over from core
logger log.Logger
}

// PolicyEntry is used to store a policy by name
Expand All @@ -154,10 +157,11 @@ type PolicyEntry struct {

// NewPolicyStore creates a new PolicyStore that is backed
// using a given view. It used used to durable store and manage named policy.
func NewPolicyStore(baseView *BarrierView, system logical.SystemView) *PolicyStore {
func NewPolicyStore(baseView *BarrierView, system logical.SystemView, logger log.Logger) *PolicyStore {
ps := &PolicyStore{
aclView: baseView.SubView(policyACLSubPath),
modifyLock: new(sync.RWMutex),
logger: logger,
}
if !system.CachingDisabled() {
cache, _ := lru.New2Q(policyCacheSize)
Expand All @@ -166,7 +170,7 @@ func NewPolicyStore(baseView *BarrierView, system logical.SystemView) *PolicySto

keys, err := logical.CollectKeys(ps.aclView)
if err != nil {
vlogger.Error("error collecting acl policy keys", "error", err)
ps.logger.Error("policy: error collecting acl policy keys", "error", err)
return nil
}
for _, key := range keys {
Expand All @@ -182,7 +186,7 @@ func NewPolicyStore(baseView *BarrierView, system logical.SystemView) *PolicySto
func (c *Core) setupPolicyStore() error {
// Create the policy store
sysView := &dynamicSystemView{core: c}
c.policyStore = NewPolicyStore(c.systemBarrierView, sysView)
c.policyStore = NewPolicyStore(c.systemBarrierView, sysView, c.logger)

if c.ReplicationState().HasState(consts.ReplicationPerformanceSecondary) {
// Policies will sync from the primary
Expand Down Expand Up @@ -228,7 +232,7 @@ func (ps *PolicyStore) invalidate(name string, policyType PolicyType) {
// Force a reload
_, err := ps.GetPolicy(name, policyType)
if err != nil {
vlogger.Error("policy: error fetching policy after invalidation", "name", saneName)
ps.logger.Error("policy: error fetching policy after invalidation", "name", saneName)
}
}

Expand Down
6 changes: 4 additions & 2 deletions vault/policy_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"reflect"
"testing"

"github.com/hashicorp/vault/helper/logformat"
"github.com/hashicorp/vault/logical"
log "github.com/mgutz/logxi/v1"
)

func mockPolicyStore(t *testing.T) *PolicyStore {
_, barrier, _ := mockBarrier(t)
view := NewBarrierView(barrier, "foo/")
p := NewPolicyStore(view, logical.TestSystemView())
p := NewPolicyStore(view, logical.TestSystemView(), logformat.NewVaultLogger(log.LevelTrace))
return p
}

Expand All @@ -19,7 +21,7 @@ func mockPolicyStoreNoCache(t *testing.T) *PolicyStore {
sysView.CachingDisabledVal = true
_, barrier, _ := mockBarrier(t)
view := NewBarrierView(barrier, "foo/")
p := NewPolicyStore(view, sysView)
p := NewPolicyStore(view, sysView, logformat.NewVaultLogger(log.LevelTrace))
return p
}

Expand Down

0 comments on commit b907a2e

Please sign in to comment.