Add core object to policy store for some ent uses

This commit is contained in:
Jeff Mitchell 2018-02-23 14:00:46 -05:00
parent 8b09949a81
commit 1a814803d7
2 changed files with 6 additions and 4 deletions

View file

@ -137,6 +137,7 @@ var (
// PolicyStore is used to provide durable storage of policy, and to
// manage ACLs associated with them.
type PolicyStore struct {
core *Core
aclView *BarrierView
tokenPoliciesLRU *lru.TwoQueueCache
// This is used to ensure that writes to the store (acl/rgp) or to the egp
@ -158,11 +159,12 @@ 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(ctx context.Context, baseView *BarrierView, system logical.SystemView, logger log.Logger) *PolicyStore {
func NewPolicyStore(ctx context.Context, core *Core, baseView *BarrierView, system logical.SystemView, logger log.Logger) *PolicyStore {
ps := &PolicyStore{
aclView: baseView.SubView(policyACLSubPath),
modifyLock: new(sync.RWMutex),
logger: logger,
core: core,
}
if !system.CachingDisabled() {
cache, _ := lru.New2Q(policyCacheSize)
@ -187,7 +189,7 @@ func NewPolicyStore(ctx context.Context, baseView *BarrierView, system logical.S
func (c *Core) setupPolicyStore(ctx context.Context) error {
// Create the policy store
sysView := &dynamicSystemView{core: c}
c.policyStore = NewPolicyStore(ctx, c.systemBarrierView, sysView, c.logger)
c.policyStore = NewPolicyStore(ctx, c, c.systemBarrierView, sysView, c.logger)
if c.ReplicationState().HasState(consts.ReplicationPerformanceSecondary) {
// Policies will sync from the primary

View file

@ -13,7 +13,7 @@ import (
func mockPolicyStore(t *testing.T) *PolicyStore {
_, barrier, _ := mockBarrier(t)
view := NewBarrierView(barrier, "foo/")
p := NewPolicyStore(context.Background(), view, logical.TestSystemView(), logformat.NewVaultLogger(log.LevelTrace))
p := NewPolicyStore(context.Background(), nil, view, logical.TestSystemView(), logformat.NewVaultLogger(log.LevelTrace))
return p
}
@ -22,7 +22,7 @@ func mockPolicyStoreNoCache(t *testing.T) *PolicyStore {
sysView.CachingDisabledVal = true
_, barrier, _ := mockBarrier(t)
view := NewBarrierView(barrier, "foo/")
p := NewPolicyStore(context.Background(), view, sysView, logformat.NewVaultLogger(log.LevelTrace))
p := NewPolicyStore(context.Background(), nil, view, sysView, logformat.NewVaultLogger(log.LevelTrace))
return p
}