// addPolicyRuleState adds policy rule to state store
329422
func addPolicyRuleState(ofnetRule *ofnet.OfnetPolicyRule) error {
	ruleCfg := &CfgPolicyRule{}
	ruleCfg.StateDriver = stateStore
	ruleCfg.OfnetPolicyRule = (*ofnetRule)

	// Save the rule
	return ruleCfg.Write()
}
19333
func NewStateStore(config *StateStoreConfig) (*StateStore, error) {
	// Create the MemDB
	db, err := memdb.NewMemDB(stateStoreSchema())
	if err != nil {
		return nil, fmt.Errorf("state store setup failed: %v", err)
	}

	// Create the state store
	s := &StateStore{
		logger:    config.Logger.Named("state_store"),
		db:        db,
		config:    config,
		abandonCh: make(chan struct{}),
	}
	return s, nil
}
1171332
func (s *ListEntitiesForPolicyOutput) SetPolicyRoles(v []*PolicyRole) *ListEntitiesForPolicyOutput {
	s.PolicyRoles = v
	return s
}
1003516
func (d *Daemon) TriggerPolicyUpdates(force bool, reason string) {
	if force {
		log.Debugf("Artifically increasing policy revision to enforce policy recalculation")
		d.policy.BumpRevision()
	}

	d.policyTrigger.TriggerWithReason(reason)
}
93857
func LoadPolicy(ctx context.Context, s logical.Storage, path string) (*Policy, error) {
	raw, err := s.Get(ctx, path)
	if err != nil {
		return nil, err
	}
	if raw == nil {
		return nil, nil
	}

	var policy Policy
	err = jsonutil.DecodeJSON(raw.Value, &policy)
	if err != nil {
		return nil, err
	}

	policy.l = new(sync.RWMutex)

	return &policy, nil
}
1295820
func addPolicyIdentifiers(data *dataBundle, certTemplate *x509.Certificate) {
	for _, oidstr := range data.params.PolicyIdentifiers {
		oid, err := stringToOid(oidstr)
		if err == nil {
			certTemplate.PolicyIdentifiers = append(certTemplate.PolicyIdentifiers, oid)
		}
	}
}
1052192
func (s *CreateUserInput) SetPolicy(v string) *CreateUserInput {
	s.Policy = &v
	return s
}
1011688
func (e *Enforcer) AddPolicySafe(params ...interface{}) (result bool, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("%v", r)
			result = false
		}
	}()

	result = e.AddNamedPolicy("p", params...)
	err = nil
	return
}
213613
func NewPolicyStore(ctx context.Context, core *Core, baseView *BarrierView, system logical.SystemView, logger log.Logger) (*PolicyStore, error) {
	ps := &PolicyStore{
		aclView:    baseView.SubView(policyACLSubPath),
		rgpView:    baseView.SubView(policyRGPSubPath),
		egpView:    baseView.SubView(policyEGPSubPath),
		modifyLock: new(sync.RWMutex),
		logger:     logger,
		core:       core,
	}

	ps.extraInit()

	if !system.CachingDisabled() {
		cache, _ := lru.New2Q(policyCacheSize)
		ps.tokenPoliciesLRU = cache
		cache, _ = lru.New2Q(policyCacheSize)
		ps.egpLRU = cache
	}

	aclView := ps.getACLView(namespace.RootNamespace)
	keys, err := logical.CollectKeys(namespace.RootContext(ctx), aclView)
	if err != nil {
		ps.logger.Error("error collecting acl policy keys", "error", err)
		return nil, err
	}
	for _, key := range keys {
		index := ps.cacheKey(namespace.RootNamespace, ps.sanitizeName(key))
		ps.policyTypeMap.Store(index, PolicyTypeACL)
	}

	if err := ps.loadNamespacePolicies(ctx, core); err != nil {
		return nil, err
	}

	// Special-case root; doesn't exist on disk but does need to be found
	ps.policyTypeMap.Store(ps.cacheKey(namespace.RootNamespace, "root"), PolicyTypeACL)
	return ps, nil
}
623856
func PolicyAddRule(policy *contivModel.Policy, rule *contivModel.Rule) error {
	// Dont install policies in ACI mode
	if !isPolicyEnabled() {
		return nil
	}

	// Walk all associated endpoint groups
	for epgKey := range policy.LinkSets.EndpointGroups {
		gpKey := epgKey + ":" + policy.Key

		// Find the epg policy
		gp := mastercfg.FindEpgPolicy(gpKey)
		if gp == nil {
			log.Errorf("Failed to find the epg policy %s", gpKey)
			return core.Errorf("epg policy not found")
		}

		// Add the Rule
		err := gp.AddRule(rule)
		if err != nil {
			log.Errorf("Error adding the rule %s to epg policy %s. Err: %v", rule.Key, gpKey, err)
			return err
		}

		// Save the policy state
		err = gp.Write()
		if err != nil {
			return err
		}
	}

	return nil
}
1234918
func (e *Enforcer) addPolicy(sec string, ptype string, rule []string) bool {
	ruleAdded := e.model.AddPolicy(sec, ptype, rule)
	if !ruleAdded {
		return ruleAdded
	}

	if e.adapter != nil && e.autoSave {
		if err := e.adapter.AddPolicy(sec, ptype, rule); err != nil {
			if err.Error() != notImplemented {
				panic(err)
			}
		}
		if e.watcher != nil {
			// error intentionally ignored
			e.watcher.Update()
		}
	}

	return ruleAdded
}
566961
func (e *Enforcer) AddNamedGroupingPolicy(ptype string, params ...interface{}) bool {
	var ruleAdded bool
	if strSlice, ok := params[0].([]string); len(params) == 1 && ok {
		ruleAdded = e.addPolicy("g", ptype, strSlice)
	} else {
		policy := make([]string, 0)
		for _, param := range params {
			policy = append(policy, param.(string))
		}

		ruleAdded = e.addPolicy("g", ptype, policy)
	}

	if e.autoBuildRoleLinks {
		e.BuildRoleLinks()
	}
	return ruleAdded
}
470769
func (s *ParameterInlinePolicy) SetPolicyStatus(v string) *ParameterInlinePolicy {
	s.PolicyStatus = &v
	return s
}
1273688
func InitPolicyMgr(stateDriver core.StateDriver, ofm *ofnet.OfnetMaster) error {
	// save statestore and ofnet masters
	stateStore = stateDriver
	ofnetMaster = ofm

	// restore all existing epg policies
	err := restoreEpgPolicies(stateDriver)
	if err != nil {
		log.Errorf("Error restoring EPG policies. ")
	}
	return nil
}
723686
func newPolicy(config Config) *policy {
	policy := &policy{}
	policy.loadConfig(config)
	return policy
}
235299
func CreatePolicy(t testing.T, state StateStore, index uint64, name, rule string) {
	t.Helper()

	// Create the ACLPolicy
	policy := &structs.ACLPolicy{
		Name:  name,
		Rules: rule,
	}
	policy.SetHash()
	assert.Nil(t, state.UpsertACLPolicies(index, []*structs.ACLPolicy{policy}))
}
572727
func (p *NetPlugin) AddPolicyRule(id string) error {
	p.Lock()
	defer p.Unlock()
	return p.NetworkDriver.AddPolicyRule(id)
}