Return scan data loaded from `location` that is either: - a path string - a JSON string - a Python mapping - a List or Tuple of paths to JSON scans to combine together. In this case all paths are prefixed with codebase-1/, codebase-2., etc.
(self, location)
| 1790 | return scan_data |
| 1791 | |
| 1792 | def _get_scan_data(self, location): |
| 1793 | """ |
| 1794 | Return scan data loaded from `location` that is either: |
| 1795 | - a path string |
| 1796 | - a JSON string |
| 1797 | - a Python mapping |
| 1798 | - a List or Tuple of paths to JSON scans to combine together. In this |
| 1799 | case all paths are prefixed with codebase-1/, codebase-2., etc. |
| 1800 | incremented for each location. |
| 1801 | Loading also cleans the paths as POSIX. |
| 1802 | """ |
| 1803 | if isinstance(location, dict): |
| 1804 | return location |
| 1805 | |
| 1806 | if isinstance( |
| 1807 | location, |
| 1808 | ( |
| 1809 | list, |
| 1810 | tuple, |
| 1811 | ), |
| 1812 | ): |
| 1813 | combined_scan_data = dict(headers=[], files=[]) |
| 1814 | for idx, loc in enumerate(location, 1): |
| 1815 | scan_data = self._get_scan_data_helper(loc) |
| 1816 | headers = scan_data.get("headers") |
| 1817 | if headers: |
| 1818 | combined_scan_data["headers"].extend(headers) |
| 1819 | files = scan_data.get("files") |
| 1820 | if files: |
| 1821 | for f in files: |
| 1822 | f["path"] = posixpath_join(f"codebase-{idx}", clean_path(f["path"])) |
| 1823 | combined_scan_data["files"].extend(files) |
| 1824 | else: |
| 1825 | raise Exception( |
| 1826 | f'Input file is missing a "files" (aka. resources) section to load: {loc}' |
| 1827 | ) |
| 1828 | |
| 1829 | combined_scan_data["headers"] = sorted( |
| 1830 | combined_scan_data["headers"], |
| 1831 | key=lambda x: x["start_timestamp"], |
| 1832 | ) |
| 1833 | return combined_scan_data |
| 1834 | |
| 1835 | return self._get_scan_data_helper(location) |
| 1836 | |
| 1837 | def _create_empty_resource_data(self): |
| 1838 | """ |
no test coverage detected