|
18 | 18 | from pathlib import Path |
19 | 19 | import sys |
20 | 20 |
|
| 21 | +from importlib.metadata import version |
| 22 | + |
21 | 23 | import pandas as pd |
22 | 24 | import html |
23 | 25 | import datetime |
|
44 | 46 | get_imported_modules_by_file, |
45 | 47 | ) |
46 | 48 | from codeaudit.htmlhelpfunctions import json_to_html, dict_list_to_html_table |
47 | | -from codeaudit import __version__ |
| 49 | + |
48 | 50 | from codeaudit.pypi_package_scan import get_pypi_download_info, get_package_source |
49 | 51 | from codeaudit.privacy_lint import data_egress_scan, has_privacy_findings |
50 | 52 | from codeaudit.suppression import filter_sast_results |
51 | 53 | from codeaudit.api_interfaces import _collect_issue_lines |
52 | 54 |
|
53 | 55 | from importlib.resources import files |
54 | 56 |
|
| 57 | +CA_VERSION = version("codeaudit") |
| 58 | + |
55 | 59 | PYTHON_CODE_AUDIT_TEXT = '<a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a>' |
56 | 60 | DISCLAIMER_TEXT = ( |
57 | 61 | "<p><b>Disclaimer:</b> <i>This SAST tool " |
@@ -769,7 +773,7 @@ def create_htmlfile(html_input, outputfile): |
769 | 773 |
|
770 | 774 | now = datetime.datetime.now() |
771 | 775 | timestamp_str = now.strftime("%Y-%m-%d %H:%M") |
772 | | - code_audit_version = __version__ |
| 776 | + code_audit_version = CA_VERSION |
773 | 777 |
|
774 | 778 | output += ( |
775 | 779 | f"<p>This Python security report was created on: <b>{timestamp_str}</b> with " |
@@ -806,64 +810,6 @@ def create_htmlfile(html_input, outputfile): |
806 | 810 | print("=====================================================================\n") |
807 | 811 |
|
808 | 812 |
|
809 | | -# def create_htmlfile(html_input,outputfile): |
810 | | -# """ Creates a clean html file based on html input given """ |
811 | | -# # Read CSS from the file - So it is included in the reporting HTML file |
812 | | - |
813 | | -# with open(SIMPLE_CSS_FILE, 'r') as css_file: |
814 | | -# css_content = css_file.read() |
815 | | -# # Start building the HTML |
816 | | -# output = '<!DOCTYPE html><html lang="en-US"><head>' |
817 | | -# output += '<meta charset="UTF-8"/>' |
818 | | -# output += '<title>Python_Code_Audit_SecurityReport</title>' |
819 | | -# # Inline CSS inside <style> block |
820 | | -# output += f'<style>\n{css_content}\n</style>' |
821 | | -# output += '<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>' # needed for altair plots |
822 | | -# output += '<script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>' # needed for altair plots |
823 | | -# output += '<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>' # needed for altair plots |
824 | | -# output += '</head><body>' |
825 | | -# output += '<div class="container">' |
826 | | -# output += html_input |
827 | | -# now = datetime.datetime.now() |
828 | | -# timestamp_str = now.strftime("%Y-%m-%d %H:%M") |
829 | | -# code_audit_version = __version__ |
830 | | -# output += ( |
831 | | -# f"<p>This Python security report was created on: <b>{timestamp_str}</b> with " |
832 | | -# + PYTHON_CODE_AUDIT_TEXT |
833 | | -# + f" version <b>{code_audit_version}</b></p>" |
834 | | -# ) |
835 | | -# output += '<hr>' |
836 | | -# output += '<footer>' |
837 | | -# output += ( |
838 | | -# '<div class="footer-links">' |
839 | | -# 'Check the <a href="https://nocomplexity.com/documents/codeaudit/intro.html" ' |
840 | | -# 'target="_blank">documentation</a> for help on found issues.<br>' |
841 | | -# 'Codeaudit is made with <span class="heart">❤</span> by cyber security ' |
842 | | -# 'professionals who advocate for <a href="https://nocomplexity.com/simplify-security/" target="_blank">open simple security solutions</a>.<br>' |
843 | | -# '<a href="https://nocomplexity.com/documents/codeaudit/CONTRIBUTE.html" target="_blank">Join the community</a> and contribute to make this tool better!' |
844 | | -# "</div>" |
845 | | -# ) |
846 | | -# output += "</footer>" |
847 | | -# output += '</div>' #base container |
848 | | -# output += '</body></html>' |
849 | | -# # Now create the HTML output file |
850 | | -# with open(outputfile, 'w') as f: |
851 | | -# f.write(output) |
852 | | -# current_directory = os.getcwd() |
853 | | -# # Get the directory of the output file (if any) |
854 | | -# directory_for_output = os.path.dirname(os.path.abspath(outputfile)) |
855 | | -# filename_only = os.path.basename(outputfile) |
856 | | -# # Determine the effective directory to use in the file URL |
857 | | -# if not directory_for_output or directory_for_output == current_directory: |
858 | | -# file_url = f'file://{current_directory}/{filename_only}' |
859 | | -# else: |
860 | | -# file_url = f'file://{directory_for_output}/{filename_only}' |
861 | | -# # Print the result |
862 | | -# print("\n=====================================================================") |
863 | | -# print(f'Code Audit report file created!\nPaste the line below directly into your browser bar:\n\t{file_url}\n') |
864 | | -# print("=====================================================================\n") |
865 | | - |
866 | | - |
867 | 813 | def extract_altair_html(plot_html): |
868 | 814 | match = re.search(r"<body[^>]*>(.*?)</body>", plot_html, re.DOTALL | re.IGNORECASE) |
869 | 815 | if match: |
@@ -955,7 +901,7 @@ def report_implemented_tests(filename=DEFAULT_OUTPUT_FILE): |
955 | 901 | number_of_test = len(df_checks) |
956 | 902 |
|
957 | 903 | output += df_checks_sorted.to_html(escape=False, index=False) |
958 | | - code_audit_version = __version__ |
| 904 | + code_audit_version = CA_VERSION |
959 | 905 | output += "<br>" |
960 | 906 | output += ( |
961 | 907 | f"<p>Number of implemented security validations:<b>{number_of_test}</b></p>" |
|
0 commit comments