NaxsiWhitelist.parse()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 2
rs 10
ccs 2
cts 2
cp 1
crap 1
1 1
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
2 1
from shlex import shlex
0 ignored issues
show
Unused Code introduced by
Unused shlex imported from shlex
Loading history...
3
4 1
from flask import url_for
0 ignored issues
show
Unused Code introduced by
Unused url_for imported from flask
Loading history...
5
6 1
from spike.model import db
7 1
from spike.model.naxsi_rules import NaxsiRules
0 ignored issues
show
Unused Code introduced by
Unused NaxsiRules imported from spike.model.naxsi_rules
Loading history...
8
9 1
from nxapi import whitelist
0 ignored issues
show
Configuration introduced by
The import nxapi could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
10
11
12 1
class NaxsiWhitelist(db.Model):
13 1
    __bind_key__ = 'rules'
14 1
    __tablename__ = 'naxsi_whitelist'
15
16 1
    id = db.Column(db.Integer, primary_key=True)
17 1
    wl = db.Column(db.String, nullable=False)
18 1
    mz = db.Column(db.String(1024), nullable=False)
19 1
    negative = db.Column(db.Integer, nullable=False, server_default='0')
20 1
    active = db.Column(db.Integer, nullable=False, server_default='1')
21 1
    timestamp = db.Column(db.Integer, nullable=False)
22 1
    whitelistset = db.Column(db.String(1024), nullable=False)
23
24 1
    def __init__(self, wl='0', mz='', active=0, negative=0, whitelistset='', timestamp=0):
25 1
        self.wl = wl
26 1
        self.mz = mz
27 1
        self.active = active
28 1
        self.negative = negative
29 1
        self.whitelistset = whitelistset
30 1
        self.timestamp = timestamp
31 1
        self.warnings = []
32 1
        self.errors = []
33
34 1
    def from_dict(self, d):
0 ignored issues
show
Coding Style Naming introduced by
The name d does not conform to the argument naming conventions ([a-z_][a-z0-9_]{1,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
35 1
        for key, value in d.items():
36 1
            setattr(self, key, value)
37 1
        return self
38
39 1
    def __str__(self):
40 1
        return 'BasicRule {} wl:{} "mz:{}";'.format('negative' if self.negative else '', self.wl, self.mz)
41
42 1
    def parse(self, str_wl):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
43 1
        return whitelist.parse(str_wl)
44
45 1
    def validate(self):
46 1
        return whitelist.validate(self.__dict__)
47
48 1
    def explain(self):
49
        return whitelist.explain(self.__dict__)
50