Test Setup Failed
Push — master ( 9fdcd8...5b10e8 )
by -
01:16
created

save_settings()   A

Complexity

Conditions 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 17
rs 9.2
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...
Unused Code introduced by
The import os seems to be unused.
Loading history...
2
import logging
0 ignored issues
show
Unused Code introduced by
The import logging seems to be unused.
Loading history...
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 db
8
from spike.model.naxsi_rules import ValueTemplates
9
10
settings = Blueprint('settings', __name__)
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("/mz")
14
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...
15
    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...
16
    if not mz:
17
        return redirect("/settings")
18
    return render_template("settings/mz.html", mz=mz)
19
20
21
@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...
22
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...
23
    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...
24
    if not dmz:
25
        flash("Nothing found in %s " % (request.form["mzid"]), "error")
26
        return redirect("/settings/mz")
27
28
    db.session.delete(dmz)
29
    try:
30
        db.session.commit()
31
        flash("OK: deleted %s " % dmz.value, "success")
32
    except SQLAlchemyError:
33
        flash("ERROR while trying to delete : %s" % dmz.value, "error")
34
    return redirect("/settings/mz")
35
36
37
@settings.route("/mz/new", methods=["POST"])
38
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...
39
    db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"]))
40
    db.session.commit()
41
    flash("Updated MZ: %s" % request.form["nmz"], "success")
42
    return redirect("/settings/mz")
43
44
45
@settings.route("/scores")
46
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...
47
    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...
48
    if not sc:
49
        return redirect("/settings")
50
    return render_template("settings/scores.html", scores=sc)
51
52
53
@settings.route("/scores/new", methods=["POST"])
54
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...
55
    if not request.form["nscore"].startswith("$"):
56
        request.form["nscore"] = '$' + request.form["nscore"]
57
58
    db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper()))
59
    db.session.commit()
60
    flash("Updated Score: %s" % request.form["nscore"], "success")
61
    return redirect("/settings/scores")
62
63
64
@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...
65
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...
66
    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...
67
    if not dsc:
68
        flash("Nothing found in %s " % (request.form["scid"]), "error")
69
        return redirect("/settings/scores")
70
    db.session.delete(dsc)
71
72
    try:
73
        db.session.commit()
74
        flash("OK: deleted %s " % dsc.value, "success")
75
    except SQLAlchemyError:
76
        flash("ERROR while trying to delete : %s" % dsc.value, "error")
77
    return redirect("/settings/scores")
78