Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom DefectDojo URL prefix #12

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions defectdojo_api/defectdojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def __init__(self, host, api_key, user, api_version='v1', verify_ssl=True, timeo
self.verify_ssl = verify_ssl
self.proxies = proxies
self.timeout = timeout

if host.split('/') > 3:
self.custom_path = '/' + '/'.join(host.split('/')[3:]).rstrip('/')
else:
self.custom_path = ''

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

###### Helper Functions ######

def get_user_uri(self, user_id):
"""Returns the DefectDojo API URI for a user.

:param user_id: Id of the user

"""

return "/api/" + self.api_version + "/users/" + str(user_id) + "/"
return self.custom_path + "/api/" + self.api_version + "/users/" + str(user_id) + "/"

def get_engagement_uri(self, engagement_id):
"""Returns the DefectDojo API URI for an engagement.

:param engagement_id: Id of the engagement

"""
return "/api/" + self.api_version + "/engagements/" + str(engagement_id) + "/"
return self.custom_path + "/api/" + self.api_version + "/engagements/" + str(engagement_id) + "/"

def get_product_uri(self, product_id):
"""Returns the DefectDojo API URI for a product.

:param product_id: Id of the product

"""
return "/api/" + self.api_version + "/products/" + str(product_id) + "/"
return self.custom_path + "/api/" + self.api_version + "/products/" + str(product_id) + "/"

def get_test_uri(self, test_id):
"""Returns the DefectDojo API URI for a test.

:param test_id: Id of the test

"""
return "/api/" + self.api_version + "/tests/" + str(test_id) + "/"
return self.custom_path + "/api/" + self.api_version + "/tests/" + str(test_id) + "/"

def get_language_uri(self, language_type_id):
"""Returns the DefectDojo API URI for a test.

:param test_id: Id of the test

"""
return "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"
return self.custom_path + "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"

def version_url(self):
"""Returns the DefectDojo API version.
Expand Down