Skip to content

Commit

Permalink
Adding language and app info
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronweaver committed Mar 13, 2018
1 parent bd186ec commit 9db7d60
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 15 deletions.
2 changes: 1 addition & 1 deletion defectdojo_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.1'
__version__ = '1.1.2'
159 changes: 145 additions & 14 deletions defectdojo_api/defectdojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def get_test_uri(self, test_id):
"""
return "/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) + "/"

def version_url(self):
"""Returns the DefectDojo API version.
Expand Down Expand Up @@ -780,13 +788,13 @@ def get_credential_mapping(self, cred_mapping_id, limit=20):
"""
return self._request('GET', 'credential_mappings/' + str(cred_mapping_id) + '/')

##### Container API #####

def list_containers(self, name=None, container_type=None, limit=20):
"""Retrieves all the globally configured credentials.
##### App Analysis API #####
def list_app_analysis(self, id=None, product_id=None, name=None, limit=20):
"""Retrieves source code languages.
:param name_contains: Search by credential name.
:param username: Search by username
:param id: Search by lanaguage id.
:param product: Search by product id
:param language_name: Search by language name
:param limit: Number of records to return.
"""
Expand All @@ -795,20 +803,143 @@ def list_containers(self, name=None, container_type=None, limit=20):
if limit:
params['limit'] = limit

if id:
params['id'] = id

if product_id:
params['product__id'] = product_id

if name:
params['name__contains'] = name
params['name__icontains'] = language_name

return self._request('GET', 'app_analysis/', params)

def create_app_analysis(self, product_id, user_id, name, confidence, version, icon, website):
"""
Create a application analysis to product mapping.
:param id: Language identification.
"""

data = {
'product': self.get_product_uri(product_id),
'user': self.get_user_uri(user_id),
'name': name,
'confidence': confidence,
'version': version,
'icon': icon,
'website': website
}

return self._request('POST', 'app_analysis/', data=data)

def delete_app_analysis(self, id):
"""
Deletes an app analysis using the given id.
:param id: Language identification.
"""
return self._request('DELETE', 'app_analysis/' + str(id) + '/')

def delete_all_app_analysis_product(self, product_id):
"""
Delete all app analysis using the given id.
:product_id id: Product to remove
"""
app_analysis = self.list_app_analysis(product_id=product_id)

if app_analysis.success:
for app in app_analysis.data["objects"]:
self.delete_app_analysis(self.get_id_from_url(app['resource_uri']))

##### Language API #####

def list_languages(self, id=None, product_id=None, language_name=None, limit=20):
"""Retrieves source code languages.
:param id: Search by lanaguage id.
:param product: Search by product id
:param language_name: Search by language name
:param limit: Number of records to return.
if container_type:
params['container_type__contains'] = container_type
"""

params = {}
if limit:
params['limit'] = limit

if id:
params['id'] = id

if product_id:
params['product__id'] = product_id

if language_name:
params['language_type__language__icontains'] = language_name

return self._request('GET', 'languages/', params)

def create_language(self, product_id, user_id, files, code, blank, comment, language_type_id=None, language_name=None):
"""
Create a language to product mapping.
:param product_id: Product identification.
"""
#If language name specified then lookup
if language_name:
languages = self.list_language_types(language_name=language_name)

if languages.success:
for language in languages.data["objects"]:
language_type = language['resource_uri']

data = {
'product': self.get_product_uri(product_id),
'language_type': language_type,
'user': self.get_user_uri(user_id),
'files': files,
'code': code,
'blank': blank,
'comment': comment
}

return self._request('POST', 'languages/', data=data)

return self._request('GET', 'container/', params)
def delete_language(self, id):
"""
Deletes a language using the given id.
:param id: Language identification.
"""
return self._request('DELETE', 'languages/' + str(id) + '/')

def get_container(self, container_id, limit=20):
def delete_all_languages_product(self, product_id):
"""
Retrieves a finding using the given container id.
:param container_id: Container identification.
Delete all languages for a given product id.
:param id: Language identification.
"""
languages = self.list_languages(product_id=product_id)

if languages.success:
for language in languages.data["objects"]:
self.delete_language(self.get_id_from_url(language['resource_uri']))

def list_language_types(self, id=None, language_name=None, limit=20):
"""Retrieves source code languages.
:param id: Search by lanaguage id.
:param language_name: Search by language name
:param limit: Number of records to return.
"""
return self._request('GET', 'container/' + str(container_id) + '/')

params = {}
if limit:
params['limit'] = limit

if id:
params['id'] = id

if language_name:
params['language__icontains'] = language_name

return self._request('GET', 'language_types/', params)

###### Tool API #######

Expand Down

0 comments on commit 9db7d60

Please sign in to comment.