class ThreadFixList(object): def __init__(self, team, application): self.helper = ThreadFixHelper() self._list_applications(team, application) def _list_applications(self, team, application): applications = self.helper.list_all_apps(team, application) if applications is not False: if len(applications): print("{0:^10} {1:55} {2:30}".format('App ID', 'Team', 'Application')) print("{0:10} {1:55} {2:30}".format('-' * 10, '-' * 55, '-' * 30)) for app in applications: print("{0:^10} {1:55} {2:30}".format( app['app_id'], app['team_name'], app['app_name'])) threadfixloghelper.log_info_threadfix_list_success() else: query_info = '' if team is not None: query_info = ' with team name matching {}'.format(team) if application is not None: if query_info == '': query_info = ' with application name matching {}'.format( application) else: query_info = query_info + ' and application name matching {}'.format( application) threadfixloghelper.log_info_no_application_found(query_info) else: threadfixloghelper.log_error_api_token_associated_with_local_account( )
class ThreadFixCreate(object): def __init__(self, team_id, team, application, url): self.helper = ThreadFixHelper() self._create_application_wrapper(team_id, team, application, url) def _create_application_wrapper(self, team_id, team, application, url): if not team_id and not team: threadfixloghelper.log_error_specify_team() return if team and not team_id: team_id = self._get_team_id_by_name(team) if team_id is None: threadfixloghelper.log_error_no_team_with_application(team) return created_app = self._create_application(team_id, application, url) threadfixloghelper.log_info_application_created_with_id((created_app['id'])) def _create_application(self, team_id, name, url): response = self.helper.api.create_application(team_id, name, url) APIHelper().check_for_response_errors(response) return response.data def _get_team_id_by_name(self, team_name): teams = self.helper.get_team_list() for team in teams: if team['name'] == team_name: return team['id'] return None
class ThreadFixTeams(object): def __init__(self): self.helper = ThreadFixHelper() self._list_teams() def _list_teams(self): teams = self.helper.get_team_list() if teams: print("{0:^10} {1:30}".format('ID', 'Name')) print("{0:10} {1:30}".format('-' * 10, '-' * 30)) for team in teams: print("{0:^10} {1:30}".format(team['id'], team['name'])) threadfixloghelper.log_info_threadfix_teams_listed_success() print('\n\n') else: threadfixloghelper.log_error_no_team()
class ThreadFixUpload(object): def __init__(self, app_id, application, scan_file): self.helper = ThreadFixHelper() if not app_id and not application: threadfixloghelper.log_error_specify_application(app_id) return self._upload_scan_wrapper(app_id, application, scan_file) def _upload_scan(self, app_id, file_name): response = self.helper.api.upload_scan(app_id, file_name) APIHelper().check_for_response_errors(response) return response.data def _upload_scan_wrapper(self, app_id, application, scan_file): if not app_id: threadfixloghelper.log_info_find_application_with_matching_name( application) apps = self.helper.list_all_apps() if not apps: threadfixloghelper.log_error_threadfix_retrieve_fail() return else: matches = [] for app in apps: if app['app_name'] == application: matches.append(app.copy()) if len(matches) == 0: threadfixloghelper.log_info_find_application_with_matching_name( application) return if len(matches) > 1: threadfixloghelper.log_error_multiple_application_found( application) print("{0:^10} {1:55} {2:30}".format( 'App ID', 'Team', 'Application')) print("{0:10} {1:55} {2:30}".format( '-' * 10, '-' * 55, '-' * 30)) for app in matches: print("{0:^10} {1:55} {2:30}".format( app['app_id'], app['team_name'], app['app_name'])) print('\n\n') return else: app_id = matches[0]['app_id'] upload_resp = self._upload_scan(app_id, scan_file) threadfixloghelper.log_info_upload_response(upload_resp)
def __init__(self, app_id, application, scan_file): self.helper = ThreadFixHelper() if not app_id and not application: threadfixloghelper.log_error_specify_application(app_id) return self._upload_scan_wrapper(app_id, application, scan_file)
def __init__(self, team_id, team, application, url): self.helper = ThreadFixHelper() self._create_application_wrapper(team_id, team, application, url)
def __init__(self, app_id): self.helper = ThreadFixHelper() self._list_scans(app_id)
def __init__(self, team, application): self.helper = ThreadFixHelper() self._list_applications(team, application)
def __init__(self): self.helper = ThreadFixHelper() self._list_teams()