Skip to content

Commit 9db7d60

Browse files
committed
Adding language and app info
1 parent bd186ec commit 9db7d60

File tree

2 files changed

+146
-15
lines changed

2 files changed

+146
-15
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.1'
1+
__version__ = '1.1.2'

defectdojo_api/defectdojo.py

Lines changed: 145 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def get_test_uri(self, test_id):
7979
"""
8080
return "/api/" + self.api_version + "/tests/" + str(test_id) + "/"
8181

82+
def get_language_uri(self, language_type_id):
83+
"""Returns the DefectDojo API URI for a test.
84+
85+
:param test_id: Id of the test
86+
87+
"""
88+
return "/api/" + self.api_version + "/language_types/" + str(language_type_id) + "/"
89+
8290
def version_url(self):
8391
"""Returns the DefectDojo API version.
8492
@@ -780,13 +788,13 @@ def get_credential_mapping(self, cred_mapping_id, limit=20):
780788
"""
781789
return self._request('GET', 'credential_mappings/' + str(cred_mapping_id) + '/')
782790

783-
##### Container API #####
784-
785-
def list_containers(self, name=None, container_type=None, limit=20):
786-
"""Retrieves all the globally configured credentials.
791+
##### App Analysis API #####
792+
def list_app_analysis(self, id=None, product_id=None, name=None, limit=20):
793+
"""Retrieves source code languages.
787794
788-
:param name_contains: Search by credential name.
789-
:param username: Search by username
795+
:param id: Search by lanaguage id.
796+
:param product: Search by product id
797+
:param language_name: Search by language name
790798
:param limit: Number of records to return.
791799
792800
"""
@@ -795,20 +803,143 @@ def list_containers(self, name=None, container_type=None, limit=20):
795803
if limit:
796804
params['limit'] = limit
797805

806+
if id:
807+
params['id'] = id
808+
809+
if product_id:
810+
params['product__id'] = product_id
811+
798812
if name:
799-
params['name__contains'] = name
813+
params['name__icontains'] = language_name
814+
815+
return self._request('GET', 'app_analysis/', params)
816+
817+
def create_app_analysis(self, product_id, user_id, name, confidence, version, icon, website):
818+
"""
819+
Create a application analysis to product mapping.
820+
:param id: Language identification.
821+
"""
822+
823+
data = {
824+
'product': self.get_product_uri(product_id),
825+
'user': self.get_user_uri(user_id),
826+
'name': name,
827+
'confidence': confidence,
828+
'version': version,
829+
'icon': icon,
830+
'website': website
831+
}
832+
833+
return self._request('POST', 'app_analysis/', data=data)
834+
835+
def delete_app_analysis(self, id):
836+
"""
837+
Deletes an app analysis using the given id.
838+
:param id: Language identification.
839+
"""
840+
return self._request('DELETE', 'app_analysis/' + str(id) + '/')
841+
842+
def delete_all_app_analysis_product(self, product_id):
843+
"""
844+
Delete all app analysis using the given id.
845+
:product_id id: Product to remove
846+
"""
847+
app_analysis = self.list_app_analysis(product_id=product_id)
848+
849+
if app_analysis.success:
850+
for app in app_analysis.data["objects"]:
851+
self.delete_app_analysis(self.get_id_from_url(app['resource_uri']))
852+
853+
##### Language API #####
854+
855+
def list_languages(self, id=None, product_id=None, language_name=None, limit=20):
856+
"""Retrieves source code languages.
857+
858+
:param id: Search by lanaguage id.
859+
:param product: Search by product id
860+
:param language_name: Search by language name
861+
:param limit: Number of records to return.
800862
801-
if container_type:
802-
params['container_type__contains'] = container_type
863+
"""
864+
865+
params = {}
866+
if limit:
867+
params['limit'] = limit
868+
869+
if id:
870+
params['id'] = id
871+
872+
if product_id:
873+
params['product__id'] = product_id
874+
875+
if language_name:
876+
params['language_type__language__icontains'] = language_name
877+
878+
return self._request('GET', 'languages/', params)
879+
880+
def create_language(self, product_id, user_id, files, code, blank, comment, language_type_id=None, language_name=None):
881+
"""
882+
Create a language to product mapping.
883+
:param product_id: Product identification.
884+
"""
885+
#If language name specified then lookup
886+
if language_name:
887+
languages = self.list_language_types(language_name=language_name)
888+
889+
if languages.success:
890+
for language in languages.data["objects"]:
891+
language_type = language['resource_uri']
892+
893+
data = {
894+
'product': self.get_product_uri(product_id),
895+
'language_type': language_type,
896+
'user': self.get_user_uri(user_id),
897+
'files': files,
898+
'code': code,
899+
'blank': blank,
900+
'comment': comment
901+
}
902+
903+
return self._request('POST', 'languages/', data=data)
803904

804-
return self._request('GET', 'container/', params)
905+
def delete_language(self, id):
906+
"""
907+
Deletes a language using the given id.
908+
:param id: Language identification.
909+
"""
910+
return self._request('DELETE', 'languages/' + str(id) + '/')
805911

806-
def get_container(self, container_id, limit=20):
912+
def delete_all_languages_product(self, product_id):
807913
"""
808-
Retrieves a finding using the given container id.
809-
:param container_id: Container identification.
914+
Delete all languages for a given product id.
915+
:param id: Language identification.
916+
"""
917+
languages = self.list_languages(product_id=product_id)
918+
919+
if languages.success:
920+
for language in languages.data["objects"]:
921+
self.delete_language(self.get_id_from_url(language['resource_uri']))
922+
923+
def list_language_types(self, id=None, language_name=None, limit=20):
924+
"""Retrieves source code languages.
925+
926+
:param id: Search by lanaguage id.
927+
:param language_name: Search by language name
928+
:param limit: Number of records to return.
929+
810930
"""
811-
return self._request('GET', 'container/' + str(container_id) + '/')
931+
932+
params = {}
933+
if limit:
934+
params['limit'] = limit
935+
936+
if id:
937+
params['id'] = id
938+
939+
if language_name:
940+
params['language__icontains'] = language_name
941+
942+
return self._request('GET', 'language_types/', params)
812943

813944
###### Tool API #######
814945

0 commit comments

Comments
 (0)