From 0dfb307202396e9a248a60d9dad15ee821de2272 Mon Sep 17 00:00:00 2001 From: Rohit kumar Date: Sun, 30 Jun 2024 17:37:19 +0530 Subject: [PATCH] Added connection-json flag --- hawk_scanner/commands/fs.py | 6 +++++- hawk_scanner/internals/system.py | 14 +++++++++++--- readme.md | 11 ++++++++++- setup.py | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/hawk_scanner/commands/fs.py b/hawk_scanner/commands/fs.py index 13f2a2a..a74e452 100644 --- a/hawk_scanner/commands/fs.py +++ b/hawk_scanner/commands/fs.py @@ -39,7 +39,11 @@ def execute(args): exclude_patterns = fs_config.get(key, {}).get('exclude_patterns', []) start_time = time.time() - files = system.list_all_files_iteratively(path, exclude_patterns) + ## CHECK If file or directory + if os.path.isfile(path): + files = [path] + else: + files = system.list_all_files_iteratively(path, exclude_patterns) # Use ThreadPoolExecutor for parallel processing file_count = 0 diff --git a/hawk_scanner/internals/system.py b/hawk_scanner/internals/system.py index a83d6cc..9b02171 100644 --- a/hawk_scanner/internals/system.py +++ b/hawk_scanner/internals/system.py @@ -19,9 +19,10 @@ parser = argparse.ArgumentParser(description='🦅 A powerful scanner to scan your Filesystem, S3, MySQL, PostgreSQL, MongoDB, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.') parser.add_argument('command', nargs='?', choices=data_sources_option, help='Command to execute') parser.add_argument('--connection', action='store', help='YAML Connection file path') +parser.add_argument('--connection-json', type=str, help='Connection details in JSON format, useful for passing connection info directly as CLI Input') parser.add_argument('--fingerprint', action='store', help='Override YAML fingerprint file path') -parser.add_argument('--json', help='Save output to json file') -parser.add_argument('--stdout', action='store_true', help='Print output to stdout') +parser.add_argument('--json', help='Save output to a json file') +parser.add_argument('--stdout', action='store_true', help='Print output to stdout in JSON format') parser.add_argument('--quiet', action='store_true', help='Print only the results') parser.add_argument('--debug', action='store_true', help='Enable debug mode') parser.add_argument('--no-write', action='store_true', help='Do not write previous alerts to file, this may flood you with duplicate alerts') @@ -126,8 +127,15 @@ def get_connection(): else: print_error(f"Connection file not found: {args.connection}") exit(1) + elif args.connection_json: + try: + connections = json.loads(args.connection_json) + return connections + except json.JSONDecodeError as e: + print_error(f"Error parsing JSON: {e}") + exit(1) else: - print_error(f"Please provide a connection file using --connection flag") + print_error("Please provide a connection file using --connection flag or connection details using --connection-json flag") exit(1) def get_fingerprint_file(): diff --git a/readme.md b/readme.md index 34d83e2..a308964 100644 --- a/readme.md +++ b/readme.md @@ -40,11 +40,16 @@ See how this works on Youtube - https://youtu.be/LuPXE7UJKOY ``` -## Example working command (Use all/fs/s3/gcs etc...) +### Example working command (Use all/fs/s3/gcs etc...) ```bash hawk_scanner all --connection connection.yml --fingerprint fingerprint.yml --json output.json --debug ``` +### Pass connection data as CLI input in --connection-json flag, and output in json data (Helpful for CI/CD pipeline or automation) + ```bash + hawk_scanner fs --connection-json '{"sources": {"fs": {"fs1": {"quick_scan": true, "path": "/Users/rohitcoder/Downloads/data/KYC_PDF.pdf"}}}}' --stdout --quiet --fingerprint fingerprint.yml + ``` + ## Platform and arch-specific guidelines ### Postgresql @@ -184,6 +189,10 @@ Note: If you don't provide any command, it will run all commands (firebase, fs, --connection Provide a connection YAML local file path like --connection connection.yml, this file will contain all creds and configs for different sources and other configurations. + + --connection-json + Provide a connection json as CLI Input, helpful when you want to run this tool in CI/CD pipeline or automation. + --fingerprint Provide a fingerprint file path like --fingerprint fingerprint.yml, this file will override default fingerprints. diff --git a/setup.py b/setup.py index 575a4a9..4cbe81a 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -VERSION = "0.3.13" +VERSION = "0.3.14" from setuptools import setup, find_packages