Skip to content

Commit dbb0628

Browse files
committed
finishe ddefect tracker api
1 parent 1ba4832 commit dbb0628

1 file changed

Lines changed: 264 additions & 1 deletion

File tree

ThreadFixProApi/Networks/_utils/_defect_tracker.py

Lines changed: 264 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,267 @@ def __init__(self, host, api_key, verify_ssl, timeout, headers, user_agent, cert
2121
the private key and the certificate) or as a tuple of both file’s path
2222
:param debug: Prints requests and responses, useful for debugging.
2323
"""
24-
super().__init__(host, api_key, verify_ssl, timeout, headers, user_agent, cert, debug)
24+
super().__init__(host, api_key, verify_ssl, timeout, headers, user_agent, cert, debug)
25+
26+
def test_defect_tracker_connection(self, name, provider_type, authentication_values):
27+
"""
28+
Tests connection to the defect tracker
29+
:param name: Name of defect tracker
30+
:param provider_type: Provider type of defect tracker
31+
:param authentication_values: Authentication values for defect tracker.
32+
"""
33+
params = {}
34+
if name:
35+
params['name'] = name
36+
if provider_type:
37+
params['providerType'] = provider_type
38+
if authentication_values:
39+
params['authenticationValues'] = authentication_values
40+
return super().request('POST', '/api/defect-tracker/test-connection', params=params)
41+
42+
def get_projects_for_defect_tracker(self, defect_tracker_id):
43+
"""
44+
Gets all projects for a specific defect tracker
45+
:param defect_tracker_id: ID of defect tracker to get projects from
46+
"""
47+
return super().request('GET', f'/api/defect-tracker/{defect_tracker_id}/projects')
48+
49+
50+
def get_list_of_fields_for_defect_tracker_project_issue(self, defect_tracker_id, project_native_id, issue_type_id):
51+
"""
52+
Gets a list of fields describing the project issue
53+
:param defect_tracker_id: ID of defect tracker
54+
:param project_native_id: Native ID of project
55+
:param issue_type_id: ID of issue type
56+
"""
57+
return super().request('GET', f'/api/defect-tracker/{defect_tracker_id}/projects/{project_native_id}/fields/{issue_type_id}')
58+
59+
def get_suggested_type_ahead_values_for_defect_tracker_fields(self, defect_tracker_id, native_id=None, name=None, active=None, multiple=None, required=None, visible=None,
60+
readonly=None, type_ahead_field=None, type_ahead_endpoint=None, type_ahead_accepted_type=None,
61+
value=None, field_type=None):
62+
"""
63+
Gets suggested values for defect tracker fields
64+
:param defect_tracker_id: ID of defect tracker
65+
:param native_id: Native ID of type ahead data
66+
:param name: Name of type ahead data.
67+
:param active: Active state of type ahead data
68+
:param multiple: If type ahead data is multiple
69+
:param required: If type ahead data is required
70+
:param visible: If type ahead data is visiblle
71+
:param readonly: If type ahead data is readonly
72+
:param type_ahead_field: Type ahead field
73+
:param type_ahead_endpoint: Type ahead endpoint
74+
:param type_ahead_accepted_type: Accepted types for the type ahead
75+
:param value: value of type ahead
76+
:param field_type: field type of type ahead
77+
"""
78+
params = {}
79+
if native_id:
80+
params['nativeId'] = native_id
81+
if name:
82+
params['name'] = name
83+
if active != None:
84+
params['active'] = active
85+
if multiple != None:
86+
params['multiple'] = multiple
87+
if required != None:
88+
params['required'] = required
89+
if visible != None:
90+
params['visible'] = visible
91+
if readonly != None:
92+
params['readonly'] = readonly
93+
if type_ahead_field:
94+
params['typeAheadField'] = type_ahead_field
95+
if type_ahead_endpoint:
96+
params['typeAheadEndpoint'] = type_ahead_endpoint
97+
if type_ahead_accepted_type:
98+
params['typeAheadAcceptedType'] = type_ahead_accepted_type
99+
if value:
100+
params['value'] = value
101+
if field_type:
102+
params['fieldType'] = field_type
103+
return super().request('POST', f'/api/defect-tracker/{defect_tracker_id}/type-ahead-data', params=params)
104+
105+
def submit_defect(self, defect_tracker_id, project_id=None, issue_type_id=None, vulnerabilties=None):
106+
"""
107+
Adds a new defect to the defect tracker.
108+
:param defect_tracker_id: ID of defect tracker to add defect to.
109+
:param project_id: ID of project defect belongs to.
110+
:param issue_type_id: Type of issue the defect is.
111+
:param vulnerabilties: Vulnerabilities related to defect.
112+
"""
113+
params = {}
114+
if project_id:
115+
params['projectId'] = project_id
116+
if issue_type_id:
117+
params['issueTypeId'] = issue_type_id
118+
if vulnerabilties:
119+
params['vulnerabilities'] = vulnerabilties
120+
return super().request('POST', f'/api/defect-tracker/{defect_tracker_id}/submit', params=params)
121+
122+
def sync_defect(self, defect_id, defect_tracker_id):
123+
"""
124+
Syncs defect with its defect tracker if it has become disconnected
125+
:param defect_id: ID of defect to sync
126+
:param defect_tracker_id: ID of defect tracker to sync to.
127+
"""
128+
return super().request('PATCH', f'/api/defect-tracker/{defect_tracker_id}/defects/{defect_id}/sync')
129+
130+
def generate_field_mapping(self, defect_tracker_id, project_id=None, defect_type_id=None, profile_id=None, vuln_ids=None):
131+
"""
132+
Generates a new field mapping
133+
:param defect_tracker_id:
134+
:param project_id:
135+
:param defect_type_id:
136+
:param profile_id: Profile attached to field mapping
137+
:param vuln_ids: List of vulnerability ids for field mapping
138+
"""
139+
params = {}
140+
if project_id:
141+
params['projectId'] = project_id
142+
if defect_type_id:
143+
params['defectTypeId'] = defect_type_id
144+
if profile_id:
145+
params['profileId'] = profile_id
146+
if vuln_ids:
147+
params['vulnIds'] = vuln_ids
148+
return super().request('POST', f'/api/defect-tracker/{defect_tracker_id}/generate-field-mappings')
149+
150+
def add_defect_tracker(self, name, provider_type, authentication_values):
151+
"""
152+
Creates a new defect trackers
153+
:param name: Name of defect tracker
154+
:param provider_type: Type of defect tracker
155+
:param authentication_values: Authentication information for defect tracker
156+
"""
157+
params = { 'name' : name, 'providerType' : provider_type, 'authenticationValues' : authentication_values}
158+
return super().request('POST', '/api/provider/defect-trackers', params=params)
159+
160+
def get_all_defect_trackers(self, page=1, limit=50, href=None):
161+
"""
162+
Fetches all defect trackers one page at a time of limit
163+
:param page: The page of the defect trackers to get (optional if you have href)
164+
:param limit: The amount of defect trackers per page
165+
:param href: The link to the next page in the system from a previous call
166+
"""
167+
# If href (calling another page gives an href tag for next page in line)
168+
if href:
169+
return super().request('GET', '/api/provider' + href)
170+
# First call
171+
return super().request('GET', f'/api/provider/defect-trackers?_page={page}&_limit={limit}')
172+
173+
def find_defect_tracker_by_id(self, defect_tracker_id):
174+
"""
175+
Gets defect tracker by id
176+
:param defect_tracker_id: ID of defect tracker to get
177+
"""
178+
return super().request('GET', f'/api/provider/defect-trackers/{defect_tracker_id}')
179+
180+
def update_existing_defect_tracker(self, defect_tracker_id, name, provider_type, authentication_values):
181+
"""
182+
Updates an existing defect trackers
183+
:param defect_tracker_id: ID of defect tracker to update
184+
:param name: Name of defect tracker
185+
:param provider_type: Type of defect tracker
186+
:param authentication_values: Authentication information for defect tracker
187+
"""
188+
params = { 'name' : name, 'providerType' : provider_type, 'authenticationValues' : authentication_values}
189+
return super().request('POST', f'/api/provider/defect-trackers/{defect_tracker_id}', params=params)
190+
191+
def delete_defect_tracker(self, defect_tracker_id):
192+
"""
193+
Deletes defect tracker
194+
:param defect_tracker_id: ID of defect tracker to delete
195+
"""
196+
return super().request('DELETE', f'/api/provider/defect-trackers/{defect_tracker_id}')
197+
198+
def add_defect_tracker_profile(self, id=None, dataset_id=None, created_date=None, modified_date=None, name=None, project_id=None, issue_type_id=None, profile_fields=None):
199+
"""
200+
Creates a new defect tracker profile
201+
:param id: ID of profile
202+
:param dataset_id: ID of dataset related to profile
203+
:param created_date: Created date of defect tracker profile
204+
:param modified_date: Modified date of defect tracker profile
205+
:param name: Name of profile
206+
:param project_id: ID of project related to profile
207+
:param issue_type_id: ID of issue type of this profile
208+
:param profile_fields: Fields that the profile contains
209+
"""
210+
params = {}
211+
if id:
212+
params['id'] = id
213+
if dataset_id:
214+
params['datasetId'] = dataset_id
215+
if created_date:
216+
params['createdDate'] = created_date
217+
if modified_date:
218+
params['modifiedDate'] = modified_date
219+
if name:
220+
params['name'] = name
221+
if project_id:
222+
params['projectId'] = project_id
223+
if issue_type_id:
224+
params['issueTypeId'] = issue_type_id
225+
if profile_fields:
226+
params['profileFields'] = profile_fields
227+
return super().request('POST', '/api/provider/defect-profiles', params=params)
228+
229+
def get_all_defect_profiles(self, page=1, limit=50, href=None):
230+
"""
231+
Fetches all defect profiles one page at a time of limit
232+
:param page: The page of the defect profiles to get (optional if you have href)
233+
:param limit: The amount of defect profiles per page
234+
:param href: The link to the next page in the system from a previous call
235+
"""
236+
# If href (calling another page gives an href tag for next page in line)
237+
if href:
238+
return super().request('GET', '/api/provider' + href)
239+
# First call
240+
return super().request('GET', f'/api/provider/defect-profiles?_page={page}&_limit={limit}')
241+
242+
def get_defect_profile_by_id(self, defect_profile_id):
243+
"""
244+
Gets a defect profile by its ID
245+
:param defect_profile_id: ID of the defect profile to get
246+
"""
247+
return super().request('GET', f'/api/provider/defect-profiles/{defect_profile_id}')
248+
249+
def update_defect_tracker_profile(self, defect_profile_id, id=None, dataset_id=None, created_date=None, modified_date=None, name=None, project_id=None, issue_type_id=None, profile_fields=None):
250+
"""
251+
Updates an existing defect tracker profile
252+
:param defect_profile_id: ID of defect profile to update
253+
:param id: ID of profile
254+
:param dataset_id: ID of dataset related to profile
255+
:param created_date: Created date of defect tracker profile
256+
:param modified_date: Modified date of defect tracker profile
257+
:param name: Name of profile
258+
:param project_id: ID of project related to profile
259+
:param issue_type_id: ID of issue type of this profile
260+
:param profile_fields: Fields that the profile contains
261+
"""
262+
params = {}
263+
if id:
264+
params['id'] = id
265+
if dataset_id:
266+
params['datasetId'] = dataset_id
267+
if created_date:
268+
params['createdDate'] = created_date
269+
if modified_date:
270+
params['modifiedDate'] = modified_date
271+
if name:
272+
params['name'] = name
273+
if project_id:
274+
params['projectId'] = project_id
275+
if issue_type_id:
276+
params['issueTypeId'] = issue_type_id
277+
if profile_fields:
278+
params['profileFields'] = profile_fields
279+
return super().request('PUT', f'/api/provider/defect-profiles/{defect_profile_id}', params=params)
280+
281+
282+
def delete_defect_profile(self, defect_profile_id):
283+
"""
284+
Delets a defect profile
285+
:param defect_profile_id: ID of the defect profile to delete
286+
"""
287+
return super().request('DELETE', f'/api/provider/defect-profiles/{defect_profile_id}')

0 commit comments

Comments
 (0)