Skip to content

Commit 02222b7

Browse files
authored
Merge pull request #162 from nemanjaASE/issue-158-missing-type-annotations
Added Missing Type Annotations
2 parents aa27817 + 5a4b5e1 commit 02222b7

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

agentic_security/core/app.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
from fastapi import FastAPI
55
from fastapi.responses import ORJSONResponse
66

7+
from agentic_security.http_spec import LLMSpec
8+
79
tools_inbox: Queue = Queue()
810
stop_event: Event = Event()
911
current_run: str = {"spec": "", "id": ""}
10-
_secrets = {}
12+
_secrets: dict[str, str] = {}
13+
14+
current_run: dict[str, int | LLMSpec] = {"spec": "", "id": ""}
1115

1216

1317
def create_app() -> FastAPI:
@@ -26,29 +30,29 @@ def get_stop_event() -> Event:
2630
return stop_event
2731

2832

29-
def get_current_run() -> str:
33+
def get_current_run() -> dict[str, int | LLMSpec]:
3034
"""Get the current run id."""
3135
return current_run
3236

3337

34-
def set_current_run(spec):
38+
def set_current_run(spec: LLMSpec) -> dict[str, int | LLMSpec]:
3539
"""Set the current run id."""
3640
current_run["id"] = hash(id(spec))
3741
current_run["spec"] = spec
3842
return current_run
3943

4044

41-
def get_secrets():
45+
def get_secrets() -> dict[str, str]:
4246
return _secrets
4347

4448

45-
def set_secrets(secrets):
49+
def set_secrets(secrets: dict[str, str]) -> dict[str, str]:
4650
_secrets.update(secrets)
4751
expand_secrets(_secrets)
4852
return _secrets
4953

5054

51-
def expand_secrets(secrets):
55+
def expand_secrets(secrets: dict[str, str]) -> None:
5256
for key in secrets:
5357
val = secrets[key]
5458
if val.startswith("$"):

agentic_security/misc/banner.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
from pyfiglet import Figlet, FontNotFound
23
from termcolor import colored
34

@@ -8,14 +9,14 @@
89

910

1011
def generate_banner(
11-
title="Agentic Security",
12-
font="slant",
13-
version="v2.1.0",
14-
tagline="Proactive Threat Detection & Automated Security Protocols",
15-
author="Developed by: [Security Team]",
16-
website="Website: https://github.com/msoedov/agentic_security",
17-
warning="",
18-
):
12+
title: str = "Agentic Security",
13+
font: str = "slant",
14+
version: str = "v2.1.0",
15+
tagline: str = "Proactive Threat Detection & Automated Security Protocols",
16+
author: str = "Developed by: [Security Team]",
17+
website: str = "Website: https://github.com/msoedov/agentic_security",
18+
warning: str | None = "", # Using Optional for warning since it might be None
19+
) -> str:
1920
"""Generate a visually enhanced banner with dynamic width and borders."""
2021
# Define the text elements
2122

agentic_security/report_chart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from matplotlib.cm import ScalarMappable
88
from matplotlib.colors import LinearSegmentedColormap, Normalize
99

10+
from .primitives import Table
1011

11-
def plot_security_report(table):
12+
13+
def plot_security_report(table: Table) -> io.BytesIO:
1214
# Data preprocessing
1315
data = pd.DataFrame(table)
1416

@@ -141,7 +143,7 @@ def plot_security_report(table):
141143
return buf
142144

143145

144-
def generate_identifiers(data):
146+
def generate_identifiers(data: pd.DataFrame) -> list[str]:
145147
data_length = len(data)
146148
alphabet = string.ascii_uppercase
147149
num_letters = len(alphabet)

agentic_security/routes/scan.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from collections.abc import Generator
12
from datetime import datetime
3+
from typing import Any
24

35
from fastapi import (
46
APIRouter,
@@ -24,7 +26,7 @@
2426
@router.post("/verify")
2527
async def verify(
2628
info: LLMInfo, secrets: InMemorySecrets = Depends(get_in_memory_secrets)
27-
):
29+
) -> dict[str, int | str | float]:
2830
spec = LLMSpec.from_string(info.spec)
2931
try:
3032
r = await spec.verify()
@@ -42,7 +44,7 @@ async def verify(
4244
)
4345

4446

45-
def streaming_response_generator(scan_parameters: Scan):
47+
def streaming_response_generator(scan_parameters: Scan) -> Generator[str, Any, None]:
4648
request_factory = LLMSpec.from_string(scan_parameters.llmSpec)
4749
set_current_run(request_factory)
4850

@@ -63,15 +65,15 @@ async def scan(
6365
scan_parameters: Scan,
6466
background_tasks: BackgroundTasks,
6567
secrets: InMemorySecrets = Depends(get_in_memory_secrets),
66-
):
68+
) -> StreamingResponse:
6769
scan_parameters.with_secrets(secrets)
6870
return StreamingResponse(
6971
streaming_response_generator(scan_parameters), media_type="application/json"
7072
)
7173

7274

7375
@router.post("/stop")
74-
async def stop_scan():
76+
async def stop_scan() -> dict[str, str]:
7577
get_stop_event().set()
7678
return {"status": "Scan stopped"}
7779

@@ -85,7 +87,7 @@ async def scan_csv(
8587
maxBudget: int = Query(10_000),
8688
enableMultiStepAttack: bool = Query(False),
8789
secrets: InMemorySecrets = Depends(get_in_memory_secrets),
88-
):
90+
) -> StreamingResponse:
8991
# TODO: content dataset to fuzzer
9092
content = await file.read() # noqa
9193
llm_spec = await llmSpec.read()

0 commit comments

Comments
 (0)