// We used to specify a set of policies as []Policy, and in some places
// it may be so serialised.
961878
func (s *Set) UnmarshalJSON(in []byte) error {
	type set Set
	if err := json.Unmarshal(in, (*set)(s)); err != nil {
		var list []Policy
		if err = json.Unmarshal(in, &list); err != nil {
			return err
		}
		var s1 = Set{}
		*s = s1.Add(list...)
	}
	return nil
}
9760
func expandPolicyAttributes(configured []interface{}) ([]*elb.PolicyAttribute, error) {
	attributes := make([]*elb.PolicyAttribute, 0, len(configured))

	// Loop over our configured attributes and create
	// an array of aws-sdk-go compatible objects
	for _, lRaw := range configured {
		data := lRaw.(map[string]interface{})

		a := &elb.PolicyAttribute{
			AttributeName:  aws.String(data["name"].(string)),
			AttributeValue: aws.String(data["value"].(string)),
		}

		attributes = append(attributes, a)

	}

	return attributes, nil
}
401404
func NewSetVirtualTimePolicyArgs(policy VirtualTimePolicy) *SetVirtualTimePolicyArgs {
	args := new(SetVirtualTimePolicyArgs)
	args.Policy = policy
	return args
}
1059151
func (c *Connection) policy(policy string) string {
	return "https://" + c.Signature.Region.Glacier + "/-/policies/" + policy
}
1369152
func (p *PoliciesClient) List(ctx context.Context, orgID *identity.ID, name string) ([]envelope.Policy, error) {
	v := &url.Values{}
	if orgID != nil {
		v.Set("org_id", orgID.String())
	}
	if name != "" {
		v.Set("name", name)
	}

	policies := []envelope.Policy{}
	err := p.client.RoundTrip(ctx, "GET", "/policies", v, nil, &policies)
	return policies, err
}
536222
func (model Model) HasPolicy(sec string, ptype string, rule []string) bool {
	for _, r := range model[sec][ptype].Policy {
		if util.ArrayEquals(rule, r) {
			return true
		}
	}

	return false
}
1356366
func ValidatePolicy(policy string) error {
	_, err := casbin.NewEnforcerSafe(newBuiltInModel(), newAdapter("", "", policy))
	if err != nil {
		return fmt.Errorf("policy syntax error: %s", policy)
	}
	return nil
}
1340366
func (p *Policy) init() {
	if !p.initialized {
		p.elsAndAttrs = make(map[string]map[string]attrPolicy)
		p.globalAttrs = make(map[string]attrPolicy)
		p.allowURLSchemes = make(map[string]urlPolicy)
		p.setOfElementsAllowedWithoutAttrs = make(map[string]struct{})
		p.setOfElementsToSkipContent = make(map[string]struct{})
		p.initialized = true
	}
}
76727
func (p Policy) Equals(another Policy) bool {
	if p.Etag != another.Etag {
		return false
	}

	if !p.Bindings.Equals(another.Bindings) {
		return false
	}

	if len(p.UnrecognizedFields) != len(another.UnrecognizedFields) {
		return false
	}
	for k, left := range p.UnrecognizedFields {
		right, hasIt := another.UnrecognizedFields[k]
		if !hasIt || !isEqualRawMsg(left, right) {
			return false
		}
	}

	return true
}
1222337
func PoliciesFrom(s *vapi.Secret) ([]string, error) {
	if s == nil {
		return nil, fmt.Errorf("cannot parse nil Vault secret")
	}
	var data tokenData
	if err := mapstructure.WeakDecode(s.Data, &data); err != nil {
		return nil, fmt.Errorf("failed to parse Vault token's data block: %v", err)
	}

	return data.Policies, nil
}
714553
func (p *Policy) UnmarshalJSON(data []byte) error {
	var fields map[string]*json.RawMessage
	if err := json.Unmarshal(data, &fields); err != nil {
		return err
	}

	newOne := Policy{
		Bindings:           make(PolicyBindings),
		UnrecognizedFields: fields,
	}

	if raw, ok := fields["bindings"]; ok && raw != nil {
		delete(fields, "bindings")
		if err := json.Unmarshal([]byte(*raw), &newOne.Bindings); err != nil {
			return err
		}
	}

	if raw, ok := fields["etag"]; ok && raw != nil {
		delete(fields, "etag")
		if err := json.Unmarshal([]byte(*raw), &newOne.Etag); err != nil {
			return err
		}
	}

	*p = newOne
	return nil
}
436494
func (cli *OpsGenieClient) Policy() (*OpsGeniePolicyClient, error) {
	cli.makeHTTPTransportSettings()

	policyClient := new(OpsGeniePolicyClient)
	policyClient.SetOpsGenieClient(*cli)

	if cli.opsGenieAPIURL == "" {
		policyClient.SetOpsGenieAPIUrl(endpointURL)
	}

	return policyClient, nil
}
654490
func policyExtensions(runtime policy.RuntimeReader) (extensions policy.ExtendedMap) {

	if runtime == nil {
		return nil
	}

	if runtime.Options().PolicyExtensions == nil {
		return nil
	}

	if extensions, ok := runtime.Options().PolicyExtensions.(policy.ExtendedMap); ok {
		return extensions
	}
	return nil
}
147861
func SetPolicies(repo policies.Repository, policies []policies.Policy) error {
	r, ok := repo.(*policyRepository)
	if !ok {
		return errors.New("unexpected type")
	}
	store := policyStore{}
	for _, policy := range policies {
		store[policyName(policy.Name)] = &policy
	}
	r.mtx.Lock()
	defer r.mtx.Unlock()
	r.policies = store
	return nil
}
271342
func MergePolicies(policies []*Policy) *Policy {
	// maps are used here so that we can lookup each policy by
	// the segment that the rule applies to during the policy
	// merge. Otherwise we could do a linear search through a slice
	// and replace it inline
	aclPolicy := ""
	agentPolicies := make(map[string]*AgentPolicy)
	agentPrefixPolicies := make(map[string]*AgentPolicy)
	eventPolicies := make(map[string]*EventPolicy)
	eventPrefixPolicies := make(map[string]*EventPolicy)
	keyringPolicy := ""
	keyPolicies := make(map[string]*KeyPolicy)
	keyPrefixPolicies := make(map[string]*KeyPolicy)
	nodePolicies := make(map[string]*NodePolicy)
	nodePrefixPolicies := make(map[string]*NodePolicy)
	operatorPolicy := ""
	preparedQueryPolicies := make(map[string]*PreparedQueryPolicy)
	preparedQueryPrefixPolicies := make(map[string]*PreparedQueryPolicy)
	servicePolicies := make(map[string]*ServicePolicy)
	servicePrefixPolicies := make(map[string]*ServicePolicy)
	sessionPolicies := make(map[string]*SessionPolicy)
	sessionPrefixPolicies := make(map[string]*SessionPolicy)

	// Parse all the individual rule sets
	for _, policy := range policies {
		if takesPrecedenceOver(policy.ACL, aclPolicy) {
			aclPolicy = policy.ACL
		}

		for _, ap := range policy.Agents {
			update := true
			if permission, found := agentPolicies[ap.Node]; found {
				update = takesPrecedenceOver(ap.Policy, permission.Policy)
			}

			if update {

				agentPolicies[ap.Node] = ap
			}
		}

		for _, ap := range policy.AgentPrefixes {
			update := true
			if permission, found := agentPrefixPolicies[ap.Node]; found {
				update = takesPrecedenceOver(ap.Policy, permission.Policy)
			}

			if update {
				agentPrefixPolicies[ap.Node] = ap
			}
		}

		for _, ep := range policy.Events {
			update := true
			if permission, found := eventPolicies[ep.Event]; found {
				update = takesPrecedenceOver(ep.Policy, permission.Policy)
			}

			if update {
				eventPolicies[ep.Event] = ep
			}
		}

		for _, ep := range policy.EventPrefixes {
			update := true
			if permission, found := eventPrefixPolicies[ep.Event]; found {
				update = takesPrecedenceOver(ep.Policy, permission.Policy)
			}

			if update {
				eventPrefixPolicies[ep.Event] = ep
			}
		}

		if takesPrecedenceOver(policy.Keyring, keyringPolicy) {
			keyringPolicy = policy.Keyring
		}

		for _, kp := range policy.Keys {
			update := true
			if permission, found := keyPolicies[kp.Prefix]; found {
				update = takesPrecedenceOver(kp.Policy, permission.Policy)
			}

			if update {
				keyPolicies[kp.Prefix] = kp
			}
		}

		for _, kp := range policy.KeyPrefixes {
			update := true
			if permission, found := keyPrefixPolicies[kp.Prefix]; found {
				update = takesPrecedenceOver(kp.Policy, permission.Policy)
			}

			if update {
				keyPrefixPolicies[kp.Prefix] = kp
			}
		}

		for _, np := range policy.Nodes {
			update := true
			if permission, found := nodePolicies[np.Name]; found {
				update = takesPrecedenceOver(np.Policy, permission.Policy)
			}

			if update {
				nodePolicies[np.Name] = np
			}
		}

		for _, np := range policy.NodePrefixes {
			update := true
			if permission, found := nodePrefixPolicies[np.Name]; found {
				update = takesPrecedenceOver(np.Policy, permission.Policy)
			}

			if update {
				nodePrefixPolicies[np.Name] = np
			}
		}

		if takesPrecedenceOver(policy.Operator, operatorPolicy) {
			operatorPolicy = policy.Operator
		}

		for _, qp := range policy.PreparedQueries {
			update := true
			if permission, found := preparedQueryPolicies[qp.Prefix]; found {
				update = takesPrecedenceOver(qp.Policy, permission.Policy)
			}

			if update {
				preparedQueryPolicies[qp.Prefix] = qp
			}
		}

		for _, qp := range policy.PreparedQueryPrefixes {
			update := true
			if permission, found := preparedQueryPrefixPolicies[qp.Prefix]; found {
				update = takesPrecedenceOver(qp.Policy, permission.Policy)
			}

			if update {
				preparedQueryPrefixPolicies[qp.Prefix] = qp
			}
		}

		for _, sp := range policy.Services {
			existing, found := servicePolicies[sp.Name]

			if !found {
				servicePolicies[sp.Name] = sp
				continue
			}

			if takesPrecedenceOver(sp.Policy, existing.Policy) {
				existing.Policy = sp.Policy
				existing.Sentinel = sp.Sentinel
			}

			if takesPrecedenceOver(sp.Intentions, existing.Intentions) {
				existing.Intentions = sp.Intentions
			}
		}

		for _, sp := range policy.ServicePrefixes {
			existing, found := servicePrefixPolicies[sp.Name]

			if !found {
				servicePrefixPolicies[sp.Name] = sp
				continue
			}

			if takesPrecedenceOver(sp.Policy, existing.Policy) {
				existing.Policy = sp.Policy
				existing.Sentinel = sp.Sentinel
			}

			if takesPrecedenceOver(sp.Intentions, existing.Intentions) {
				existing.Intentions = sp.Intentions
			}
		}

		for _, sp := range policy.Sessions {
			update := true
			if permission, found := sessionPolicies[sp.Node]; found {
				update = takesPrecedenceOver(sp.Policy, permission.Policy)
			}

			if update {
				sessionPolicies[sp.Node] = sp
			}
		}

		for _, sp := range policy.SessionPrefixes {
			update := true
			if permission, found := sessionPrefixPolicies[sp.Node]; found {
				update = takesPrecedenceOver(sp.Policy, permission.Policy)
			}

			if update {
				sessionPrefixPolicies[sp.Node] = sp
			}
		}
	}

	merged := &Policy{ACL: aclPolicy, Keyring: keyringPolicy, Operator: operatorPolicy}

	// All the for loop appends are ugly but Go doesn't have a way to get
	// a slice of all values within a map so this is necessary

	for _, policy := range agentPolicies {
		merged.Agents = append(merged.Agents, policy)
	}

	for _, policy := range agentPrefixPolicies {
		merged.AgentPrefixes = append(merged.AgentPrefixes, policy)
	}

	for _, policy := range eventPolicies {
		merged.Events = append(merged.Events, policy)
	}

	for _, policy := range eventPrefixPolicies {
		merged.EventPrefixes = append(merged.EventPrefixes, policy)
	}

	for _, policy := range keyPolicies {
		merged.Keys = append(merged.Keys, policy)
	}

	for _, policy := range keyPrefixPolicies {
		merged.KeyPrefixes = append(merged.KeyPrefixes, policy)
	}

	for _, policy := range nodePolicies {
		merged.Nodes = append(merged.Nodes, policy)
	}

	for _, policy := range nodePrefixPolicies {
		merged.NodePrefixes = append(merged.NodePrefixes, policy)
	}

	for _, policy := range preparedQueryPolicies {
		merged.PreparedQueries = append(merged.PreparedQueries, policy)
	}

	for _, policy := range preparedQueryPrefixPolicies {
		merged.PreparedQueryPrefixes = append(merged.PreparedQueryPrefixes, policy)
	}

	for _, policy := range servicePolicies {
		merged.Services = append(merged.Services, policy)
	}

	for _, policy := range servicePrefixPolicies {
		merged.ServicePrefixes = append(merged.ServicePrefixes, policy)
	}

	for _, policy := range sessionPolicies {
		merged.Sessions = append(merged.Sessions, policy)
	}

	for _, policy := range sessionPrefixPolicies {
		merged.SessionPrefixes = append(merged.SessionPrefixes, policy)
	}

	merged.ID = fmt.Sprintf("%x", multiPolicyID(policies))

	return merged
}
202298
func ImplicitMetaAllPolicy(policyName string) *StandardConfigPolicy {
	return &StandardConfigPolicy{
		key:   policyName,
		value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_ALL),
	}
}
1082085
func TemplateImplicitMetaAllPolicy(path []string, policyName string) *cb.ConfigGroup {
	return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ALL)
}