Skip to content

Commit

Permalink
Add core object to policy store for some ent uses
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Feb 23, 2018
1 parent a84944c commit 2769b9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions vault/policy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vault/policy_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 2769b9f

Please sign in to comment.