|
20 | 20 | import crum |
21 | 21 | import cvss |
22 | 22 | import vobject |
23 | | -from asteval import Interpreter |
24 | 23 | from auditlog.models import LogEntry |
25 | 24 | from cryptography.hazmat.backends import default_backend |
26 | 25 | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes |
@@ -1224,6 +1223,26 @@ def get_setting(setting): |
1224 | 1223 | return getattr(settings, setting) |
1225 | 1224 |
|
1226 | 1225 |
|
| 1226 | +def grade_product(crit, high, med, low): |
| 1227 | + health = 100 |
| 1228 | + if crit > 0: |
| 1229 | + health = 40 |
| 1230 | + health -= ((crit - 1) * 5) |
| 1231 | + if high > 0: |
| 1232 | + if health == 100: |
| 1233 | + health = 60 |
| 1234 | + health -= ((high - 1) * 3) |
| 1235 | + if med > 0: |
| 1236 | + if health == 100: |
| 1237 | + health = 80 |
| 1238 | + health -= ((med - 1) * 2) |
| 1239 | + if low > 0: |
| 1240 | + if health == 100: |
| 1241 | + health = 95 |
| 1242 | + health -= low |
| 1243 | + return max(health, 5) |
| 1244 | + |
| 1245 | + |
1227 | 1246 | @dojo_model_to_id |
1228 | 1247 | @dojo_async_task(signature=True) |
1229 | 1248 | @app.task |
@@ -1276,17 +1295,14 @@ def calculate_grade_internal(product, *args, **kwargs): |
1276 | 1295 | medium = severity_count["numerical_severity__count"] |
1277 | 1296 | elif severity_count["severity"] == "Low": |
1278 | 1297 | low = severity_count["numerical_severity__count"] |
1279 | | - aeval = Interpreter() |
1280 | | - aeval(system_settings.product_grade) |
1281 | | - grade_product = f"grade_product({critical}, {high}, {medium}, {low})" |
1282 | | - prod_numeric_grade = aeval(grade_product) |
1283 | | - if prod_numeric_grade != product.prod_numeric_grade: |
1284 | | - logger.debug("Updating product %s grade from %s to %s", product.id, product.prod_numeric_grade, prod_numeric_grade) |
1285 | | - product.prod_numeric_grade = prod_numeric_grade |
| 1298 | + grade = grade_product(critical, high, medium, low) |
| 1299 | + if grade != product.prod_numeric_grade: |
| 1300 | + logger.debug("Updating product %s grade from %s to %s", product.id, product.prod_numeric_grade, grade) |
| 1301 | + product.prod_numeric_grade = grade |
1286 | 1302 | super(Product, product).save() |
1287 | 1303 | else: |
1288 | 1304 | # Use %s to safely handle None grades without formatter errors |
1289 | | - logger.debug("Product %s grade %s is up to date", product.id, prod_numeric_grade) |
| 1305 | + logger.debug("Product %s grade %s is up to date", product.id, product.prod_numeric_grade) |
1290 | 1306 |
|
1291 | 1307 |
|
1292 | 1308 | def perform_product_grading(product): |
|
0 commit comments