Skip to content

Commit

Permalink
Added connection-json flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitcoder committed Jun 30, 2024
1 parent 705bc58 commit 0dfb307
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
6 changes: 5 additions & 1 deletion hawk_scanner/commands/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions hawk_scanner/internals/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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():
Expand Down
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,6 +189,10 @@ Note: If you don't provide any command, it will run all commands (firebase, fs,
<td>--connection</td>
<td>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.</td>
</tr>
<tr>
<td>--connection-json</td>
<td>Provide a connection json as CLI Input, helpful when you want to run this tool in CI/CD pipeline or automation.</td>
</tr>
<tr>
<td>--fingerprint</td>
<td>Provide a fingerprint file path like --fingerprint fingerprint.yml, this file will override default fingerprints.</td>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "0.3.13"
VERSION = "0.3.14"

from setuptools import setup, find_packages

Expand Down

0 comments on commit 0dfb307

Please sign in to comment.