Skip to content

Commit de61c8f

Browse files
authored
Merge pull request #12 from mattvaldes/master
Add support for custom DefectDojo URL prefix
2 parents a4bb016 + c329c28 commit de61c8f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

defectdojo_api/defectdojo.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def __init__(self, host, api_key, user, api_version='v1', verify_ssl=True, timeo
3333
self.verify_ssl = verify_ssl
3434
self.proxies = proxies
3535
self.timeout = timeout
36+
37+
if host.split('/') > 3:
38+
self.custom_path = '/' + '/'.join(host.split('/')[3:]).rstrip('/')
39+
else:
40+
self.custom_path = ''
3641

3742
if not user_agent:
3843
self.user_agent = 'DefectDojo_api/' + version
@@ -46,46 +51,47 @@ def __init__(self, host, api_key, user, api_version='v1', verify_ssl=True, timeo
4651
requests.packages.urllib3.disable_warnings() # Disabling SSL warning messages if verification is disabled.
4752

4853
###### Helper Functions ######
54+
4955
def get_user_uri(self, user_id):
5056
"""Returns the DefectDojo API URI for a user.
5157
5258
:param user_id: Id of the user
5359
5460
"""
5561

56-
return "/api/" + self.api_version + "/users/" + str(user_id) + "/"
62+
return self.custom_path + "/api/" + self.api_version + "/users/" + str(user_id) + "/"
5763

5864
def get_engagement_uri(self, engagement_id):
5965
"""Returns the DefectDojo API URI for an engagement.
6066
6167
:param engagement_id: Id of the engagement
6268
6369
"""
64-
return "/api/" + self.api_version + "/engagements/" + str(engagement_id) + "/"
70+
return self.custom_path + "/api/" + self.api_version + "/engagements/" + str(engagement_id) + "/"
6571

6672
def get_product_uri(self, product_id):
6773
"""Returns the DefectDojo API URI for a product.
6874
6975
:param product_id: Id of the product
7076
7177
"""
72-
return "/api/" + self.api_version + "/products/" + str(product_id) + "/"
78+
return self.custom_path + "/api/" + self.api_version + "/products/" + str(product_id) + "/"
7379

7480
def get_test_uri(self, test_id):
7581
"""Returns the DefectDojo API URI for a test.
7682
7783
:param test_id: Id of the test
7884
7985
"""
80-
return "/api/" + self.api_version + "/tests/" + str(test_id) + "/"
86+
return self.custom_path + "/api/" + self.api_version + "/tests/" + str(test_id) + "/"
8187

8288
def get_language_uri(self, language_type_id):
8389
"""Returns the DefectDojo API URI for a langauge.
8490
8591
:param test_id: Id of the language
8692
8793
"""
88-
return "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"
94+
return self.custom_path + "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"
8995

9096
def get_tool_configuration_uri(self, tool_configuration_id):
9197
"""Returns the DefectDojo API URI for a tool.

0 commit comments

Comments
 (0)