Test Setup Failed
Push — master ( 63da58...9fdcd8 )
by -
01:30
created

scores_del()   A

Complexity

Conditions 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 14
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 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...
5
from sqlalchemy.exc import SQLAlchemyError
0 ignored issues
show
Configuration introduced by
The import sqlalchemy.exc 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...
6
7
from spike.model import Settings, db
8
from spike.model.naxsi_rules import ValueTemplates
9
10
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...
11
12
13
@settings.route("/")
14
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...
15
    _settings = Settings.query.order_by(Settings.name).all()
16
    if not _settings:
17
        return redirect("/rules")
18
    return render_template("settings/index.html", settings=_settings)
19
20
21
@settings.route("/mz")
22
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...
23
    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...
Bug introduced by
The Class ValueTemplates does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
24
    if not mz:
25
        return redirect("/settings")
26
    return render_template("settings/mz.html", mz=mz)
27
28
29
@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...
30
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...
31
    dmz = ValueTemplates.query.filter(ValueTemplates.id == request.form["mzid"]).first()
0 ignored issues
show
Bug introduced by
The Class ValueTemplates does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
32
    if not dmz:
33
        flash("Nothing found in %s " % (request.form["mzid"]), "error")
34
        return redirect("/settings/mz")
35
36
    db.session.delete(dmz)
37
    try:
38
        db.session.commit()
39
        flash("OK: deleted %s " % dmz.value, "success")
40
    except SQLAlchemyError:
41
        flash("ERROR while trying to delete : %s" % dmz.value, "error")
42
    return redirect("/settings/mz")
43
44
45
@settings.route("/mz/new", methods=["POST"])
46
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...
47
    db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"]))
48
    db.session.commit()
49
    flash("Updated MZ: %s" % request.form["nmz"], "success")
50
    return redirect("/settings/mz")
51
52
53
@settings.route("/scores")
54
def scores_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...
55
    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...
Bug introduced by
The Class ValueTemplates does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
56
    if not sc:
57
        return redirect("/settings")
58
    return render_template("settings/scores.html", scores=sc)
59
60
61
@settings.route("/scores/new", methods=["POST"])
62
def scores_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...
63
    if not request.form["nscore"].startswith("$"):
64
        request.form["nscore"] = '$' + request.form["nscore"]
65
66
    db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper()))
67
    db.session.commit()
68
    flash("Updated Score: %s" % request.form["nscore"], "success")
69
    return redirect("/settings/scores")
70
71
72
@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...
73
def scoress_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...
74
    dsc = ValueTemplates.query.filter(ValueTemplates.id == request.form["scid"]).first()
0 ignored issues
show
Bug introduced by
The Class ValueTemplates does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
75
    if not dsc:
76
        flash("Nothing found in %s " % (request.form["scid"]), "error")
77
        return redirect("/settings/scores")
78
    db.session.delete(dsc)
79
80
    try:
81
        db.session.commit()
82
        flash("OK: deleted %s " % dsc.value, "success")
83
    except SQLAlchemyError:
84
        flash("ERROR while trying to delete : %s" % dsc.value, "error")
85
    return redirect("/settings/scores")
86
87
@settings.route("/save", methods=["POST"])
88
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...
89
    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...
90
    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...
91
        sfind = Settings.query.filter(Settings.name == s).first()
92
        if not sfind:
93
            logging.error("no value for %s", sfind)
94
            continue
95
96
        if sfind.value != request.form[s]:
97
            sfind.value = request.form[s]
98
            db.session.add(sfind)
99
100
    flash("Updated setting: %s" % s, "success")
101
    db.session.commit()
102
    os.system("touch spike/__init__.py")
103
    return redirect("/settings")
104