Creates rule for a certain L7 policy.
189716
def create_lbaas_l7rule(self, l7policy, body=None):
        """"""
        return self.post(self.lbaas_l7rules_path % l7policy, body=body)
64438
function setRuleModel (roles, rule, rules, origRule) {
    // allow/deny is last element of rule
    var allow = rule.pop()
    // blanket rule for all models
    if (rule.length === 0) {
        // create role access rule map
        if (!rules.allow) {
            rules.allow = {}
        }
        // set rule for each role
        _.each(roles, role => {
            rules.allow[role] = allow
        })
        // break
        return
    }

    // model name is first clause of rule
    var model = rule.shift()
    // create map of models
    if (!rules.model) {
        rules.model = {}
    }
    // create entry for model
    if (!rules.model[model]) {
        rules.model[model] = {}
    }

    // blanket rule for single model
    if (rule.length === 0) {
        // create role access rule map
        if (!rules.model[model].allow) {
            rules.model[model].allow = {}
        }
        // set rule for each role
        _.each(roles, role => {
            rules.model[model].allow[role] = allow
        })
        // break
        return
    }

    // action follows model name
    var action = rule.shift()
    // create map of actions
    if (!rules.model[model].action) {
        rules.model[model].action = {}
    }
    // create entry for action
    if (!rules.model[model].action[action]) {
        rules.model[model].action[action] = {}
    }

    // create action does not have any options
    if (action === 'create') {
        // there should be no more rule clauses
        if (rule.length === 0) {
            // create role access rule map
            if (!rules.model[model].action[action].allow) {
                rules.model[model].action[action].allow = {}
            }
            // set rule for each role
            _.each(roles, role => {
                rules.model[model].action[action].allow[role] = allow
            })
            // break
            return
        }
        else {
            throw new Error('invalid rule '+origRule)
        }
    }
    // all other actions apply to existing model instances and can
    // apply either to any instance or to instances owned by session
    else {
        // if there are two rule clauses then next is a state
        if (rule.length === 2) {
            var state = rule.shift()
            // create map of states
            if (!rules.model[model].action[action].state) {
                rules.model[model].action[action].state = {}
            }
            // create entry for state
            if (!rules.model[model].action[action].state[state]) {
                rules.model[model].action[action].state[state] = {}
            }
            // own/any clause follows state
            rules = rules.model[model].action[action].state[state]
        }
        // otherwise own/any clause follows action
        else {
            rules = rules.model[model].action[action]
        }
        // there must be one additional rule clause
        if (rule.length === 1) {
            var scope = rule.shift()
            // scope must be own or any
            assert.ok(scope === 'own' || scope === 'any', 'invalid rule '+origRule)
            // create map for scope
            if (!rules[scope]) {
                rules[scope] = {}
            }
            // create role access rule map
            if (!rules[scope].allow) {
                rules[scope].allow = {}
            }
            // set rule for each role
            _.each(roles, role => {
                rules[scope].allow[role] = allow
            })
        }
        else {
            throw new Error('invalid rule '+origRule)
        }
    }
}
89009
def apply_T7(word):
    ''''''
    WORD = word
    offset = 0

    for vvv in vvv_sequences(WORD):
        i = vvv.start(2) + 2 + offset
        WORD = WORD[:i] + '.' + WORD[i:]
        offset += 1

    RULE = ' T7' if word != WORD else ''

    return WORD, RULE
893331
public boolean addPolicy(String sec, String ptype, List<String> rule) {
        if (!hasPolicy(sec, ptype, rule)) {
            model.get(sec).get(ptype).policy.add(rule);
            return true;
        }
        return false;
    }
1327562
@Override
    public void addPolicy(String sec, String ptype, List<String> rule) {
        throw new Error("not implemented");
    }
583372
public MetaConfig withInstanceCheck(InstanceCheckPolicy policy) {
    Ensure.that(policy != null, "policy != null");

    return new MetaConfigBuilder(this)
      .setInstanceCheckPolicy(policy)
      .build();
  }
575586
function createRule(path, handler) {
  if ('*' !== path && 0 != path.indexOf(watch.__base)) {
    path = watch.__base + (path == '/' ? '' : path)
  }
  let rule = pathToRegExp(path)
  if (handler instanceof String) {
    let target = handler
    handler = function() {
      watch({
        url: target
      })
    }
  }
  rule.handler = handler

  return rule
}
941312
def enforce_policy(rule):
    """"""
    def wrapper(func):
        """Decorator used for wrap API."""
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if enforcer.enforce(rule, {}, g.cred):
                return func(*args, **kwargs)

        return wrapped

    return wrapper
992059
def apply_policy(self, policy):
        
        tenant_name = policy['tenant_name']
        fw_id = policy['fw_id']
        fw_name = policy['fw_name']
        LOG.info("asa_apply_policy: tenant=%(tenant)s fw_id=%(fw_id)s "
                 "fw_name=%(fw_name)s",
                 {'tenant': tenant_name, 'fw_id': fw_id, 'fw_name': fw_name})
        cmds = ["conf t", "changeto context " + tenant_name]

        for rule_id, rule in policy['rules'].items():
            acl = self.build_acl(tenant_name, rule)

            LOG.info("rule[%(rule_id)s]: name=%(name)s enabled=%(enabled)s"
                     " protocol=%(protocol)s dport=%(dport)s "
                     "sport=%(sport)s dip=%(dport)s "
                     "sip=%(sip)s action=%(dip)s",
                     {'rule_id': rule_id, 'name': rule.get('name'),
                      'enabled': rule.get('enabled'),
                      'protocol': rule.get('protocol'),
                      'dport': rule.get('dst_port'),
                      'sport': rule.get('src_port'),
                      'dip': rule.get('destination_ip_address'),
                      'sip': rule.get('source_ip_address'),
                      'action': rule.get('action')})

            # remove the old ace for this rule
            if rule_id in self.rule_tbl:
                cmds.append('no ' + self.rule_tbl[rule_id])

            self.rule_tbl[rule_id] = acl
            if tenant_name in self.tenant_rule:
                if rule_id not in self.tenant_rule[tenant_name]['rule_lst']:
                    self.tenant_rule[tenant_name]['rule_lst'].append(rule_id)
            cmds.append(acl)
        cmds.append("access-group " + tenant_name + " global")
        cmds.append("write memory")

        LOG.info("cmds sent is %s", cmds)
        data = {"commands": cmds}
        return self.rest_send_cli(data)
94669
def one_rule_present(self, pol_id):
        
        pol_dict = self.policies[pol_id]
        for rule in pol_dict['rule_dict']:
            if self.is_rule_present(rule):
                return True
        return False
13809
public Optional<SyntheticsAlertCondition> create(long policyId, SyntheticsAlertCondition condition)
    {
        return HTTP.POST(String.format("/v2/alerts_synthetics_conditions/policies/%d.json", policyId), condition, SYNTHETICS_ALERT_CONDITION);
    }
1056108
def enforce(self, rule, target, creds, exc=None, *args, **kwargs):
        """"""

        self.load_rules()

        if isinstance(rule, checks.BaseCheck):
            result = rule(target, creds, self, rule)
        elif not self.rules:
            # No rules means we're going to fail closed.
            result = False
        else:
            try:
                # Evaluate the rule
                result = self.rules[rule](target, creds, self, rule)
            except KeyError:
                LOG.debug('Rule [%s] does not exist', rule)
                # If the rule doesn't exist, fail closed
                result = False

        if self.raise_error and not result:
            if exc:
                raise exc(*args, **kwargs)
            else:
                raise PolicyNotAuthorized(rule, target, creds)

        return result
934854
def _set_rules(self, group, rules):
        """"""
        group.clear()

        for rule in rules:
            self._add_rule(group, *rule)

        self.invalidate()
1171926
def create_rule(*args, &block)
      pattern, args, deps = resolve_args(args)
      pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
      @rules << [pattern, args, deps, block]
    end
863647
def add_policy(self, name, policy_type, cooldown, change=None,
            is_percent=False, desired_capacity=None, args=None):
        
        return self.manager.add_policy(self, name, policy_type, cooldown,
                change=change, is_percent=is_percent,
                desired_capacity=desired_capacity, args=args)
803962
def create_alert_policy(self, policy_name):
    """"""
    policy_data = { 'policy': { 'incident_preference': 'PER_POLICY', 'name': policy_name } }
    create_policy = requests.post(
      'https://api.newrelic.com/v2/alerts_policies.json',
      headers=self.auth_header,
      data=json.dumps(policy_data))
    create_policy.raise_for_status()
    policy_id = create_policy.json()['policy']['id']
    self.refresh_all_alerts()
    return policy_id
338627
private MonitoringRule buildRelatedRule(IGuaranteeTerm guarantee) {
        
        MonitoringRule result = new MonitoringRule();
        result.setId(guarantee.getName());

        String violation = extractOutputMetric(guarantee);
        Parameter param = new Parameter();
        param.setName(QosModels.METRIC_PARAM_NAME);
        param.setValue(violation);
        
        Action action = new Action();
        action.setName(QosModels.OUTPUT_METRIC_ACTION);
        action.getParameters().add(param);
        
        Actions actions = new Actions();
        actions.getActions().add(action);
        
        result.setActions(actions);
        
        return result;
    }