def get_projects(self) -> dict:
        """Returns the projects in a CodeDx instance

		Returns:
			dict: Returns a dictionary with a list of project names and ids
		"""
        path = '/api/projects'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 2
0
    def get_finding_description(self, finding: int) -> dict:
        """Returns the descriptions for the given finding from all available sources.

		Args:
			finding (int): Finding id

		Returns:
			dict: Contains the description(s) for the finding
		"""
        path = f"/api/findings/{ finding }/description"
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
    def project_files(self, project: int) -> list:
        """Provides a list of files for a project.

		Args:
			project (int): Project id

		Returns:
			list: list of files
		"""
        path = f'/api/projects/{ project }/files'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
    def job_status(self, job: str) -> dict:
        """Queries the status of a running job.

		Args:
			job (str): Job id

		Returns:
			dict: Job status
		"""
        path = f'/api/jobs/{ job }'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
    def project_status(self, project: int) -> dict:
        """Provides information on all valid triage statuses for a project.

		Args:
			project (int): Project id

		Returns:
			dict: Project statuses
		"""
        path = f'/api/projects/{ project }/statuses'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 6
0
    def get_finding_history(self, finding: int) -> list:
        """Responds with an array of "activity event" objects.

		Args:
			finding (int): Finding id

		Returns:
			list: An array of "activity event" objects
		"""
        path = f"/api/findings/{ finding }/history"
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 7
0
    def get_all_analysis(self, project: int) -> list:
        """Get list of analysis details for analysis associated with a project

		Args:
			project (int): Project ID

		Returns:
			list: List of analysis details
		"""
        path = f'/api/projects/{ project }/analyses'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 8
0
    def get_prep(self, prep_id: str) -> dict:
        """Get lists of Input IDs and Verification Errors for an Analysis Prep.

		Args:
			prep_id (str): Analysis Prep id

		Returns:
			dict: input ids and verification errors
		"""
        path = f'/api/analysis-prep/{ prep_id }'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 9
0
    def run_analysis(self, prep_id: str) -> dict:
        """Start an analysis

		Args:
			prep_id (str): Analysis prep id

		Returns:
			dict: Analysis ID and Job ID for analysis
		"""
        path = f'/api/analysis-prep/{ prep_id }/analyze'
        data = JSONResponseHandler(self.post(path)).get_data()
        return data
    def project_roles(self, project: int) -> list:
        """Provides a list of all User roles.

		Args:
			project (int): project ID

		Returns:
			list: list of users and their roles for the project
		"""
        path = f'/api/projects/{ project }/user-roles'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 11
0
    def get_input_metadata(self, prep_id: str, input_id: str) -> dict:
        """[summary]

		Args:
			prep_id (str): Prep ID
			input_id (str): Input ID

		Returns:
			dict: Input data
		"""
        path = f'/api/analysis-prep/{ prep_id }/{ input_id }'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 12
0
    def create_analysis(self, project: int) -> dict:
        """Create a new Analysis Prep associated with a particular project.

		Args:
			project (int): project id

		Returns:
			dict: new Analysis Prep as JSON
		"""
        path = '/api/analysis-prep'
        params = {"projectId": project}
        data = JSONResponseHandler(self.post(path, params)).get_data()
        return data
Esempio n. 13
0
    def get_analysis(self, project: int, analysis: int) -> dict:
        """Obtain analysis details, such as start and finish times

		Args:
			project (int): Project ID
			analysis (int): Analysis ID

		Returns:
			dict: Analysis details
		"""
        path = f'/api/projects/{ project }/analyses/{ analysis }'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
    def project_user(self, project: int, user: int) -> dict:
        """Provides a User Role for a given user.

		Args:
			project (int): Project id
			user (int): User id

		Returns:
			dict: Contains the user role for the given user
		"""
        path = f'/api/projects/{ project }/user-roles/user/{ user }'
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 15
0
    def get_finding_flow(self, project: int, req_body: dict) -> list:
        """Returns filtered finding flow data.

		Args:
			project (int): Project ID
			req_body (dict): Filters
		Returns:
			list: Contains the filtered flow data
		"""
        path = f"/api/projects/{ project }/findings/flow"
        data = JSONResponseHandler(self.post(path,
                                             json_data=req_body)).get_data()
        return data
    def file_mappings(self, project: int, files: dict) -> dict:
        """Provides source path mappings for a project.

		Args:
			project (int): Project id
			files (dict): Dictionary with files keyword and list of files

		Returns:
			dict: Contains the dictionary of file path mappings
		"""
        url = f'/api/projects/{ project }/files/mappings'
        data = JSONResponseHandler(self.post(url, json_data=files)).get_data()
        return data
    def create_project(self, name: str) -> dict:
        """Create a new project

		Args:
			name (str): Project name

		Returns:
			dict: Project object
		"""
        path = '/api/projects'
        params = {"name": name}
        data = JSONResponseHandler(self.put(path, params)).get_data()
        return data
Esempio n. 18
0
    def get_finding_group_count(self, project: int, req_body: dict) -> list:
        """Returns filtered finding counts, grouped by the specified field.

		Args:
			project (int): [description]
			req_body (dict): Dictionary with "countBy" key and filters.

		Returns:
			list: Grouped counts
		"""
        path = f"/api/projects/{ project }/findings/grouped-counts"
        data = JSONResponseHandler(self.post(path,
                                             json_data=req_body)).get_data()
        return data
    def query_count(self, filters: dict) -> int:
        """Count of projects matching given criteria

		Args:
			filters (dict): Filters for the query criteria

		Returns:
			int: Number of projects fitting the filters
		"""
        path = '/api/projects/query/count'
        criteria = self.__query_criteria(filters)
        data = JSONResponseHandler(self.post(path,
                                             json_data=criteria)).get_data()
        return data
Esempio n. 20
0
    def get_finding_count(self, project: int, req_body: dict = None) -> dict:
        """Returns the count of all findings in the project matching the given filter.

		Args:
			project (int): Project ID
			req_body (dict, optional): Filters, pagination options. Defaults to None.

		Returns:
			dict: Dictionary with project finding count
		"""
        path = f"/api/projects/{ project }/findings/count"
        if not req_body: req_body = {}
        data = JSONResponseHandler(self.post(path,
                                             json_data=req_body)).get_data()
        return data
Esempio n. 21
0
    def get_finding(self, finding: int, options: List[str] = None) -> dict:
        """Returns metadata for the given finding

		Args:
			finding (int): Finding id
			options (List[str], optional): The expand parameter is a comma separated list, which can modify the reponse. Defaults to None.

		Returns:
			dict: [description]
		"""
        path = f"/api/findings/{ finding }"
        if options:
            expanders = ",".join(options)
            query = f'?expand={ expanders }'
            path += query
        data = JSONResponseHandler(self.get(path)).get_data()
        return data
Esempio n. 22
0
    def toggle_display_tag(self, prep_id: str, input_id: str, tag_id: str,
                           enabled: bool) -> dict:
        """Enable and disable individual display tags on individual prop inputs.

		Args:
			prep_id (str): Prep ID
			input_id (str): Input ID
			tag_id (str): Tag ID
			enabled (bool): True to enable, False to disable

		Returns:
			dict: Input Display Info object as JSON, representing the new state of the input
		"""
        path = f'/api/analysis-prep/{ prep_id }/{ input_id }/tag/{ tag_id }'
        params = {"enabled": enabled}
        data = JSONResponseHandler(self.put(path, json_data=params)).get_data()
        return data
    def query_projects(self,
                       filters: dict,
                       limit: int = None,
                       offset: int = None) -> list:
        """Returns the results of a query as a list of project dictionaries

		Args:
			filters (dict): Filters for the query results
			limit (int, optional): Limits the number of results to return. Defaults to None.
			offset (int, optional): Offset for the results. Specifying an offset without a limit is an error. Defaults to None.

		Returns:
			list: List of projects
		"""
        path = '/api/projects/query'
        criteria = self.__query_criteria(filters, offset, limit)
        data = JSONResponseHandler(self.post(path,
                                             json_data=criteria)).get_data()
        return data
Esempio n. 24
0
    def bulk_status_update(self,
                           project: int,
                           status: str,
                           filters: dict = None) -> dict:
        """Applies a status to a group of findings in a project based on project id

		Args:
			project (int): Project id
			status (str): New finding status
			filters (dict, optional): Filters the group of findings. Defaults to None.

		Returns:
			dict: Job object from CodeDx
		"""
        if filters == None:
            filters = {}
        FindingStatus(status)
        path = f"/api/projects/{ project }/bulk-status-update"
        params = {"filter": filters, "status": status}
        data = JSONResponseHandler(self.post(path, params)).get_data()
        return data
Esempio n. 25
0
    def upload_analysis(self,
                        prep_id: str,
                        file_name: str,
                        client_request_id: str = None) -> dict:
        """Analysis Preps should be populated by uploading files to Code Dx.

		This will create a job to determine the contents of the file.
		Args:
			prep_id (str): Analysis Prep ID
			file_name (str): File for analysis
			client_request_id (str, optional): Arbitrary identifier used to make modifications to analysis later. Defaults to None.

		Returns:
			dict: Data about the job created
		"""
        path = f'/api/analysis-prep/{ prep_id }/upload'
        file_data = self.__get_file_data(file_name)
        if client_request_id:
            headers['X-Client-Request-Id'] = client_request_id
        data = JSONResponseHandler(self.upload(
            path, file_data=file_data)).get_data()
        return data
Esempio n. 26
0
    def get_finding_table(self,
                          project: int,
                          options: List[str] = None,
                          req_body: dict = None) -> dict:
        """Returns filtered finding table data.

		Args:
			project (int): Project id
			options (List[str], optional): The expand parameter is a comma separated list. Defaults to None.
			req_body (dict, optional): Filters, pagination options. Defaults to None.

		Returns:
			dict: [description]
		"""
        path = f"/api/projects/{ project }/findings/table"
        if options:
            query = "?expand=" + ",".join(options)
            path += query
        if not req_body:
            req_body = {}
        data = JSONResponseHandler(self.post(path,
                                             json_data=req_body)).get_data()
        return data
    def generate(self,
                 project: int,
                 report_type: str,
                 config: dict,
                 filters: dict = None) -> dict:
        """Allows user to queue a job to generate a report.

		Args:
			project (int): Project id
			report_type (str): Report type
			config (dict): Report configuration options
			filters (dict, optional): Filters for findings in report. Defaults to None.

		Returns:
			dict: Data about the queued reporting task wth jobId and inputID
		"""
        params = {"config": config}
        if filters:
            params["filter"] = filters
        path = f'/api/projects/{ project }/report/{ report_type }'
        data = JSONResponseHandler(self.post(path,
                                             json_data=params)).get_data()
        return data