Test Failed
Push — master ( eefec5...2d7b9d )
by -
02:06
created

mz_new()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 6
rs 9.4285
1
import os
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import logging
3
4
from flask import current_app, Blueprint, render_template, request, redirect, flash
1 ignored issue
show
Configuration introduced by
The import flask 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...
Unused Code introduced by
Unused current_app imported from flask
Loading history...
5
6
from spike.model import Settings, ValueTemplates, db
7
8
settings = Blueprint('settings', __name__, url_prefix='/settings')
0 ignored issues
show
Coding Style Naming introduced by
The name settings does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

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...
9
10
11
@settings.route("/")
12
def index():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13
    _settings = Settings.query.order_by(Settings.name).all()
14
    if not _settings:
15
        return redirect("/rules")
16
    return render_template("settings/index.html", settings=_settings)
17
18
19
@settings.route("/mz")
20
def mz_index():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
21
    mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").order_by(ValueTemplates.value).all()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
22
    if not mz:
23
        return redirect("/settings")
24
    return render_template("settings/mz.html", mz=mz)
25
26
27
@settings.route("/mz/del", methods=["POST"])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
def mz_del():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
29
    dmz = ValueTemplates.query.filter(ValueTemplates.id == request.form["mzid"]).first()
30
    if not dmz:
31
        flash("Nothing found in %s " % (request.form["mzid"]), "error")
32
        return redirect("/settings/mz")
33
34
    db.session.delete(dmz)
35
    try:
36
        db.session.commit()
37
        flash("OK: deleted %s " % dmz.value, "success")
38
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
39
        flash("ERROR while trying to delete : %s" % dmz.value, "error")
40
    return redirect("/settings/mz")
41
42
43
@settings.route("/mz/new", methods=["POST"])
44
def mz_new():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
45
    db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"]))
46
    db.session.commit()
47
    flash("Updated MZ: %s" % request.form["nmz"], "success")
48
    return redirect("/settings/mz")
49
50
51
@settings.route("/scores")
52
def score_index():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
53
    sc = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").order_by(ValueTemplates.value).all()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name sc does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
54
    if not sc:
55
        return redirect("/settings")
56
    return render_template("settings/scores.html", scores=sc)
57
58
59
@settings.route("/scores/new", methods=["POST"])
60
def score_new():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
61
    if not request.form["nscore"].startswith("$"):
62
        request.form["nscore"] = '$' + request.form["nscore"]
63
64
    db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper()))
65
    db.session.commit()
66
    flash("Updated Score: %s" % request.form["nscore"], "success")
67
    return redirect("/settings/scores")
68
69
70
@settings.route("/scores/del", methods=["POST"])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
def scores_del():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
72
    dsc = ValueTemplates.query.filter(ValueTemplates.id == request.form["scid"]).first()
73
    if not dsc:
74
        flash("Nothing found in %s " % (request.form["scid"]), "error")
75
        return redirect("/settings/scores")
76
    db.session.delete(dsc)
77
78
    try:
79
        db.session.commit()
80
        flash("OK: deleted %s " % dsc.value, "success")
81
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
82
        flash("ERROR while trying to delete : %s" % dsc.value, "error")
83
    return redirect("/settings/scores")
84
85
@settings.route("/save", methods=["POST"])
86
def save_settings():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
87
    s = ''
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
88
    for s in request.form:
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
89
        sfind = Settings.query.filter(Settings.name == s).first()
90
        if not sfind:
91
            logging.error("no value for %s", sfind)
92
            continue
93
94
        if sfind.value != request.form[s]:
95
            sfind.value = request.form[s]
96
            db.session.add(sfind)
97
98
    flash("Updated setting: %s" % s, "success")
99
    db.session.commit()
100
    os.system("touch spike/__init__.py")
101
    return redirect("/settings")
102