Skip to content

Commit

Permalink
Speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
battleoverflow committed Aug 4, 2023
1 parent c59af56 commit a646830
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -154,6 +154,4 @@ FROM ubuntu:18.04

Some scripts are now provided to help with your local configuration of ThreatIngestor.

| Script | Description | Example |
|-----------------------|-------------------------------------------------------------------------------------------------------------|----------------------------------|
| `scripts/validate.py` | This script validates your YAML syntax and checks that you have the bare minimum required by ThreatIngestor | `python3 validate.py config.yml` |
A README.md with additional information is available [here](https://github.com/InQuest/ThreatIngestor/tree/master/scripts/README.md).
15 changes: 15 additions & 0 deletions scripts/README.md
@@ -0,0 +1,15 @@
# ThreatIngestor Utilities

Scripts to improve ThreatIngestor usage and help with minimizing errors.

All scripts contain the following optional argument to allow for higher verbosity in stdout:

```bash
python3 scripts/<script> -v
```

A quick list of all available scripts:

| Script | Example | Description |
|-----------------------|----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `scripts/validate.py` | `python3 validate.py config.yml` | This script validates your YAML syntax and checks that you have the minimum required (`config.yml`) by ThreatIngestor to operate properly. |
26 changes: 19 additions & 7 deletions scripts/validate.py
@@ -1,11 +1,19 @@
"""
This script validates your YAML syntax and checks that you have the minimum required (`config.yml`) by ThreatIngestor to operate properly.
"""

import sys, yaml

from shutil import which
from subprocess import getoutput
from rich.console import Console
from time import sleep

config_file = sys.argv[1]
try:
config_file = sys.argv[1]
except IndexError:
print("Missing config.yml file location")
print("Usage: python3 scripts/validate.py config.yml")
sys.exit(1)

def validate_config():
if which("yamllint") is not None:
Expand All @@ -16,10 +24,10 @@ def validate_config():
print(f"\nYaml config errors:\n{lint}")
return False
elif "warning" in lint:
print(f"\nYaml config warnings:\n{lint}")
return True
else:
return True
if "-v" in sys.argv:
print(f"\nYaml config warnings:\n{lint}")

return True
else:
print("Missing yamllint")
sys.exit(1)
Expand All @@ -36,7 +44,11 @@ def main():
console.log(f"[green]Validating sources...[/green]")

for source in yaml_file['sources']:
sleep(0.2)

# Slow down the output
if "-v" in sys.argv:
from time import sleep
sleep(0.2)

try:
console.log(f"[green]Validating[/green] {source['name']}")
Expand Down

0 comments on commit a646830

Please sign in to comment.