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

check_or_get_latest_sid()   B

Complexity

Conditions 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 5
dl 0
loc 22
rs 8.3411
1
from flask.ext.sqlalchemy import SQLAlchemy
2
3
db = SQLAlchemy()
4
5
from naxsi_rules import NaxsiRules, NaxsiRuleSets
6
from settings import Settings
7
8
9
def check_constraint(ctype, value):
10
    if ctype == "settings":
11
        cres = Settings.query.filter(Settings.name == value).first()
12
    elif ctype == "ruleset":
13
        cres = NaxsiRuleSets.query.filter(NaxsiRuleSets.file == value).first()
14
    else:
15
        cres = 1
16
17
    if not cres:
18
        return 0
19
    return (cres)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
20
21
22
def get_latest_sid():  # FIXME I'm ugly as fuck
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
23
    latest = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
24
    if latest is None:
25
        latest = Settings.query.filter(Settings.name == "rules_offset").first()
26
        return int(latest.value) + 1
27
    return latest.sid + 1
28