Skip to content

Commit 67202ed

Browse files
committed
adds model Finding_Template to the API.
1 parent 1d9b9c3 commit 67202ed

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

dojo/api.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from tastypie.validation import CleanedDataFormValidation
1111

1212
from dojo.models import Product, Engagement, Test, Finding, \
13-
User, ScanSettings, IPScan, Scan, Stub_Finding, Risk_Acceptance
13+
User, ScanSettings, IPScan, Scan, Stub_Finding, Risk_Acceptance, Finding_Template
1414
from dojo.forms import ProductForm, EngForm2, TestForm, \
15-
ScanSettingsForm, FindingForm, StubFindingForm
15+
ScanSettingsForm, FindingForm, StubFindingForm, FindingTemplateForm
1616

1717
"""
1818
Setup logging for the api
@@ -420,7 +420,7 @@ class FindingResource(BaseModelResource):
420420
class Meta:
421421
resource_name = 'findings'
422422
queryset = Finding.objects.select_related("test")
423-
# deleting of findings is not allowed via UI or API.
423+
# deleting of findings is not allowed via API.
424424
# Admin interface can be used for this.
425425
list_allowed_methods = ['get', 'post']
426426
detail_allowed_methods = ['get', 'post', 'put']
@@ -458,6 +458,55 @@ def dehydrate(self, bundle):
458458
"/api/v1/products/%s/" % engagement[0].product.id
459459
return bundle
460460

461+
"""
462+
/api/v1/finding_templates/
463+
GET [/id/], DELETE [/id/]
464+
Expects: no params or test_id
465+
Returns test: ALL or by test_id
466+
Relevant apply filter ?active=True, ?id=?, ?severity=?
467+
468+
POST, PUT [/id/]
469+
Expects *title, *severity, *description, *mitigation, *impact,
470+
*endpoint, *test, cwe, active, false_p, verified,
471+
mitigated, *reporter
472+
473+
"""
474+
475+
476+
class FindingTemplateResource(BaseModelResource):
477+
478+
class Meta:
479+
resource_name = 'finding_templates'
480+
queryset = Finding_Template.objects.all()
481+
excludes= ['numerical_severity']
482+
# deleting of Finding_Template is not allowed via API.
483+
# Admin interface can be used for this.
484+
list_allowed_methods = ['get', 'post']
485+
detail_allowed_methods = ['get', 'post', 'put']
486+
include_resource_uri = True
487+
"""
488+
title = models.TextField(max_length=1000)
489+
cwe = models.IntegerField(default=None, null=True, blank=True)
490+
severity = models.CharField(max_length=200, null=True, blank=True)
491+
description = models.TextField(null=True, blank=True)
492+
mitigation = models.TextField(null=True, blank=True)
493+
impact = models.TextField(null=True, blank=True)
494+
references = models.TextField(null=True, blank=True, db_column="refs")
495+
numerical_severity
496+
"""
497+
filtering = {
498+
'id': ALL,
499+
'title': ALL,
500+
'cwe': ALL,
501+
'severity': ALL,
502+
'description': ALL,
503+
'mitigated': ALL,
504+
}
505+
authentication = DojoApiKeyAuthentication()
506+
authorization = DjangoAuthorization()
507+
serializer = Serializer(formats=['json'])
508+
validation = CleanedDataFormValidation(form_class=FindingTemplateForm)
509+
461510

462511
class StubFindingResource(BaseModelResource):
463512
reporter = fields.ForeignKey(UserResource, 'reporter', null=False)

dojo/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ class Finding_Template(models.Model):
687687
mitigation = models.TextField(null=True, blank=True)
688688
impact = models.TextField(null=True, blank=True)
689689
references = models.TextField(null=True, blank=True, db_column="refs")
690-
numerical_severity = models.CharField(max_length=4, null=True, blank=True)
690+
numerical_severity = models.CharField(max_length=4, null=True, blank=True, editable=False)
691691

692692
SEVERITIES = {'Info': 4, 'Low': 3, 'Medium': 2,
693693
'High': 1, 'Critical': 0}
@@ -870,6 +870,7 @@ def save(self, *args, **kwargs):
870870
auditlog.register(Product)
871871
auditlog.register(Test)
872872
auditlog.register(Risk_Acceptance)
873+
auditlog.register(Finding_Template)
873874

874875
# Register tagging for models
875876
tag_register(Product)

dojo/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dojo import views
77
from dojo.ajax import StubFindingResource as ajax_stub_finding_resource
88
from dojo.api import UserResource, ProductResource, EngagementResource, \
9-
TestResource, FindingResource, ScanSettingsResource, ScanResource, StubFindingResource
9+
TestResource, FindingResource, ScanSettingsResource, ScanResource, StubFindingResource, FindingTemplateResource
1010
from dojo.development_environment.urls import urlpatterns as dev_env_urls
1111
from dojo.endpoint.urls import urlpatterns as endpoint_urls
1212
from dojo.engagement.urls import urlpatterns as eng_urls
@@ -34,6 +34,7 @@
3434
v1_api.register(EngagementResource())
3535
v1_api.register(TestResource())
3636
v1_api.register(FindingResource())
37+
v1_api.register(FindingTemplateResource())
3738
v1_api.register(ScanSettingsResource())
3839
v1_api.register(ScanResource())
3940
v1_api.register(StubFindingResource())

0 commit comments

Comments
 (0)