Skip to content

Commit a4bb016

Browse files
committed
Updating for 1.4 DefectDojo release
1 parent cf9f3cd commit a4bb016

File tree

7 files changed

+146
-20
lines changed

7 files changed

+146
-20
lines changed

defectdojo_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.1.3'
1+
__version__ = '1.1.4'

defectdojo_api/__init__.pyc

0 Bytes
Binary file not shown.

defectdojo_api/defectdojo.py

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,21 @@ def get_test_uri(self, test_id):
8080
return "/api/" + self.api_version + "/tests/" + str(test_id) + "/"
8181

8282
def get_language_uri(self, language_type_id):
83-
"""Returns the DefectDojo API URI for a test.
83+
"""Returns the DefectDojo API URI for a langauge.
8484
85-
:param test_id: Id of the test
85+
:param test_id: Id of the language
8686
8787
"""
8888
return "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"
8989

90+
def get_tool_configuration_uri(self, tool_configuration_id):
91+
"""Returns the DefectDojo API URI for a tool.
92+
93+
:param tool_configurations_id: Id of the test
94+
95+
"""
96+
return "/api/" + self.api_version + "/tool_configurations/" + str(tool_configuration_id) + "/"
97+
9098
def version_url(self):
9199
"""Returns the DefectDojo API version.
92100
@@ -162,8 +170,9 @@ def get_engagement(self, engagement_id):
162170
return self._request('GET', 'engagements/' + str(engagement_id) + '/')
163171

164172
def create_engagement(self, name, product_id, lead_id, status, target_start, target_end, active='True',
165-
pen_test='False', check_list='False', threat_model='False', risk_path="", test_strategy="", progress="",
166-
done_testing='False'):
173+
pen_test='False', check_list='False', threat_model='False', risk_path="",test_strategy="", progress="",
174+
done_testing='False', engagement_type="CI/CD", build_id=None, commit_hash=None, branch_tag=None, build_server=None,
175+
source_code_management_server=None, source_code_management_uri=None, orchestration_engine=None, description=None):
167176
"""Creates an engagement with the given properties.
168177
169178
:param name: Engagement name.
@@ -179,6 +188,14 @@ def create_engagement(self, name, product_id, lead_id, status, target_start, tar
179188
:param risk_path: risk_path
180189
:param test_strategy: Test Strategy URLs
181190
:param progress: Engagement progresss measured in percent.
191+
:param engagement_type: Interactive or CI/CD
192+
:param build_id: Build id from the build server
193+
:param commit_hash: Commit hash from source code management
194+
:param branch_tag: Branch or tag from source code management
195+
:param build_server: Tool Configuration id of build server
196+
:param source_code_management_server: URL of source code management
197+
:param source_code_management_uri: Link to source code commit
198+
:param orchestration_engine: URL of orchestration engine
182199
183200
"""
184201

@@ -196,9 +213,34 @@ def create_engagement(self, name, product_id, lead_id, status, target_start, tar
196213
'risk_path': risk_path,
197214
'test_strategy': test_strategy,
198215
'progress': progress,
199-
'done_testing': done_testing
216+
'done_testing': done_testing,
217+
'engagement_type': engagement_type
200218
}
201219

220+
if description:
221+
data.update({'description': description})
222+
223+
if build_id:
224+
data.update({'build_id': build_id})
225+
226+
if commit_hash:
227+
data.update({'commit_hash': commit_hash})
228+
229+
if branch_tag:
230+
data.update({'branch_tag': branch_tag})
231+
232+
if build_server:
233+
data.update({'build_server': self.get_tool_configuration_uri(build_server)})
234+
235+
if source_code_management_server:
236+
data.update({'source_code_management_server': self.get_tool_configuration_uri(source_code_management_server)})
237+
238+
if source_code_management_uri:
239+
data.update({'source_code_management_uri': source_code_management_uri})
240+
241+
if orchestration_engine:
242+
data.update({'orchestration_engine': self.get_tool_configuration_uri(orchestration_engine)})
243+
202244
return self._request('POST', 'engagements/', data=data)
203245

204246
def close_engagement(self, id, user_id=None):
@@ -207,19 +249,13 @@ def close_engagement(self, id, user_id=None):
207249
:param id: Engagement id.
208250
:param user_id: User from the user table.
209251
"""
210-
engagement = self.get_engagement(id).data
211-
212-
#if user isn't provided then close with the lead ID
213-
if user_id is None:
214-
user_id = self.get_id_from_url(engagement["lead"])
215252

216-
product_id = engagement["product_id"]
217-
218-
self.set_engagement(id, name=engagement["name"], lead_id=user_id, product_id=product_id, status="Completed", active=False)
253+
self.set_engagement(id, status="Completed", active=False)
219254

220255
def set_engagement(self, id, product_id=None, lead_id=None, name=None, status=None, target_start=None,
221256
target_end=None, active=None, pen_test=None, check_list=None, threat_model=None, risk_path=None,
222-
test_strategy=None, progress=None, done_testing=None):
257+
test_strategy=None, progress=None, done_testing=None, engagement_type="CI/CD", build_id=None, commit_hash=None, branch_tag=None, build_server=None,
258+
source_code_management_server=None, source_code_management_uri=None, orchestration_engine=None, description=None):
223259

224260
"""Updates an engagement with the given properties.
225261
@@ -237,7 +273,14 @@ def set_engagement(self, id, product_id=None, lead_id=None, name=None, status=No
237273
:param risk_path: risk_path
238274
:param test_strategy: Test Strategy URLs
239275
:param progress: Engagement progresss measured in percent.
240-
276+
:param engagement_type: Interactive or CI/CD
277+
:param build_id: Build id from the build server
278+
:param commit_hash: Commit hash from source code management
279+
:param branch_tag: Branch or tag from source code management
280+
:param build_server: Tool Configuration id of build server
281+
:param source_code_management_server: URL of source code management
282+
:param source_code_management_uri: Link to source code commit
283+
:param orchestration_engine: URL of orchestration engine
241284
"""
242285

243286
data = {}
@@ -284,7 +327,7 @@ def set_engagement(self, id, product_id=None, lead_id=None, name=None, status=No
284327
if done_testing:
285328
data['done_testing'] = done_testing
286329

287-
return self._request('PUT', 'engagements/' + str(id) + '/', data=data)
330+
return self._request('PATCH', 'engagements/' + str(id) + '/', data=data)
288331

289332
###### Product API #######
290333
def list_products(self, name=None, name_contains=None, limit=20):

defectdojo_api/defectdojo.pyc

6.31 KB
Binary file not shown.

examples/.DS_Store

-2 KB
Binary file not shown.

examples/dojo_languages.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Example written by Aaron Weaver <[email protected]>
3+
as part of the OWASP DefectDojo and OWASP AppSec Pipeline Security projects
4+
5+
Description: Creates a product in DefectDojo and returns information about the newly created product
6+
"""
7+
from defectdojo_api import defectdojo
8+
9+
import os
10+
import json
11+
12+
# Setup DefectDojo connection information
13+
host = 'http://localhost:8000'
14+
api_key = os.environ['DOJO_API_KEY']
15+
user = 'admin'
16+
17+
"""
18+
#Optionally, specify a proxy
19+
proxies = {
20+
'http': 'http://localhost:8080',
21+
'https': 'http://localhost:8080',
22+
}
23+
proxies=proxies
24+
"""
25+
26+
# Instantiate the DefectDojo api wrapper
27+
dd = defectdojo.DefectDojoAPI(host, api_key, user, debug=True)
28+
29+
# Add languages to a product
30+
product_id = 1
31+
language_type_id = 3
32+
user_id = 1
33+
34+
dd.delete_all_app_analysis_product(product_id)
35+
36+
#language =
37+
data = json.load(open('/tmp/wap.json'))
38+
for app in data["applications"]:
39+
name = app["name"]
40+
confidence = app["confidence"]
41+
version = app["version"]
42+
icon = app["icon"]
43+
website = app["website"]
44+
45+
dd.create_app_analysis(product_id, user_id, name, confidence, version, icon, website)
46+
"""
47+
#language =
48+
data = json.load(open('/Users/aweaver/git/AppSecPipelineReports/4cd987e4-6550-48c7-815c-21cf0c4f33fe/reports/cloc/languages.json'))
49+
50+
for language in data:
51+
if "header" not in language and "SUM" not in language:
52+
print data[language]["code"]
53+
files = data[language]['nFiles']
54+
code = data[language]['code']
55+
blank = data[language]['blank']
56+
comment = data[language]['comment']
57+
dd.create_language(product_id, user_id, files, code, blank, comment, language_name=language)
58+
59+
#dd.delete_language(1)
60+
languages = dd.list_language_types(language_name="Python")
61+
62+
if languages.success:
63+
for language in languages.data["objects"]:
64+
print language['resource_uri']
65+
"""
66+
#language_product = dd.list_languages(product_id=1)
67+
#dd.delete_all_languages_product(1)
68+
#print language_product
69+
"""
70+
# List Products
71+
products = dd.list_products()
72+
73+
if products.success:
74+
#print(products.data_json(pretty=True)) # Decoded JSON object
75+
print "********************************"
76+
print "Total Number of Products: " + str(products.data["meta"]["total_count"])
77+
print "********************************"
78+
79+
for product in products.data["objects"]:
80+
print(product['id'])
81+
print(product['name']) # Print the name of each product
82+
print(product['description'])
83+
print "******************"
84+
else:
85+
print products.message
86+
"""

examples/dojo_zap.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
print "Creds"
3939
print list_credentials.data_json(pretty=True)
4040

41-
list_containers = dd.list_containers()
42-
print "Containers"
43-
print list_containers.data_json(pretty=True)
4441
# Search Tool Types by Name
4542
tool_types = dd.list_tool_types(name="Source Code Repository")
4643

0 commit comments

Comments
 (0)