How to use the rules.models.Ruleset.objects.all function in rules

To help you get started, we’ve selected a few rules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StamusNetworks / scirius / rules / models.py View on Github external
def needs_test(self):
        try:
            sourceatversion = SourceAtVersion.objects.get(source = self, version = 'HEAD')
        except:
            return
        rulesets = Ruleset.objects.all()
        for ruleset in rulesets:
            if sourceatversion in ruleset.sources.all():
                ruleset.needs_test()
github StamusNetworks / scirius / rules / forms.py View on Github external
def __init__(self, *args, **kwargs):
        super(RulesetChoiceForm, self).__init__(*args, **kwargs)
        ruleset_list =  Ruleset.objects.all()
        self.fields['rulesets'].queryset = ruleset_list

        if hasattr(self, 'rulesets_label'):
            self.fields['rulesets'].label = self.rulesets_label

        if not len(ruleset_list):
            if not (isinstance(self, AddSourceForm) or isinstance(self, AddPublicSourceForm)):
                self.errors[NON_FIELD_ERRORS] = ['Please create a ruleset first']
            self.fields.pop('rulesets')
github StamusNetworks / scirius / rules / views.py View on Github external
if form.is_valid(): # All validation rules pass
            rulesets = form.cleaned_data['rulesets']
            for ruleset in rulesets:
                suppressed_rules = ruleset.get_transformed_rules(key=Transformation.SUPPRESSED,
                                                                value=Transformation.S_SUPPRESSED).values_list('pk', flat=True)
                if rule_object.pk not in suppressed_rules and operation == 'disable' :
                    rule_object.disable(ruleset, user = request.user, comment=form.cleaned_data['comment'])
                elif rule_object.pk in suppressed_rules and operation == 'enable':
                    rule_object.enable(ruleset, user = request.user, comment=form.cleaned_data['comment'])
                ruleset.save()
            return redirect(rule_object)
    else:
        form = RulesetSuppressForm()

    context = { 'rule': rule_object, 'form': form }
    rulesets = Ruleset.objects.all()
    for ruleset in rulesets:
        ruleset.deps_rules = rule_object.get_dependant_rules(ruleset)
    context['rulesets'] = rulesets
    context['operation'] = operation
    return scirius_render(request, 'rules/disable_rule.html', context)
github StamusNetworks / scirius / rules / views.py View on Github external
else:
                UserAction.create(
                        action_type='create_source',
                        comment=form.cleaned_data['comment'],
                        user=request.user,
                        source=src,
                        ruleset='No Ruleset'
                )
            ruleset_list = [ '"' + ruleset.name + '"' for ruleset in ruleset_list ]
            return scirius_render(request, 'rules/add_public_source.html', { 'source': src,  'update': True, 'rulesets': rulesets, 'ruleset_list': ruleset_list})
        else:
            return scirius_render(request, 'rules/add_public_source.html', { 'form': form, 'error': 'form is not valid' })
        


    rulesets = Ruleset.objects.all()
    return scirius_render(request, 'rules/add_public_source.html', { 'sources': public_sources['sources'], 'rulesets': rulesets})
github StamusNetworks / scirius / rules / views.py View on Github external
if len(rulesets) == rulesets_res[key][val] or \
                        (None in rulesets_res[key] and
                         len(rulesets) == rulesets_res[key][val] + rulesets_res[key][None]):
                    pass
                else:
                    initial[key.value] = 'category'
                    if 'rulesets' in initial:
                        del initial['rulesets']

        form = RuleTransformForm(
                initial=initial,
                instance=rule_object)

    category_transforms = []
    ruleset_transforms = []
    rulesets = Ruleset.objects.all()

    for ruleset in rulesets:
        trans_cats_values = []
        trans_rulesets_values = []
        for trans_key in (Transformation.ACTION, Transformation.LATERAL, Transformation.TARGET):
            trans_cat_value = rule_object.category.get_transformation(ruleset, key=trans_key)
            trans_ruleset_value = ruleset.get_transformation(key=trans_key)

            if trans_cat_value:
                trans_cats_values.append('%s: %s' % (trans_key.name.title(), trans_cat_value.name.title()))

            if trans_ruleset_value:
                trans_rulesets_values.append('%s: %s' % (trans_key.name.title(), trans_ruleset_value.name.title()))

        if len(trans_cats_values) > 0:
            category_transforms.append({'category': rule_object.category, 'trans': " | ".join(trans_cats_values)})
github StamusNetworks / scirius / rules / views.py View on Github external
def index(request):
    ruleset_list = Ruleset.objects.all().order_by('-created_date')[:5]
    source_list = Source.objects.all().order_by('-created_date')[:5]
    context = {'ruleset_list': ruleset_list,
                'source_list': source_list}
    try:
        context['probes'] = map(lambda x: '"' +  x + '"', Probe.models.get_probe_hostnames())
    except:
        pass
    return scirius_render(request, 'rules/index.html', context)
github StamusNetworks / scirius / rules / rest_api.py View on Github external
raise serializers.ValidationError({'filters': ['Wrong filters: "%s"' % params_str]})

        # Check key/value filters
        # Key
        if key_str:
            if key_str not in Transformation.AVAILABLE_MODEL_TRANSFO.keys():
                raise serializers.ValidationError({'filters': ['Wrong filter type "%s".' % key_str]})

            # Value
            if value_str and value_str not in Transformation.AVAILABLE_MODEL_TRANSFO[key_str]:
                raise serializers.ValidationError({'filters': ['Wrong filter value "%s" for key "%s".' % (value_str, key_str)]})

        res = {}
        Rule.enable_cache()

        for ruleset in Ruleset.objects.all():
            trans_rules = RuleTransformation.objects.filter(ruleset=ruleset, **params)
            trans_cats = CategoryTransformation.objects.filter(ruleset=ruleset, **params)
            trans_rulesets = RulesetTransformation.objects.filter(ruleset_transformation=ruleset, **params)

            all_rules = set()
            key = Transformation.Type(key_str)
            value = None

            if key == Transformation.ACTION:
                value = Transformation.ActionTransfoType(value_str)
            elif key == Transformation.LATERAL:
                value = Transformation.LateralTransfoType(value_str)
            elif key == Transformation.TARGET:
                value = Transformation.TargetTransfoType(value_str)

            if ruleset.pk not in res:
github StamusNetworks / scirius / rules / views.py View on Github external
Transformation.TARGET: Transformation.T_RULESET_DEFAULT
        }

        rulesets_res = {
                Transformation.ACTION: {},
                Transformation.LATERAL: {},
                Transformation.TARGET: {},
        }

        initial = {'action': current_trans[Transformation.ACTION].value,
                   'lateral': current_trans[Transformation.LATERAL].value,
                   'target': current_trans[Transformation.TARGET].value,
                   'rulesets': rulesets_ids
                   }

        rulesets = Ruleset.objects.all()
        for ruleset in rulesets:
            trans_action = cat_object.get_transformation(ruleset, Transformation.ACTION)
            trans_lateral = cat_object.get_transformation(ruleset, Transformation.LATERAL)
            trans_target = cat_object.get_transformation(ruleset, Transformation.TARGET)
            all_trans = [(Transformation.ACTION, trans_action), (Transformation.LATERAL, trans_lateral), (Transformation.TARGET, trans_target)]

            for key, value in all_trans:
                if value not in rulesets_res[key]:
                    rulesets_res[key][value] = 0
                rulesets_res[key][value] += 1

                if value:
                    rulesets_ids.append(ruleset.id)
                    current_trans[key] = value

                # Case 1: One transfo on all rulesets