Skip to content

Commit e5dc4e6

Browse files
Merge pull request #92 from OWASP/dev
Dev RELEASE: v0.17.4
2 parents edea41d + e7f3476 commit e5dc4e6

24 files changed

+450
-418
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ venv/
149149
ENV/
150150
env.bak/
151151
venv.bak/
152+
venvs/
152153

153154
# Spyder project settings
154155
.spyderproject

src/DockerFiles/base-Dockerfile

-12
This file was deleted.

src/offat/__main__.py

+55-55
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def banner():
1111
print(
12-
r'''
12+
r"""
1313
_/| |\_
1414
/ | | \
1515
| \ / |
@@ -25,114 +25,114 @@ def banner():
2525
/ | \
2626
/ v \
2727
OFFAT
28-
'''
28+
"""
2929
)
3030

3131

3232
def start():
33-
'''Starts cli tool'''
33+
"""Starts cli tool"""
3434
banner()
3535

36-
parser = ArgumentParser(prog='offat')
36+
parser = ArgumentParser(prog="offat")
3737
parser.add_argument(
38-
'-f',
39-
'--file',
40-
dest='fpath',
38+
"-f",
39+
"--file",
40+
dest="fpath",
4141
type=str,
42-
help='path or url of openapi/swagger specification file',
42+
help="path or url of openapi/swagger specification file",
4343
required=True,
4444
)
4545
parser.add_argument(
46-
'-v', '--version', action='version', version=f'%(prog)s {get_package_version()}'
46+
"-v", "--version", action="version", version=f"%(prog)s {get_package_version()}"
4747
)
4848
parser.add_argument(
49-
'-rl',
50-
'--rate-limit',
51-
dest='rate_limit',
52-
help='API requests rate limit per second',
49+
"-rl",
50+
"--rate-limit",
51+
dest="rate_limit",
52+
help="API requests rate limit per second",
5353
type=float,
5454
default=60,
5555
required=False,
5656
)
5757
parser.add_argument(
58-
'-pr',
59-
'--path-regex',
60-
dest='path_regex_pattern',
58+
"-pr",
59+
"--path-regex",
60+
dest="path_regex_pattern",
6161
type=str,
62-
help='run tests for paths matching given regex pattern',
62+
help="run tests for paths matching given regex pattern",
6363
required=False,
6464
default=None,
6565
)
6666
parser.add_argument(
67-
'-o',
68-
'--output',
69-
dest='output_file',
67+
"-o",
68+
"--output",
69+
dest="output_file",
7070
type=str,
71-
help='path to store test results',
71+
help="path to store test results",
7272
required=False,
7373
default=None,
7474
)
7575
parser.add_argument(
76-
'-of',
77-
'--format',
78-
dest='output_format',
76+
"-of",
77+
"--format",
78+
dest="output_format",
7979
type=str,
80-
choices=['json', 'yaml', 'html', 'table'],
81-
help='Data format to save (json, yaml, html, table). Default: table',
80+
choices=["json", "yaml", "html", "table"],
81+
help="Data format to save (json, yaml, html, table). Default: table",
8282
required=False,
83-
default='table',
83+
default="table",
8484
)
8585
parser.add_argument(
86-
'-H',
87-
'--headers',
88-
dest='headers',
86+
"-H",
87+
"--headers",
88+
dest="headers",
8989
type=str,
90-
help='HTTP requests headers that should be sent during testing eg: User-Agent: offat',
90+
help="HTTP requests headers that should be sent during testing eg: User-Agent: offat",
9191
required=False,
9292
default=None,
93-
action='append',
94-
nargs='*',
93+
action="append",
94+
nargs="*",
9595
)
9696
parser.add_argument(
97-
'-tdc',
98-
'--test-data-config',
99-
dest='test_data_config',
100-
help='YAML file containing user test data for tests',
97+
"-tdc",
98+
"--test-data-config",
99+
dest="test_data_config",
100+
help="YAML file containing user test data for tests",
101101
required=False,
102102
type=str,
103103
)
104104
parser.add_argument(
105-
'-p',
106-
'--proxy',
107-
dest='proxies_list',
105+
"-p",
106+
"--proxy",
107+
dest="proxies_list",
108108
help='Proxy server URL to route HTTP requests through (e.g. "http://proxyserver:port")',
109-
action='append',
109+
action="append",
110110
required=False,
111111
type=str,
112112
default=None,
113113
)
114114
parser.add_argument(
115-
'-s',
116-
'--ssl',
117-
dest='ssl',
115+
"-s",
116+
"--ssl",
117+
dest="ssl",
118118
required=False,
119-
action='store_true',
120-
help='Enable SSL Verification',
119+
action="store_true",
120+
help="Enable SSL Verification",
121121
)
122122
parser.add_argument(
123-
'-cf',
124-
'--capture-failed',
125-
dest='capture_failed',
126-
action='store_true',
127-
help='Captures failed requests due to any exceptions into output file',
123+
"-cf",
124+
"--capture-failed",
125+
dest="capture_failed",
126+
action="store_true",
127+
help="Captures failed requests due to any exceptions into output file",
128128
)
129129
parser.add_argument(
130-
'--server',
131-
dest='server_url',
130+
"--server",
131+
dest="server_url",
132132
type=str,
133133
default=None,
134134
required=False,
135-
help='server/host base url to overwrite from OAS/Swagger file',
135+
help="server/host base url to overwrite from OAS/Swagger file",
136136
)
137137
args = parser.parse_args()
138138

@@ -165,5 +165,5 @@ def start():
165165
)
166166

167167

168-
if __name__ == '__main__':
168+
if __name__ == "__main__":
169169
start()

src/offat/api/__main__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
def get_offat_installation_dir():
66
try:
77
# For non-editable installation
8-
return importlib.resources.files('offat')
8+
return importlib.resources.files("offat")
99
except ImportError:
1010
# For editable installation (pip install -e .)
11-
return importlib.resources.files('.')
11+
return importlib.resources.files(".")
1212

1313

1414
def start():
1515
installation_dir = get_offat_installation_dir()
1616
run(
17-
app='offat.api.app:app',
17+
app="offat.api.app:app",
1818
host="0.0.0.0",
1919
port=8000,
2020
workers=2,
@@ -23,5 +23,5 @@ def start():
2323
)
2424

2525

26-
if __name__ == '__main__':
26+
if __name__ == "__main__":
2727
start()

src/offat/api/app.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
from offat.api.jobs import scan_api
44
from offat.api.models import CreateScanModel
55
from offat.logger import logger
6+
67
# from os import uname, environ
78

89

9-
logger.info('Secret Key: %s', auth_secret_key)
10+
logger.info("Secret Key: %s", auth_secret_key)
1011

1112

1213
# if uname().sysname == 'Darwin' and environ.get('OBJC_DISABLE_INITIALIZE_FORK_SAFETY') != 'YES':
1314
# logger.warning('Mac Users might need to configure OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES in env\nVisit StackOverFlow link for more info: https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr')
1415

1516

16-
@app.get('/', status_code=status.HTTP_200_OK)
17+
@app.get("/", status_code=status.HTTP_200_OK)
1718
async def root():
1819
return {
1920
"name": "OFFAT API",
@@ -22,63 +23,64 @@ async def root():
2223
}
2324

2425

25-
@app.post('/api/v1/scan', status_code=status.HTTP_201_CREATED)
26-
async def add_scan_task(scan_data: CreateScanModel, request: Request, response: Response):
27-
# for auth
26+
@app.post("/api/v1/scan", status_code=status.HTTP_201_CREATED)
27+
async def add_scan_task(
28+
scan_data: CreateScanModel, request: Request, response: Response
29+
):
30+
# for auth
2831
client_ip = request.client.host
29-
secret_key = request.headers.get('SECRET-KEY', None)
32+
secret_key = request.headers.get("SECRET-KEY", None)
3033
if secret_key != auth_secret_key:
3134
# return 404 for better endpoint security
3235
response.status_code = status.HTTP_401_UNAUTHORIZED
33-
logger.warning('INTRUSION: %s tried to create a new scan job', client_ip)
36+
logger.warning("INTRUSION: %s tried to create a new scan job", client_ip)
3437
return {"message": "Unauthorized"}
3538

36-
msg = {
37-
"msg": "Scan Task Created",
38-
"job_id": None
39-
}
39+
msg = {"msg": "Scan Task Created", "job_id": None}
4040

41-
job = task_queue.enqueue(scan_api, scan_data, job_timeout=task_timeout)
42-
msg['job_id'] = job.id
41+
job = task_queue.enqueue(scan_api, scan_data, job_timeout=task_timeout)
42+
msg["job_id"] = job.id
4343

44-
logger.info('SUCCESS: %s created new scan job - %s', client_ip, job.id)
44+
logger.info("SUCCESS: %s created new scan job - %s", client_ip, job.id)
4545

4646
return msg
4747

4848

49-
@app.get('/api/v1/scan/{job_id}/result')
49+
@app.get("/api/v1/scan/{job_id}/result")
5050
async def get_scan_task_result(job_id: str, request: Request, response: Response):
5151
# for auth
5252
client_ip = request.client.host
53-
secret_key = request.headers.get('SECRET-KEY', None)
53+
secret_key = request.headers.get("SECRET-KEY", None)
5454
if secret_key != auth_secret_key:
5555
# return 404 for better endpoint security
5656
response.status_code = status.HTTP_401_UNAUTHORIZED
57-
logger.warning('INTRUSION: %s tried to access %s job scan results', client_ip, job_id)
57+
logger.warning(
58+
"INTRUSION: %s tried to access %s job scan results", client_ip, job_id
59+
)
5860
return {"message": "Unauthorized"}
5961

6062
scan_results_job = task_queue.fetch_job(job_id=job_id)
6163

62-
logger.info('SUCCESS: %s accessed %s job scan results', client_ip, job_id)
64+
logger.info("SUCCESS: %s accessed %s job scan results", client_ip, job_id)
6365

64-
msg = 'Task Remaining or Invalid Job Id'
66+
msg = "Task Remaining or Invalid Job Id"
6567
results = None
6668
response.status_code = status.HTTP_202_ACCEPTED
6769

6870
if scan_results_job and scan_results_job.is_started:
69-
msg = 'Job In Progress'
71+
msg = "Job In Progress"
7072

7173
elif scan_results_job and scan_results_job.is_finished:
72-
msg = 'Task Completed'
74+
msg = "Task Completed"
7375
results = scan_results_job.result
7476
response.status_code = status.HTTP_200_OK
7577

7678
elif scan_results_job and scan_results_job.is_failed:
77-
msg = 'Task Failed. Try Creating Task Again.'
79+
msg = "Task Failed. Try Creating Task Again."
7880
response.status_code = status.HTTP_200_OK
7981

8082
msg = {
81-
'msg': msg,
82-
'results': results,
83+
"msg": msg,
84+
"results": results,
8385
}
8486
return msg

src/offat/api/auth_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ def generate_random_secret_key_string(length=128):
77
characters = string.ascii_letters + string.digits + "-_."
88

99
# Generate a random string of the specified length
10-
random_string = ''.join(secrets.choice(characters) for _ in range(length))
10+
random_string = "".join(secrets.choice(characters) for _ in range(length))
1111

1212
return random_string

src/offat/api/config.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
load_dotenv()
1111

1212
app = FastAPI(
13-
title='OFFAT - API',
14-
servers=[{
15-
'url':'http://localhost:8000',
16-
}],
13+
title="OFFAT - API",
14+
servers=[
15+
{
16+
"url": "http://localhost:8000",
17+
}
18+
],
1719
)
1820

19-
auth_secret_key = environ.get(
20-
'AUTH_SECRET_KEY', generate_random_secret_key_string())
21-
redis_con = Redis(host=environ.get('REDIS_HOST', 'localhost'),
22-
port=int(environ.get('REDIS_PORT', 6379)))
23-
task_queue = Queue(name='offat_task_queue', connection=redis_con)
21+
auth_secret_key = environ.get("AUTH_SECRET_KEY", generate_random_secret_key_string())
22+
redis_con = Redis(
23+
host=environ.get("REDIS_HOST", "localhost"),
24+
port=int(environ.get("REDIS_PORT", 6379)),
25+
)
26+
task_queue = Queue(name="offat_task_queue", connection=redis_con)
2427
task_timeout = 60 * 60 # 3600 s = 1 hour

src/offat/api/jobs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def scan_api(body_data: CreateScanModel):
1818
)
1919
return results
2020
except Exception as e:
21-
logger.error('Error occurred while creating a job: %s', repr(e))
21+
logger.error("Error occurred while creating a job: %s", repr(e))
2222
logger.debug("Debug Data:", exc_info=exc_info())
23-
return [{'error': str(e)}]
23+
return [{"error": str(e)}]

0 commit comments

Comments
 (0)